From 2ef83cf9f101e7ebc08b6c1a677057b43dfba625 Mon Sep 17 00:00:00 2001 From: ssolson Date: Tue, 4 Feb 2025 10:07:01 -0500 Subject: [PATCH 1/5] manual preview action --- .github/workflows/manual-deploy.yml | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/manual-deploy.yml diff --git a/.github/workflows/manual-deploy.yml b/.github/workflows/manual-deploy.yml new file mode 100644 index 0000000..d823917 --- /dev/null +++ b/.github/workflows/manual-deploy.yml @@ -0,0 +1,59 @@ +name: Manual Deploy PR Preview + +on: + workflow_dispatch: + inputs: + ref: + description: 'Branch of the PR' + required: true + repository: + description: 'Fork repository' + required: true + pr_number: + description: 'Pull Request Number' + required: true + +jobs: + deploy_preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.inputs.ref }} + repository: ${{ github.event.inputs.repository }} + submodules: recursive + fetch-depth: 0 + + - name: Setup Conda Environment + uses: conda-incubator/setup-miniconda@v2 + with: + activate-environment: mhkit-docs + environment-file: environment.yml + auto-activate-base: false + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.GH_PAGES_DEPLOY_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan github.com >> ~/.ssh/known_hosts + + - name: Build Documentation + shell: bash -l {0} + run: | + cd docs + rm -rf _build/* + cp -r ../MHKiT-Python/examples/* source/ + sphinx-build -b html source _build/html + cp ../MHKiT-MATLAB/examples/*.html ./_build/html/mhkit-matlab + touch _build/html/.nojekyll + + - name: Deploy PR Preview + uses: peaceiris/actions-gh-pages@v3 + with: + deploy_key: ${{ secrets.GH_PAGES_DEPLOY_KEY }} + publish_dir: ./docs/_build/html + destination_dir: pr-previews/${{ github.event.inputs.pr_number }} + external_repository: MHKiT-Software/MHKiT + keep_files: true + enable_jekyll: false From 56c50a9b1476895c13315928ff589f2f2f1b8860 Mon Sep 17 00:00:00 2001 From: ssolson Date: Tue, 4 Feb 2025 12:15:34 -0500 Subject: [PATCH 2/5] delete all previews on merge or close --- .github/workflows/cleanup-preview.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/cleanup-preview.yml diff --git a/.github/workflows/cleanup-preview.yml b/.github/workflows/cleanup-preview.yml new file mode 100644 index 0000000..93e6181 --- /dev/null +++ b/.github/workflows/cleanup-preview.yml @@ -0,0 +1,27 @@ +name: Cleanup PR Preview + +on: + pull_request: + types: [closed] + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Setup SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.GH_PAGES_DEPLOY_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan github.com >> ~/.ssh/known_hosts + + - name: Delete All Previews + run: | + git clone --single-branch --branch gh-pages git@github.com:MHKiT-Software/MHKiT.git gh-pages + cd gh-pages + rm -rf pr-previews/ + git config user.name "GitHub Actions Bot" + git config user.email "<>" + git add -A + git commit -m "Remove all previews after merging PR #${{ github.event.pull_request.number }}" || echo "No cleanup needed" + git push From 3f6712bb347f650d538357fdbed35cac4d8086bf Mon Sep 17 00:00:00 2001 From: ssolson Date: Wed, 5 Feb 2025 09:09:55 -0500 Subject: [PATCH 3/5] auto deploy preview --- .github/workflows/docs.yml | 18 ++++++++- .github/workflows/manual-deploy.yml | 59 ----------------------------- 2 files changed, 16 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/manual-deploy.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2f3a8a4..77a8145 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,6 +15,8 @@ jobs: with: submodules: recursive fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} - name: Setup Conda Environment uses: conda-incubator/setup-miniconda@v2 @@ -28,11 +30,12 @@ jobs: run: | cd docs rm -rf _build/* + cp -r ../MHKiT-Python/examples/* source/ sphinx-build -b html source _build/html - # Create .nojekyll file to prevent GitHub Pages from ignoring files that begin with an underscore + cp ../MHKiT-MATLAB/examples/*.html ./_build/html/mhkit-matlab touch _build/html/.nojekyll - - name: Deploy to GitHub Pages + - name: Deploy to GitHub Pages (Main Branch) if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: peaceiris/actions-gh-pages@v3 with: @@ -41,3 +44,14 @@ jobs: force_orphan: true enable_jekyll: false full_commit_message: ${{ github.event.head_commit.message }} + + - name: Deploy Preview for PRs + if: github.event_name == 'pull_request' + uses: peaceiris/actions-gh-pages@v3 + with: + deploy_key: ${{ secrets.GH_PAGES_DEPLOY_KEY }} + publish_dir: ./docs/_build/html + destination_dir: pr-previews/${{ github.event.number }} + external_repository: MHKiT-Software/MHKiT + keep_files: true + enable_jekyll: false diff --git a/.github/workflows/manual-deploy.yml b/.github/workflows/manual-deploy.yml deleted file mode 100644 index d823917..0000000 --- a/.github/workflows/manual-deploy.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Manual Deploy PR Preview - -on: - workflow_dispatch: - inputs: - ref: - description: 'Branch of the PR' - required: true - repository: - description: 'Fork repository' - required: true - pr_number: - description: 'Pull Request Number' - required: true - -jobs: - deploy_preview: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.event.inputs.ref }} - repository: ${{ github.event.inputs.repository }} - submodules: recursive - fetch-depth: 0 - - - name: Setup Conda Environment - uses: conda-incubator/setup-miniconda@v2 - with: - activate-environment: mhkit-docs - environment-file: environment.yml - auto-activate-base: false - - - name: Setup SSH - run: | - mkdir -p ~/.ssh - echo "${{ secrets.GH_PAGES_DEPLOY_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan github.com >> ~/.ssh/known_hosts - - - name: Build Documentation - shell: bash -l {0} - run: | - cd docs - rm -rf _build/* - cp -r ../MHKiT-Python/examples/* source/ - sphinx-build -b html source _build/html - cp ../MHKiT-MATLAB/examples/*.html ./_build/html/mhkit-matlab - touch _build/html/.nojekyll - - - name: Deploy PR Preview - uses: peaceiris/actions-gh-pages@v3 - with: - deploy_key: ${{ secrets.GH_PAGES_DEPLOY_KEY }} - publish_dir: ./docs/_build/html - destination_dir: pr-previews/${{ github.event.inputs.pr_number }} - external_repository: MHKiT-Software/MHKiT - keep_files: true - enable_jekyll: false From b6db5b07934e56be3bd469625e719084ed115f48 Mon Sep 17 00:00:00 2001 From: ssolson Date: Wed, 5 Feb 2025 09:16:44 -0500 Subject: [PATCH 4/5] add the SSH setup step before the deploy --- .github/workflows/docs.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 77a8145..e9880cb 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -45,6 +45,14 @@ jobs: enable_jekyll: false full_commit_message: ${{ github.event.head_commit.message }} + - name: Setup SSH + if: github.event_name == 'pull_request' + run: | + mkdir -p ~/.ssh + echo "${{ secrets.GH_PAGES_DEPLOY_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan github.com >> ~/.ssh/known_hosts + - name: Deploy Preview for PRs if: github.event_name == 'pull_request' uses: peaceiris/actions-gh-pages@v3 From d505d90462d410f022cf79e73cc5e7024ae54896 Mon Sep 17 00:00:00 2001 From: ssolson Date: Wed, 5 Feb 2025 09:27:38 -0500 Subject: [PATCH 5/5] Revert to 56c50a9: Documentation workflow setup --- .github/workflows/docs.yml | 26 +------------ .github/workflows/manual-deploy.yml | 59 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/manual-deploy.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e9880cb..2f3a8a4 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,8 +15,6 @@ jobs: with: submodules: recursive fetch-depth: 0 - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - name: Setup Conda Environment uses: conda-incubator/setup-miniconda@v2 @@ -30,12 +28,11 @@ jobs: run: | cd docs rm -rf _build/* - cp -r ../MHKiT-Python/examples/* source/ sphinx-build -b html source _build/html - cp ../MHKiT-MATLAB/examples/*.html ./_build/html/mhkit-matlab + # Create .nojekyll file to prevent GitHub Pages from ignoring files that begin with an underscore touch _build/html/.nojekyll - - name: Deploy to GitHub Pages (Main Branch) + - name: Deploy to GitHub Pages if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: peaceiris/actions-gh-pages@v3 with: @@ -44,22 +41,3 @@ jobs: force_orphan: true enable_jekyll: false full_commit_message: ${{ github.event.head_commit.message }} - - - name: Setup SSH - if: github.event_name == 'pull_request' - run: | - mkdir -p ~/.ssh - echo "${{ secrets.GH_PAGES_DEPLOY_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan github.com >> ~/.ssh/known_hosts - - - name: Deploy Preview for PRs - if: github.event_name == 'pull_request' - uses: peaceiris/actions-gh-pages@v3 - with: - deploy_key: ${{ secrets.GH_PAGES_DEPLOY_KEY }} - publish_dir: ./docs/_build/html - destination_dir: pr-previews/${{ github.event.number }} - external_repository: MHKiT-Software/MHKiT - keep_files: true - enable_jekyll: false diff --git a/.github/workflows/manual-deploy.yml b/.github/workflows/manual-deploy.yml new file mode 100644 index 0000000..d823917 --- /dev/null +++ b/.github/workflows/manual-deploy.yml @@ -0,0 +1,59 @@ +name: Manual Deploy PR Preview + +on: + workflow_dispatch: + inputs: + ref: + description: 'Branch of the PR' + required: true + repository: + description: 'Fork repository' + required: true + pr_number: + description: 'Pull Request Number' + required: true + +jobs: + deploy_preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.inputs.ref }} + repository: ${{ github.event.inputs.repository }} + submodules: recursive + fetch-depth: 0 + + - name: Setup Conda Environment + uses: conda-incubator/setup-miniconda@v2 + with: + activate-environment: mhkit-docs + environment-file: environment.yml + auto-activate-base: false + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.GH_PAGES_DEPLOY_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan github.com >> ~/.ssh/known_hosts + + - name: Build Documentation + shell: bash -l {0} + run: | + cd docs + rm -rf _build/* + cp -r ../MHKiT-Python/examples/* source/ + sphinx-build -b html source _build/html + cp ../MHKiT-MATLAB/examples/*.html ./_build/html/mhkit-matlab + touch _build/html/.nojekyll + + - name: Deploy PR Preview + uses: peaceiris/actions-gh-pages@v3 + with: + deploy_key: ${{ secrets.GH_PAGES_DEPLOY_KEY }} + publish_dir: ./docs/_build/html + destination_dir: pr-previews/${{ github.event.inputs.pr_number }} + external_repository: MHKiT-Software/MHKiT + keep_files: true + enable_jekyll: false