feat: add github action to deploy to cloudflare pages #25
Workflow file for this run
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: Deploy to Cloudflare Pages | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- "main" | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
ref: ${{ github.ref }} | ||
- name: debug | ||
run: | | ||
echo ${{github.event.pull_request.base.sha}} | ||
echo ${{github.ref}} | ||
- name: Get Head Commit Message | ||
shell: bash | ||
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 }}) | | ||
--- |