ci(.github/workflows/worker.yml): use wrangler versions upload instead of dry run #3587
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: Cloudflare worker | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * SUN" | |
permissions: {} | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
test-worker: | |
runs-on: ubuntu-24.04 | |
timeout-minutes: 10 | |
permissions: | |
contents: read # for checkout | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
sparse-checkout: | | |
mise.toml | |
tasks.toml | |
tasks/* | |
worker/* | |
sparse-checkout-cone-mode: false | |
persist-credentials: false | |
- name: Install mise | |
uses: jdx/mise-action@5083fe46898c414b2475087cc79da59e7da859e8 # v2.1.11 | |
with: | |
version: 2025.1.4 | |
cache_save: ${{ github.ref_name == 'main' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Run tests | |
run: mise run worker:test | |
deploy-worker: | |
needs: | |
- test-worker | |
# skip for main branch as Cloudflare workers builds will deploy automatically | |
if: github.event_name != 'push' | |
runs-on: ubuntu-24.04 | |
timeout-minutes: 10 | |
permissions: | |
contents: read # for checkout | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
sparse-checkout: | | |
mise.toml | |
tasks.toml | |
tasks/* | |
worker/* | |
sparse-checkout-cone-mode: false | |
persist-credentials: false | |
# set fetch-depth to 2 for pull requests to get the head commit, not only the merge commit | |
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 1 }} | |
- name: Install mise | |
uses: jdx/mise-action@5083fe46898c414b2475087cc79da59e7da859e8 # v2.1.11 | |
with: | |
version: 2025.1.4 | |
cache_save: ${{ github.ref_name == 'main' }} | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Install package.json dependencies | |
run: mise run buni:worker | |
- name: Get Wrangler args | |
id: wrangler-args | |
run: | | |
args=$(mise run worker:wrangler-args) | |
echo "args=${args}" >> "${GITHUB_OUTPUT}" | |
- name: Get Commit SHA and Message | |
id: commit | |
run: | | |
sha=${{ github.event.pull_request.head.sha || github.sha }} | |
message=$(git log --format=%B --max-count=1 "${sha}") | |
echo "message=${message}" >> "${GITHUB_OUTPUT}" | |
- name: Upload a Version of Cloudflare Workers with Wrangler | |
id: deploy | |
uses: cloudflare/wrangler-action@6d58852c35a27e6034745c5d0bc373d739014f7f # v3.13.0 | |
with: | |
workingDirectory: worker | |
command: >- | |
versions upload --tag ${{ steps.commit.outputs.sha }} | |
--message ${{ steps.commit.outputs.message }} | |
${{ steps.wrangler-args.outputs.args }} | |
apiToken: ${{ secrets.CLOUDFLARE_WORKERS_API_TOKEN }} | |
accountId: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} | |
- name: Generate Job Summary | |
if: ${{ !cancelled() }} | |
run: | | |
worker_name=$(echo "${{ steps.deploy.outputs.command-output }}" \ | |
| grep --only-matching --perl-regexp '^Uploaded \K[^ ]+') | |
version_id=$(echo "${{ steps.deploy.outputs.command-output }}" \ | |
| grep --only-matching --perl-regexp '^Worker Version ID: \K.+') | |
preview_url=$(echo "${{ steps.deploy.outputs.command-output }}" \ | |
| grep --only-matching --perl-regexp '^Version Preview URL: \K.+') | |
echo "# ${worker_name} | |
- Version ID: ${version_id} | |
- Preview URL: ${preview_url}" >> "${GITHUB_STEP_SUMMARY}" | |
actions-timeline: | |
needs: | |
- deploy-worker | |
if: ${{ !cancelled() }} | |
runs-on: ubuntu-24.04 | |
timeout-minutes: 5 | |
permissions: | |
actions: read # for actions-timeline | |
steps: | |
- name: actions-timeline | |
# cspell:ignore kesin | |
uses: Kesin11/actions-timeline@3046833d9aacfd7745c5264b7f3af851c3e2a619 # v2.2.1 |