Skip to content

Commit 3691027

Browse files
authored
Merge branch 'dev' into chore/migrate-to-pnpm
2 parents 7cdcd41 + a24dd7c commit 3691027

1 file changed

Lines changed: 36 additions & 16 deletions

File tree

.github/workflows/cloudflare-web-preview.yml

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ on:
1111
- 'tsconfig.json'
1212
- '.github/workflows/cloudflare-web-preview.yml'
1313
- '.github/actions/setup/**'
14+
push:
15+
branches:
16+
- dev
17+
paths:
18+
- 'src/**'
19+
- 'index.html'
20+
- 'package.json'
21+
- 'package-lock.json'
22+
- 'vite.config.ts'
23+
- 'tsconfig.json'
24+
- '.github/workflows/cloudflare-web-preview.yml'
25+
- '.github/actions/setup/**'
1426

1527
concurrency:
16-
group: cloudflare-worker-preview-${{ github.event.pull_request.number }}
28+
group: cloudflare-worker-preview-${{ github.event.pull_request.number || github.ref_name }}
1729
cancel-in-progress: true
1830

1931
jobs:
2032
deploy:
21-
if: github.event.pull_request.head.repo.full_name == github.repository
33+
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push'
2234
runs-on: ubuntu-latest
2335
permissions:
2436
contents: read
@@ -47,6 +59,18 @@ jobs:
4759
with:
4860
build: 'true'
4961

62+
- name: Set deploy alias
63+
id: alias
64+
shell: bash
65+
run: |
66+
if [ "${{ github.event_name }}" = "pull_request" ]; then
67+
echo "alias=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
68+
else
69+
branch="${{ github.ref_name }}"
70+
alias="$(echo "$branch" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-\|-$//g')"
71+
echo "alias=${alias}" >> "$GITHUB_OUTPUT"
72+
fi
73+
5074
- name: Upload Worker preview
5175
id: deploy
5276
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
@@ -58,44 +82,40 @@ jobs:
5882
command: >
5983
versions upload
6084
-c dist/wrangler.json
61-
--preview-alias pr-${{ github.event.pull_request.number }}
85+
--preview-alias ${{ steps.alias.outputs.alias }}
6286
--message "$PREVIEW_MESSAGE"
6387
6488
- name: Resolve preview URL
6589
id: preview
6690
env:
6791
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
6892
COMMAND_OUTPUT: ${{ steps.deploy.outputs.command-output }}
69-
PR_NUMBER: ${{ github.event.pull_request.number }}
93+
ALIAS: ${{ steps.alias.outputs.alias }}
7094
shell: bash
7195
run: |
72-
alias="pr-${PR_NUMBER}"
96+
alias_url_pattern="^https?://${ALIAS}-[^[:space:]]+$"
7397
preview_url=""
74-
alias_url_pattern="^https?://${alias}-[^[:space:]]+$"
7598
7699
if printf '%s\n' "$DEPLOYMENT_URL" | grep -Eq "$alias_url_pattern"; then
77100
preview_url="$DEPLOYMENT_URL"
78101
else
79-
preview_url="$(printf '%s\n' "$COMMAND_OUTPUT" | grep -Eo "https?://${alias}-[^[:space:]\"'<>)]+" | head -n 1 || true)"
102+
preview_url="$(printf '%s\n' "$COMMAND_OUTPUT" | grep -Eo "https?://${ALIAS}-[^[:space:]\"'<>)]+" | head -n 1 || true)"
80103
fi
81104
82105
if ! printf '%s\n' "$preview_url" | grep -Eq "$alias_url_pattern"; then
83106
echo "Failed to resolve aliased Worker preview URL." >&2
84107
exit 1
85108
fi
86109
87-
{
88-
echo "preview_alias=${alias}"
89-
echo "preview_url=${preview_url}"
90-
} >> "$GITHUB_OUTPUT"
110+
echo "preview_url=${preview_url}" >> "$GITHUB_OUTPUT"
91111
92-
- name: Publish preview URL and write summary
112+
- name: Publish summary and PR comment
93113
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
94114
env:
95115
MARKER: '<!-- cloudflare-worker-preview -->'
96116
PREVIEW_URL: ${{ steps.preview.outputs.preview_url }}
97-
PREVIEW_ALIAS: ${{ steps.preview.outputs.preview_alias }}
98-
SHORT_SHA: ${{ github.event.pull_request.head.sha }}
117+
PREVIEW_ALIAS: ${{ steps.alias.outputs.alias }}
118+
SHORT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
99119
with:
100120
github-token: ${{ secrets.GITHUB_TOKEN }}
101121
script: |
@@ -120,10 +140,10 @@ jobs:
120140
tableRow,
121141
].join("\n");
122142
123-
// Write to step summary (marker stripped — not needed there)
124143
await core.summary.addRaw(comment.replace(marker + "\n", "")).write();
125144
126-
// Always delete and recreate so the comment appears fresh after each push
145+
if (context.eventName !== 'pull_request') return;
146+
127147
const { owner, repo } = context.repo;
128148
const issue_number = context.issue.number;
129149
const comments = await github.paginate(github.rest.issues.listComments, {

0 commit comments

Comments
 (0)