From 321d294b657b5a153cccee887adbbb06d381ebaf Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 May 2024 17:02:36 -0700 Subject: [PATCH 1/9] update actions steps --- .github/workflows/main.yaml | 10 +++++----- .github/workflows/preview.yaml | 6 +++--- .github/workflows/qaqc.yaml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 466e782b..40d0c1e7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -23,14 +23,14 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup JupyterBook Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: _build # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache - key: jupyterbook-20230707 + key: jupyterbook-20240517 - name: Install Conda environment with Micromamba uses: mamba-org/setup-micromamba@v1 @@ -52,14 +52,14 @@ jobs: - name: Save Build if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: build path: _build/ - name: Publish to GitHub Pages if: github.ref == 'refs/heads/main' - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: _build/html diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 6a02c3bf..c80a8ce6 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -14,14 +14,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup JupyterBook Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: _build # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache - key: jupyterbook-20230707 + key: jupyterbook-20240517 - name: Install Conda environment with Micromamba uses: mamba-org/setup-micromamba@v1 diff --git a/.github/workflows/qaqc.yaml b/.github/workflows/qaqc.yaml index 9bdbe69a..8686b7b4 100644 --- a/.github/workflows/qaqc.yaml +++ b/.github/workflows/qaqc.yaml @@ -17,7 +17,7 @@ jobs: shell: bash -el {0} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Conda environment with Micromamba uses: mamba-org/setup-micromamba@v1 From 5132e3212282e0371ef544c79bdf89fdecea42c6 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 May 2024 17:03:26 -0700 Subject: [PATCH 2/9] update actions steps --- .github/dependabot.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3f9192ec..b117cbb3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,11 @@ +# Regularly update Docker tags and Actions steps version: 2 updates: - package-ecosystem: "docker" directory: "/.devcontainer" schedule: interval: "daily" - - package-ecosystem: "github-actions" - directory: "/.github" + - package-ecosystem: "github-actions" + directory: "/.github" schedule: interval: "monthly" From 8346f54766ffae5984c750fadde7720d618415b0 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 May 2024 17:16:03 -0700 Subject: [PATCH 3/9] add failOnError --- .github/workflows/preview.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index c80a8ce6..08f7d748 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -47,6 +47,7 @@ jobs: with: surge_token: ${{ secrets.SURGE_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }} + failOnError: true dist: _build/html build: | npm install surge From a547ed964a8dc9bc87286c908500d9aed4d72f69 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 May 2024 17:38:21 -0700 Subject: [PATCH 4/9] follow docs --- .github/workflows/preview.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 08f7d748..1b9e6778 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -50,7 +50,8 @@ jobs: failOnError: true dist: _build/html build: | - npm install surge + npm install + npm run build - name: Format preview url id: format_url From d11d73487f26ad0ee98ccaa7068b89044ba23c74 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 May 2024 17:54:56 -0700 Subject: [PATCH 5/9] new approach --- .github/workflows/preview.yaml | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 1b9e6778..4f0422b5 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -11,6 +11,8 @@ concurrency: jobs: preview: + env: + PREVIEW_URL: https://{{repository.owner}}-{{repository.name}}-{{job.name}}-pr-{{pr.number}}.surge.sh runs-on: ubuntu-latest steps: - name: Checkout repository @@ -41,26 +43,18 @@ jobs: run: | if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi - - name: Publish to Surge - id: preview_step - uses: afc163/surge-preview@v1 - with: - surge_token: ${{ secrets.SURGE_TOKEN }} - github_token: ${{ secrets.GITHUB_TOKEN }} - failOnError: true - dist: _build/html - build: | - npm install - npm run build - - name: Format preview url id: format_url run: | - echo "url_text=:rocket: Preview deployed at https://${{ steps.preview_step.outputs.preview_url }}" >> $GITHUB_OUTPUT + echo "url_text=:rocket: Preview deployed at >> $GITHUB_OUTPUT + + - name: Install Surge.sh + uses: actions/setup-node@v4 + + - run: npm install -g surge - - name: Get the preview_url - run: echo "${{ steps.format_url.outputs.url_text }}" + - run: surge ./_build/html {{env.PREVIEW_URL}} --token ${{ secrets.SURGE_TOKEN }} - - name: Generate summary + - name: Add URL to Summary run: | - echo "#### ${{ steps.format_url.outputs.url_text }}" >> $GITHUB_STEP_SUMMARY + echo "#### :rocket: Preview deployed at {{env.PREVIEW_URL}}" >> $GITHUB_STEP_SUMMARY From f8af16173a65ff69265eb1d4e2cb8fb3102b324e Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 17 May 2024 17:57:22 -0700 Subject: [PATCH 6/9] cleanup --- .github/workflows/preview.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 4f0422b5..245b90b1 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -43,11 +43,6 @@ jobs: run: | if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi - - name: Format preview url - id: format_url - run: | - echo "url_text=:rocket: Preview deployed at >> $GITHUB_OUTPUT - - name: Install Surge.sh uses: actions/setup-node@v4 From 0f7d3db201ae42774b45f5763c0c42971785cd7c Mon Sep 17 00:00:00 2001 From: Don Setiawan Date: Mon, 20 May 2024 09:58:24 -0700 Subject: [PATCH 7/9] ci: Update SURGE_TOKEN to be accesed via env --- .github/workflows/preview.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 245b90b1..c53ee801 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -48,7 +48,9 @@ jobs: - run: npm install -g surge - - run: surge ./_build/html {{env.PREVIEW_URL}} --token ${{ secrets.SURGE_TOKEN }} + - run: surge ./_build/html {{env.PREVIEW_URL}} --token $SURGE_TOKEN + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} - name: Add URL to Summary run: | From ebee2a726a9e6629ac8e94adf328b27beda248db Mon Sep 17 00:00:00 2001 From: Don Setiawan Date: Mon, 20 May 2024 10:48:48 -0700 Subject: [PATCH 8/9] ci: Change preview to use pull_request_target --- .github/workflows/preview.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index c53ee801..d87172b4 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -1,6 +1,6 @@ name: PR Preview -on: [pull_request] +on: [pull_request_target] permissions: pull-requests: write # allow surge-preview to create/update PR comments From cf65eabd90a2417bc6cd354e3badf4620a007681 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 21 Jun 2024 11:25:09 -0700 Subject: [PATCH 9/9] use workflow_run for surge preview --- .github/workflows/main.yaml | 36 ++++++++++------ .../{preview.yaml => pull_request.yaml} | 40 ++++++++---------- .github/workflows/surge_preview.yml | 42 +++++++++++++++++++ 3 files changed, 83 insertions(+), 35 deletions(-) rename .github/workflows/{preview.yaml => pull_request.yaml} (55%) create mode 100644 .github/workflows/surge_preview.yml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 40d0c1e7..b2b827b6 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,10 +1,8 @@ -name: CI +name: Deploy Website to GitHub Pages on: push: branches: main - pull_request: - branches: main # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: @@ -18,7 +16,7 @@ concurrency: cancel-in-progress: true jobs: - build-and-deploy: + build: runs-on: ubuntu-latest steps: @@ -50,19 +48,31 @@ jobs: run: | if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi - - name: Save Build + - name: Save Build Folder if: always() uses: actions/upload-artifact@v4 with: name: build path: _build/ - - name: Publish to GitHub Pages - if: github.ref == 'refs/heads/main' - uses: peaceiris/actions-gh-pages@v4 + - name: Upload Pages Artifact + uses: actions/upload-pages-artifact@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: _build/html - publish_branch: gh-pages - cname: tutorial.xarray.dev - enable_jekyll: false + path: _build/html + + # Publish Website to GitHub Pages if built successfully + deploy: + needs: build + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/preview.yaml b/.github/workflows/pull_request.yaml similarity index 55% rename from .github/workflows/preview.yaml rename to .github/workflows/pull_request.yaml index d87172b4..bb8218b0 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/pull_request.yaml @@ -1,9 +1,8 @@ -name: PR Preview +name: Pull Request Build -on: [pull_request_target] - -permissions: - pull-requests: write # allow surge-preview to create/update PR comments +on: + pull_request: + types: [opened, synchronize, reopened, closed] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -11,14 +10,17 @@ concurrency: jobs: preview: - env: - PREVIEW_URL: https://{{repository.owner}}-{{repository.name}}-{{job.name}}-pr-{{pr.number}}.surge.sh runs-on: ubuntu-latest + defaults: + run: + shell: bash -el {0} steps: - name: Checkout repository + if: github.event.action != 'closed' uses: actions/checkout@v4 - name: Setup JupyterBook Cache + if: github.event.action != 'closed' uses: actions/cache@v4 with: path: _build @@ -26,6 +28,7 @@ jobs: key: jupyterbook-20240517 - name: Install Conda environment with Micromamba + if: github.event.action != 'closed' uses: mamba-org/setup-micromamba@v1 with: environment-file: conda/conda-lock.yml @@ -33,25 +36,18 @@ jobs: cache-environment: true - name: Build JupyterBook - # NOTE: login shell activates conda environment - shell: bash -l {0} + if: github.event.action != 'closed' run: | jupyter-book build ./ --warningiserror --keep-going - name: Dump Build Logs - if: always() + if: github.event.action != 'closed' run: | if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi - - name: Install Surge.sh - uses: actions/setup-node@v4 - - - run: npm install -g surge - - - run: surge ./_build/html {{env.PREVIEW_URL}} --token $SURGE_TOKEN - env: - SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} - - - name: Add URL to Summary - run: | - echo "#### :rocket: Preview deployed at {{env.PREVIEW_URL}}" >> $GITHUB_STEP_SUMMARY + - name: Upload artifact + if: github.event.action != 'closed' + uses: actions/upload-artifact@v4 + with: + name: html + path: book/_build/html diff --git a/.github/workflows/surge_preview.yml b/.github/workflows/surge_preview.yml new file mode 100644 index 00000000..69937ab7 --- /dev/null +++ b/.github/workflows/surge_preview.yml @@ -0,0 +1,42 @@ +name: Pull Request Preview + +on: + workflow_run: + workflows: ["Pull Request Build"] + types: + - completed + +permissions: + pull-requests: write # allow surge-preview to create/update PR comments + +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.id }} + cancel-in-progress: true + +jobs: + # NOTE: match job name in pull_request.yaml + preview: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + + steps: + # Ensure folder exists for PR 'closed' case + - run: mkdir html + + # Download built HTML from PR Build workflow + - uses: actions/download-artifact@v4 + continue-on-error: true + with: + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Manage Surge.sh Deployment + id: preview_step + uses: afc163/surge-preview@v1 + with: + surge_token: ${{ secrets.SURGE_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} + build: echo 'Uploading html/ folder contents to Surge.sh...' + dist: html # NOTE: match upload_artifact name in pull_request.yaml + failOnError: true + teardown: true