diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d8e6943..14c48ee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,6 +41,8 @@ jobs: advanced-security: false annotations: true + # Runs repo code and dependencies, so it must never see deploy credentials: + # CLOUDFLARE_* lives only in the static-deploy environment. release: needs: [verify, zizmor] runs-on: ubuntu-latest @@ -49,7 +51,6 @@ jobs: permissions: contents: write # create tag and GitHub release id-token: write # npm trusted publishing and provenance - deployments: write # GitHub deployment created by cloudflare/wrangler-action steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -63,6 +64,14 @@ jobs: - name: Build run: pnpm build + - name: Upload site artifact + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: site + path: public + if-no-files-found: error + retention-days: 3 + - name: Semantic Release uses: cycjimmy/semantic-release-action@ad51787758d9654d5a75150a89a6fa9b3ccef95e # v8.1.4 with: @@ -70,19 +79,43 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} - # wrangler comes from the lockfile (devDependencies), so the action installs nothing. + # Holds the deploy credentials, so it must never execute code from the repo. + deploy: + needs: release + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + deployments: write # GitHub deployment created by cloudflare/wrangler-action + # Any branch can push a workflow naming this environment, so its "Selected + # branches" policy is the only thing keeping other branches away from the + # Cloudflare token. Keep it limited to the release branches above. + environment: + name: static-deploy + + steps: + - name: Download site artifact + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: site + path: site/public + + # No checkout here, so wrangler is installed at a pinned version and branch + # and commit are passed explicitly instead of being read from the working tree. - name: Publish to Cloudflare Pages uses: cloudflare/wrangler-action@953926a2e2182532811c01a25e53647d93bf07c0 # v4.1.3 with: + wranglerVersion: "4.162.0" + packageManager: npm + workingDirectory: site apiToken: ${{ secrets.CLOUDFLARE_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT }} - command: pages deploy public --project-name=${{ secrets.CF_PROJECT_NAME }} + command: pages deploy public --project-name=${{ vars.CF_PROJECT_NAME }} --branch=${{ github.ref_name }} --commit-hash=${{ github.sha }} --commit-dirty=true gitHubToken: ${{ github.token }} - uses: mfinelli/cloudflare-pages-cleanup@2e6030667fd700c74509c10050adb0df151f0556 # v1.1.0 with: cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT }} cloudflare_api_token: ${{ secrets.CLOUDFLARE_TOKEN }} - project: ${{ secrets.CF_PROJECT_NAME }} + project: ${{ vars.CF_PROJECT_NAME }} min-to-keep: 0 max-to-keep: 0