Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(.github/workflows/worker.yml): use wrangler versions upload instead of dry run #1270

Merged
merged 13 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions .github/workflows/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ jobs:
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
Expand All @@ -88,11 +90,39 @@ jobs:
args=$(mise run worker:wrangler-args)
echo "args=${args}" >> "${GITHUB_OUTPUT}"

- name: Deploy to Cloudflare workers with Wrangler
- name: Get Commit SHA and Message
id: commit
run: |
sha=${{ github.event.pull_request.head.sha || github.sha }}
short_sha=$(git rev-parse --short "${sha}")
message=$(git log --format=%B --max-count=1 "${sha}")
echo "short_sha=${short_sha}" >> "${GITHUB_OUTPUT}"
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: deploy --dry-run ${{ steps.wrangler-args.outputs.args }}
# tag length is limited to 25 characters
command: >-
versions upload --tag ${{ steps.commit.outputs.short_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
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:
Expand Down
1 change: 1 addition & 0 deletions yamlfmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ formatter:
type: basic
# line breaks for readability
retain_line_breaks_single: true
scan_folded_as_literal: true
# GitHub Actions does not support anchors
# ref: https://github.com/actions/runner/issues/1182
disallow_anchors: true
Loading