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" diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 466e782b..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,19 +16,19 @@ concurrency: cancel-in-progress: true jobs: - build-and-deploy: + build: 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 @@ -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@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 + - 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/preview.yaml deleted file mode 100644 index 6a02c3bf..00000000 --- a/.github/workflows/preview.yaml +++ /dev/null @@ -1,64 +0,0 @@ -name: PR Preview - -on: [pull_request] - -permissions: - pull-requests: write # allow surge-preview to create/update PR comments - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - preview: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup JupyterBook Cache - uses: actions/cache@v3 - with: - path: _build - # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache - key: jupyterbook-20230707 - - - name: Install Conda environment with Micromamba - uses: mamba-org/setup-micromamba@v1 - with: - environment-file: conda/conda-lock.yml - environment-name: xarray-tutorial - cache-environment: true - - - name: Build JupyterBook - # NOTE: login shell activates conda environment - shell: bash -l {0} - run: | - jupyter-book build ./ --warningiserror --keep-going - - - name: Dump Build Logs - if: always() - 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 }} - dist: _build/html - build: | - npm install surge - - - name: Format preview url - id: format_url - run: | - echo "url_text=:rocket: Preview deployed at https://${{ steps.preview_step.outputs.preview_url }}" >> $GITHUB_OUTPUT - - - name: Get the preview_url - run: echo "${{ steps.format_url.outputs.url_text }}" - - - name: Generate summary - run: | - echo "#### ${{ steps.format_url.outputs.url_text }}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 00000000..bb8218b0 --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,53 @@ +name: Pull Request Build + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + preview: + 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 + # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache + 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 + environment-name: xarray-tutorial + cache-environment: true + + - name: Build JupyterBook + if: github.event.action != 'closed' + run: | + jupyter-book build ./ --warningiserror --keep-going + + - name: Dump Build Logs + if: github.event.action != 'closed' + run: | + if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi + + - 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/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 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