chore(ci): should not use wrangler versions deploy for PR branch, version upload is all you need
This commit is contained in:
@@ -160,66 +160,6 @@ jobs:
|
||||
echo "deploy_preview_url=$deployment_url" >> "$GITHUB_OUTPUT"
|
||||
echo "pull_request_preview_url=$preview_alias_url" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Workflows
|
||||
#
|
||||
# wrangler versions upload -c ./apps/stage-web/wrangler.toml --preview-alias pr-763 --message "GitHub Actions uploading preview for Pull Request 763" --tag v0.0.1-pr.763
|
||||
# wrangler versions list -c apps/stage-web/wrangler.toml --json | jq -r --arg tag v0.0.1-pr.763 'map(select(.annotations["workers/tag"] == $tag)) | sort_by(.metadata.created_on) | .[] | (.id // empty)'
|
||||
# wrangler versions deploy -c ./apps/stage-web/wrangler.toml -y --message "GitHub Actions deploying preview for Pull Request 763" 2ab3c0ee-7597-4c20-ae5b-23536d7f79ec
|
||||
|
||||
- name: Wrangler Get Version ID
|
||||
if: ${{ steps.build.outcome == 'success' }}
|
||||
id: wrangler-version-id
|
||||
# [
|
||||
# {
|
||||
# "id": "2ab3c0ee-7597-4c20-ae5b-23536d7f79ec",
|
||||
# "number": 4,
|
||||
# "metadata": {
|
||||
# "created_on": "2025-11-27T03:30:56.622177Z",
|
||||
# "source": "wrangler",
|
||||
# "author_id": "04391c4b41bbf6bd8220b4f469918aac",
|
||||
# "author_email": "user@example.com",
|
||||
# "has_preview": true
|
||||
# },
|
||||
# "annotations": {
|
||||
# "workers/alias": "pr-763",
|
||||
# "workers/message": "GitHub Actions deploying preview for PR 763",
|
||||
# "workers/tag": "v0.0.1-pr.763",
|
||||
# "workers/triggered_by": "version_upload"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
# Here we use jq to filter the version with the specific tag we just uploaded,
|
||||
#
|
||||
# - map(input)
|
||||
# - select( if input.[index].annotations.workers/tag === $tag ) // same as filter
|
||||
# - sort_by( input.[index].metadata.created_on ) // sort by created_on
|
||||
# - .[-1] // get the last one (latest)
|
||||
# - .id // get the id field
|
||||
#
|
||||
# Which means we should get the version ID we just uploaded, in this example,
|
||||
# 2ab3c0ee-7597-4c20-ae5b-23536d7f79ec
|
||||
# returned
|
||||
#
|
||||
# Thanks to:
|
||||
# - https://github.com/tuatmcc/tuatmcc.com/blob/b07197c1fb9f4939edcfa78fde96e6ad4e8a7205/.github/workflows/deploy.yml#L130C98-L130C118
|
||||
# - https://github.com/shun-shobon/blog.s2n.tech/blob/51b864301c760414d7dc910308084ffd60625384/.github/workflows/deploy.yml#L102-L109
|
||||
run: |
|
||||
export VERSION_ID=$(wrangler versions list -c ${{ matrix.wrangler_config_path }} --json | jq -r --arg tag v0.0.1-pr.${{ steps.meta.outputs.PR_NUM }} 'map(select(.annotations["workers/tag"] == $tag)) | sort_by(.metadata.created_on) | .[-1] | (.id // empty)')
|
||||
echo "VERSION_ID=$VERSION_ID" >> $GITHUB_OUTPUT
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
|
||||
- name: Wrangler Deploy
|
||||
if: ${{ steps.build.outcome == 'success' }}
|
||||
id: wrangler-deploy
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: versions deploy -c ${{ matrix.wrangler_config_path }} --message "GitHub Actions deploying preview for Pull Request ${{ steps.meta.outputs.PR_NUM }}" -y ${{ steps.wrangler-version-id.outputs.VERSION_ID }}
|
||||
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create or update comment
|
||||
if: ${{ steps.build.outcome == 'success' }}
|
||||
uses: peter-evans/create-or-update-comment@v5
|
||||
|
||||
Reference in New Issue
Block a user