Created
November 2, 2025 09:36
-
-
Save thelovekesh/32659f81d88191616feacded42bc8636 to your computer and use it in GitHub Desktop.
workflow to create cf workers dev preview, comment on pull requests, and support multi-workers setup
This file contains hidden or 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: workers dev preview | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| paths: | |
| - 'src/**' | |
| - 'workers/**' | |
| - 'bun.lock' | |
| - '.github/workflows/workers-dev-preview.yml' | |
| concurrency: | |
| group: ${{ github.workflow }} | |
| permissions: {} | |
| jobs: | |
| deploy-preview: | |
| name: ${{ matrix.worker }} | |
| if: github.event.pull_request.user.login != 'dependabot[bot]' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| timeout-minutes: 5 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| worker: [worker-1, worker-2, worker-3] # add worker names | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2 | |
| - name: setup bun | |
| uses: ./.github/actions/setup-bun | |
| with: | |
| gha-runner: true | |
| - name: build assets | |
| if: matrix.worker == 'app' | |
| run: bun build:prod | |
| - name: upload preview version | |
| id: upload-preview-version | |
| uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 #v3.14.1 | |
| with: | |
| packageManager: bun | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| command: | | |
| versions upload --tag ${{ github.event.number }} --env dev --cwd workers/${{ matrix.worker }} | |
| - name: find old comment | |
| id: find-comment | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 | |
| with: | |
| script: | | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const comment = comments.find((comment) => comment.body.includes('${{ matrix.worker }} preview url:')); | |
| return comment ? comment.id : false; | |
| - name: prepare comment body | |
| id: comment-body | |
| run: | | |
| { | |
| echo 'body<<EOF' | |
| echo "${{ matrix.worker }} preview url: [$preview_url]($preview_url)" | |
| echo EOF | |
| } >> $GITHUB_OUTPUT | |
| env: | |
| preview_url: ${{ steps.upload-preview-version.outputs.deployment-url }} | |
| - name: create comment | |
| if: ${{ steps.find-comment.outputs.result == 'false' }} | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: `${{ steps.comment-body.outputs.body }}`, | |
| }); | |
| - name: update comment | |
| if: ${{ steps.find-comment.outputs.result != 'false' }} | |
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 | |
| with: | |
| script: | | |
| github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: ${{ steps.find-comment.outputs.result }}, | |
| body: `${{ steps.comment-body.outputs.body }}`, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment