diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index a9f9712..cf5cf10 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -5,6 +5,11 @@ name: Pages # Publishing a release redeploys the site if the github-pages environment # allows v* tags. Enable Pages with "GitHub Actions" as the source in the # repository settings. +# +# Pages keeps the first deployment of each build version, and +# actions/deploy-pages always uses the commit as the version. A release +# published on the commit main was last deployed from then changed nothing +# (0.6.0 did that), so the deploy step below gives every run its own version. on: push: @@ -58,10 +63,14 @@ jobs: run: npm run build:site - name: Upload site + id: upload uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 with: path: web/dist + outputs: + artifact_id: ${{ steps.upload.outputs.artifact_id }} + deploy: name: Deploy needs: build @@ -75,6 +84,28 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} steps: + # The same API calls as actions/deploy-pages, with a build version of + # its own for each run. - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 + env: + GH_TOKEN: ${{ github.token }} + ARTIFACT_ID: ${{ needs.build.outputs.artifact_id }} + BUILD_VERSION: ${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }} + run: | + oidc=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value) + status_url=$(gh api "repos/$GITHUB_REPOSITORY/pages/deployments" \ + -F artifact_id="$ARTIFACT_ID" -f pages_build_version="$BUILD_VERSION" -f oidc_token="$oidc" -q .status_url) + echo "deployment $BUILD_VERSION" + status= + for _ in $(seq 100); do + sleep 5 + status=$(gh api "$status_url" -q .status || echo unknown_status) + echo "status: $status" + case $status in + succeed) break ;; + deployment_failed|deployment_content_failed|deployment_cancelled|deployment_lost) exit 1 ;; + esac + done + [ "$status" = succeed ] || { echo "no result after 500 s"; exit 1; } + echo "page_url=$(gh api "repos/$GITHUB_REPOSITORY/pages" -q .html_url)" >> "$GITHUB_OUTPUT"