|
| 1 | +name: Cloudflare Workers (Preview) Comment |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - Cloudflare Workers (Preview) |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +env: |
| 11 | + PR_NUM: 0 |
| 12 | + BRANCH_NAME: main |
| 13 | + |
| 14 | +jobs: |
| 15 | + on-success: |
| 16 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 17 | + name: Deploy |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + pull-requests: write |
| 23 | + |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - app_name: stage-web |
| 28 | + artifact_name: preview-build-stage-web |
| 29 | + artifact_path: ./apps/stage-web/dist |
| 30 | + deploy_command: version deploy -c ./apps/stage-web/wrangler.toml |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v6 |
| 34 | + # Turborepo |
| 35 | + - name: Cache turbo build setup |
| 36 | + uses: actions/cache@v4 |
| 37 | + with: |
| 38 | + path: .turbo |
| 39 | + key: ${{ runner.os }}-turbo-${{ github.sha }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-turbo- |
| 42 | + - uses: pnpm/action-setup@v4 |
| 43 | + - uses: actions/setup-node@v6 |
| 44 | + with: |
| 45 | + node-version: lts/* |
| 46 | + cache: pnpm |
| 47 | + |
| 48 | + # NOTICE: |
| 49 | + # |
| 50 | + # Here installing wrangler to global is required, or otherwise: |
| 51 | + # ERR_PNPM_ADDING_TO_ROOT Running this command will add the dependency to the workspace root... |
| 52 | + # error occurs. |
| 53 | + # |
| 54 | + # Since https://github.com/cloudflare/wrangler-action/pull/339#issuecomment-2667622947 rejected the -g support |
| 55 | + # by saying un-reasonable 'I'm not sure if it's common ... to install packages to the global scope, ... might be introducing some unintended side effects.' |
| 56 | + # |
| 57 | + # Clearly I think installing with `<packageManager> install` brings more unintended side effects... |
| 58 | + # |
| 59 | + # As suggested by https://github.com/cloudflare/wrangler-action/issues/181#issuecomment-2127990708, we should pre-install |
| 60 | + # with our package manager and then use it in the action. |
| 61 | + - run: pnpm i -g wrangler@4 |
| 62 | + |
| 63 | + - name: Download artifact - PR |
| 64 | + uses: dawidd6/action-download-artifact@v11 |
| 65 | + with: |
| 66 | + workflow_conclusion: success |
| 67 | + run_id: ${{ github.event.workflow_run.id }} |
| 68 | + name: pr-num |
| 69 | + path: pr-num |
| 70 | + allow_forks: true |
| 71 | + |
| 72 | + - name: Download artifact - PR |
| 73 | + uses: dawidd6/action-download-artifact@v11 |
| 74 | + with: |
| 75 | + workflow_conclusion: success |
| 76 | + run_id: ${{ github.event.workflow_run.id }} |
| 77 | + name: branch-name |
| 78 | + path: branch-name |
| 79 | + allow_forks: true |
| 80 | + |
| 81 | + - name: Obtain PR number |
| 82 | + id: pr-num |
| 83 | + run: | |
| 84 | + echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV |
| 85 | +
|
| 86 | + - name: Obtain branch name |
| 87 | + id: branch-name |
| 88 | + run: | |
| 89 | + echo "BRANCH_NAME=$(cat branch-name/branch_name)" >> $GITHUB_ENV |
| 90 | +
|
| 91 | + - name: Download artifact |
| 92 | + uses: dawidd6/action-download-artifact@v11 |
| 93 | + with: |
| 94 | + workflow_conclusion: success |
| 95 | + run_id: ${{ github.event.workflow_run.id }} |
| 96 | + name: preview-build-stage-web |
| 97 | + path: ./apps/stage-web/dist |
| 98 | + allow_forks: true |
| 99 | + |
| 100 | + - name: Upload |
| 101 | + id: deploy |
| 102 | + uses: cloudflare/wrangler-action@v3 |
| 103 | + with: |
| 104 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 105 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 106 | + command: ${{ matrix.deploy_command }} |
| 107 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 108 | + |
| 109 | + - name: Find Comment |
| 110 | + uses: peter-evans/find-comment@v4 |
| 111 | + id: fc |
| 112 | + with: |
| 113 | + issue-number: ${{ env.PR_NUM }} |
| 114 | + comment-author: 'github-actions[bot]' |
| 115 | + body-includes: to Cloudflare Workers (Preview) for *${{ matrix.app_name }}* |
| 116 | + |
| 117 | + - name: Create or update comment |
| 118 | + uses: peter-evans/create-or-update-comment@v5 |
| 119 | + with: |
| 120 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 121 | + issue-number: ${{ env.PR_NUM }} |
| 122 | + edit-mode: replace |
| 123 | + body: | |
| 124 | + ## ✅ Deploy to Cloudflare Workers (Preview) for *${{ matrix.app_name }}* ready! |
| 125 | +
|
| 126 | + | Name | Link | |
| 127 | + |:-----------------------|:---------------------------------------------------------------------------------------------| |
| 128 | + | 🔍 Latest deploy log | https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | |
| 129 | + | 😎 Deploy Preview | ${{ steps.deploy.outputs.deployment-url }} | |
| 130 | +
|
| 131 | + on-failure: |
| 132 | + if: ${{ github.event.workflow_run.conclusion == 'failure' }} |
| 133 | + name: Failed to build previewing docs |
| 134 | + runs-on: ubuntu-latest |
| 135 | + |
| 136 | + permissions: |
| 137 | + pull-requests: write |
| 138 | + |
| 139 | + strategy: |
| 140 | + matrix: |
| 141 | + include: |
| 142 | + - app_name: stage-web |
| 143 | + |
| 144 | + steps: |
| 145 | + - name: Download artifact - PR |
| 146 | + uses: dawidd6/action-download-artifact@v11 |
| 147 | + with: |
| 148 | + workflow_conclusion: success |
| 149 | + run_id: ${{ github.event.workflow_run.id }} |
| 150 | + name: pr-num |
| 151 | + path: pr-num |
| 152 | + allow_forks: true |
| 153 | + |
| 154 | + - name: Obtain PR number |
| 155 | + id: pr-num |
| 156 | + run: | |
| 157 | + echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV |
| 158 | +
|
| 159 | + - name: Find Comment |
| 160 | + uses: peter-evans/find-comment@v4 |
| 161 | + id: fc |
| 162 | + with: |
| 163 | + issue-number: ${{ env.PR_NUM }} |
| 164 | + comment-author: 'github-actions[bot]' |
| 165 | + body-includes: to Cloudflare Workers (Preview) for *${{ matrix.app_name }}* |
| 166 | + |
| 167 | + - name: Create or update comment |
| 168 | + uses: peter-evans/create-or-update-comment@v5 |
| 169 | + with: |
| 170 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 171 | + issue-number: ${{ env.PR_NUM }} |
| 172 | + edit-mode: replace |
| 173 | + body: | |
| 174 | + ## ❌ Deploy to Cloudflare Workers (Preview) for *${{ matrix.app_name }}* failed. |
| 175 | +
|
| 176 | + | Name | Link | |
| 177 | + |:-----------------------|:---------------------------------------------------------------------------------------------| |
| 178 | + | 🔍 Latest deploy log | https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | |
0 commit comments