Skip to content

feat: add github action to deploy to cloudflare pages #21

feat: add github action to deploy to cloudflare pages

feat: add github action to deploy to cloudflare pages #21

Workflow file for this run

name: Deploy to Cloudflare Pages
on:
pull_request:
push:
branches:
- "main"
jobs:
deploy:
runs-on: ubuntu-latest
# permissions:
# contents: read
# deployments: write
# pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get Head Commit Message
id: get_head_commit_message
run: echo "HEAD_COMMIT_MESSAGE=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT"
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
# stolen from: https://github.com/cloudflare/pages-action/issues/16#issuecomment-1398478711
- name: Comment deploy start
if: github.event_name != 'push'
uses: mshick/add-pr-comment@v2
with:
message-id: cloudflare-deploy
message: |
### <span aria-hidden="true">🚧</span> Deploy Preview building...
| Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">πŸ”¨</span> Latest commit | ${{ github.sha }} |
|<span aria-hidden="true">πŸ”</span> Latest deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
---
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.81.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.2"
- name: Install wasm-pack
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Install npm dependencies
working-directory: crates/org-wasm
run: npm install
- name: Generate wasm binaries
working-directory: crates/org-wasm
run: wasm-pack build --release --target bundler
- name: Deploy npm
working-directory: crates/org-wasm
run: npm run deploy
- name: Publish to Cloudflare
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy crates/org-wasm/dist --project-name=org-rust --branch ${{ steps.extract_branch.outputs.branch }} --commit-hash ${{ github.sha }} --commit-message ${{ github.event.workflow_run.head_commit.message }}
- name: Comment deploy url
uses: mshick/add-pr-comment@v2
with:
message-id: cloudflare-deploy
message: |
### <span aria-hidden="true">βœ…</span> Deploy Preview ready!
| Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">πŸ”¨</span> Latest commit | ${{ github.sha }} |
|<span aria-hidden="true">πŸ”</span> Latest deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
|<span aria-hidden="true">😎</span> Deploy Preview Url | [${{ steps.deploy.outputs.pages-deployment-alias-url }}](${{ steps.deploy.outputs.pages-deployment-alias-url }}) |
---