Deploy staging site on Cloudflare Pages (#252) #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: π | |
on: | |
push: | |
branches: ['main'] | |
paths: | |
- '.github/workflows/pages.yml' | |
- 'public/**' | |
- 'deno.jsonc' | |
pull_request: | |
paths: | |
- '.github/workflows/pages.yml' | |
- 'public/**' | |
- 'deno.jsonc' | |
workflow_dispatch: | |
jobs: | |
build: | |
timeout-minutes: 15 | |
runs-on: ubuntu-24.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: denoland/setup-deno@v2 | |
with: | |
deno-version: '2.1.4' # selfup {"extract":"\\d[^']+","replacer":["bash","-c","deno --version | head -n 1"],"nth": 2} | |
- run: deno task get-dependencies | |
- uses: actions/upload-pages-artifact@v3 | |
with: | |
path: 'public' | |
clouflare: | |
if: github.event_name == 'pull_request' | |
needs: [build] | |
timeout-minutes: 15 | |
runs-on: ubuntu-24.04 | |
permissions: | |
contents: read | |
deployments: write | |
pull-requests: write # Required to post comment | |
steps: | |
- name: Download build assets | |
env: | |
GH_TOKEN: ${{ github.token }} | |
# upload-pages-artifact actually uploading artifacts with special structure. So we can download them | |
# See https://github.com/actions/upload-pages-artifact/blob/2d163be3ddce01512f3eea7ac5b7023b5d643ce1/.github/workflows/test-hosted-runners.yml#L37-L45 | |
run: | | |
gh run download --repo '${{ github.repository }}' | |
ls -alh | |
tree | |
- name: Extract the downloaded artifact | |
run: | | |
mkdir dist | |
tar -xf ./github-pages/artifact.tar -C dist | |
ls -alh ./dist | |
tree ./dist | |
- name: Deploy | |
id: deploy | |
uses: cloudflare/wrangler-action@6d58852c35a27e6034745c5d0bc373d739014f7f # v3.13.0 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
# https://developers.cloudflare.com/workers/wrangler/commands/#pages | |
# I use branch for relating to PR number. Not actual git branch. | |
command: pages deploy dist --project-name=kachick-github-io --branch='${{ github.event.pull_request.number }}' | |
gitHubToken: ${{ github.token }} | |
- name: Post comment | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh pr comment --repo '${{ github.repository }}' \ | |
--body 'π ${{ steps.deploy.outputs.deployment-url }}' \ | |
'${{ github.event.pull_request.number }}' | |
github: | |
needs: [build] | |
if: ${{ github.event_name != 'pull_request' }} | |
timeout-minutes: 15 | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
# Allow one concurrent deployment | |
concurrency: | |
group: 'pages' | |
cancel-in-progress: true | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Wait other jobs | |
uses: kachick/wait-other-jobs@v3 | |
with: | |
skip-list: | | |
[ | |
{ | |
"workflowFile": "merge-bot-pr.yml" | |
}, | |
{ | |
"workflowFile": "update-flake-lock-and-ci.yml" | |
} | |
] | |
timeout-minutes: 10 | |
- uses: actions/configure-pages@v5 | |
- id: deployment | |
uses: actions/deploy-pages@v4 |