From f5d3c536991bac2d9725f5f98151957b7cd9b7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven!=20Ragnar=C3=B6k?= Date: Tue, 20 Aug 2024 14:19:38 -0700 Subject: [PATCH] Update Actions workflows to support deploying to GitHub Pages. (#9) * Add artifact upload to site build. When the build was triggered by a push to the main branch upload the generated output as a GitHub Actions artifact in order to facilitate deployment. * Add GitHub Pages deployment actions. Deploy uploaded artifacts to GitHub Pages. --- .github/workflows/ci.yaml | 9 +++++++- .github/workflows/pages-deploy.yml | 33 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pages-deploy.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d2d2c0d..d7a0b09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,3 +1,5 @@ +--- +name: CI on: push: branches: ["main"] @@ -12,4 +14,9 @@ jobs: - uses: earthly/actions-setup@v1 - name: nanoc compile run: | - earthly --ci +build + earthly --output --ci +build + - name: Upload for GitHub Pages + if: ${{ github.event_name == 'push' }} + uses: actions/upload-pages-artifact@v3 + with: + path: output diff --git a/.github/workflows/pages-deploy.yml b/.github/workflows/pages-deploy.yml new file mode 100644 index 0000000..3051fb0 --- /dev/null +++ b/.github/workflows/pages-deploy.yml @@ -0,0 +1,33 @@ +--- +name: Deploy to GitHub Pages +on: + # NOTE: As of 2024-08-15, this event will only trigger a workflow run if + # the workflow file is on the default branch. + # This is our desired behavior but if this default ever changes we may need + # to add additional guard clauses to make sure we are only deploying + # artifacts from the main branch. + # + # https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run + workflow_run: + workflows: ['CI'] + types: ['completed'] + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + deploy: + permissions: + contents: read + id-token: write + pages: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + if: ${{ github_event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-22.04 + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4