From 90969b523256d8181f6103e7564d9f8a8fb8fcdc Mon Sep 17 00:00:00 2001 From: Alexandre Chabot-Leclerc Date: Wed, 6 Mar 2024 12:08:36 -0600 Subject: [PATCH 1/7] Fix make target name --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 011719d..775612b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -38,7 +38,7 @@ jobs: cache: "pip" - name: Install dependencies - run: make install + run: make init - name: Build website run: make clean && make publish From 3e9a121dce7efefc441f5fdfa03d684ea52d9044 Mon Sep 17 00:00:00 2001 From: Alexandre Chabot-Leclerc Date: Wed, 6 Mar 2024 13:46:08 -0600 Subject: [PATCH 2/7] Enable the workflow to write contents --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 775612b..f3f52e7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ on: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: - contents: read + contents: write pages: write id-token: write From 35857182b34b1ebd39687f8ec73100603eb7a0b8 Mon Sep 17 00:00:00 2001 From: Alexandre Chabot-Leclerc Date: Wed, 6 Mar 2024 13:46:24 -0600 Subject: [PATCH 3/7] Remove actions/configure-pages AFAIK, we don't need the metadata. https://github.com/actions/configure-pages/ --- .github/workflows/publish.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f3f52e7..b7bd659 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,9 +28,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup Pages - uses: actions/configure-pages@v4 - - name: Set up Python uses: actions/setup-python@v5 with: From e8695dc2f94f46c87fcbd3da28cb1293f6b3a90f Mon Sep 17 00:00:00 2001 From: Alexandre Chabot-Leclerc Date: Wed, 6 Mar 2024 13:52:42 -0600 Subject: [PATCH 4/7] Force push (with lease) the gh-pages Because we're not keeping the history of the gh-pages branch, we end up with a new commit every time. Github refuses that we push that branch because it doesn't match the history. --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b7bd659..b944084 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -46,5 +46,5 @@ jobs: git config user.email "actions@users.noreply.github.com" timestamp=$(date -u +%FT%T%z) ghp-import -m "Generate Pelican site ${timestamp}" --no-history --branch gh-pages output - git push origin gh-pages + git push --force-with-lease origin gh-pages From 8ba78f4049ffe432309676e39a2e67917167d7ad Mon Sep 17 00:00:00 2001 From: Alexandre Chabot-Leclerc Date: Wed, 6 Mar 2024 13:55:33 -0600 Subject: [PATCH 5/7] Good old --force --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b944084..e587ec2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -46,5 +46,5 @@ jobs: git config user.email "actions@users.noreply.github.com" timestamp=$(date -u +%FT%T%z) ghp-import -m "Generate Pelican site ${timestamp}" --no-history --branch gh-pages output - git push --force-with-lease origin gh-pages + git push --force origin gh-pages From 6ffa9a1e639dce7e7ba8db4c6fb363cf0cffdb85 Mon Sep 17 00:00:00 2001 From: Alexandre Chabot-Leclerc Date: Wed, 6 Mar 2024 15:43:01 -0600 Subject: [PATCH 6/7] Pass cname when creating the gh-pages The docs [1] adds a CNAME file if you're publishing from a branch. But since the action wipes the `gh-pages` branch every time, I think the CNAME file will go away. ghp-import has the option to recreate it every time. [1]: https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#configuring-a-subdomain --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e587ec2..dad19b0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -45,6 +45,6 @@ jobs: git config user.name "Automated" git config user.email "actions@users.noreply.github.com" timestamp=$(date -u +%FT%T%z) - ghp-import -m "Generate Pelican site ${timestamp}" --no-history --branch gh-pages output + ghp-import -m "Generate Pelican site ${timestamp}" --no-history --cname 'conference.scipy.org' --branch gh-pages output git push --force origin gh-pages From 9d6c2dda0ab2fadebcc02034903ecbac3ac205b6 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 6 Mar 2024 18:00:55 -0600 Subject: [PATCH 7/7] ci: Use GitHub Actions to perform deployment * Run on push events to 'main' as the default branch has been renamed from 'master'. * Add running the build job on pull_request events to allow testing builds of the website in advance. * Scope concurrency to the workflow level, which allows for per branch runs to not conflict. * Split the workflow into a build and deploy job. In the build job have the built website be uploaded as a run artifact. In the deploy job this artifact is then downloaded and and deployed to GitHub Pages. - For the deploy job, set the permissions to allow for the default GITHUB_TOKEN to perform the deployment. - Use the github-pages environment as required by GitHub Actions. - Run the deploy job on either: * push events to main (a merged PR) * workflow_dispatch events that happen on any branch, to allow for hotfixing --- .github/workflows/publish.yml | 56 ++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index dad19b0..1a3b768 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,22 +3,18 @@ name: Deploy to GitHub Pages on: # Runs on pushes targeting the default branch push: - branches: ["master"] + branches: ["main"] + + # Ensure the docs build on PR + pull_request: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: write - pages: write - id-token: write - # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: - group: "pages" - cancel-in-progress: false + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: # Build job @@ -40,11 +36,37 @@ jobs: - name: Build website run: make clean && make publish - - name: Commit output to gh-pages branch + - name: Fix permissions if needed run: | - git config user.name "Automated" - git config user.email "actions@users.noreply.github.com" - timestamp=$(date -u +%FT%T%z) - ghp-import -m "Generate Pelican site ${timestamp}" --no-history --cname 'conference.scipy.org' --branch gh-pages output - git push --force origin gh-pages - + chmod -c -R +rX "output/" | while read line; do + echo "::warning title=Invalid file permissions automatically fixed::$line" + done + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: 'output/' + + deploy: + name: Deploy to GitHub Pages + # Deploy on push event to main or with any branch and workflow dispatch + if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' + needs: build + # Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + + steps: + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4