|
| 1 | +# NOTE: This name appears in GitHub's Checks API and in workflow's status badge. |
| 2 | +name: cloudflare-deploy |
| 3 | + |
| 4 | +# Trigger the workflow when: |
| 5 | +on: |
| 6 | + # A push occurs to one of the matched branches. |
| 7 | + push: |
| 8 | + branches: [master] |
| 9 | + # Or when a pull request event occurs for a pull request against one of the |
| 10 | + # matched branches. |
| 11 | + pull_request: |
| 12 | + branches: [master] |
| 13 | + |
| 14 | +jobs: |
| 15 | + cloudflare-pages: |
| 16 | + # This name appears in GitHub's Checks API. |
| 17 | + name: cloudflare-deploy |
| 18 | + # Do not trigger job for dependency update bot. |
| 19 | + if: github.actor != 'renovate[bot]' |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + pull-requests: write |
| 24 | + steps: |
| 25 | + # In progress comment will be updated with a deploy status. |
| 26 | + - name: Add in progress comment to PR |
| 27 | + # We want to add in progress comment on a pull request event only. |
| 28 | + if: github.event_name == 'pull_request' |
| 29 | + uses: mshick/add-pr-comment@v2 |
| 30 | + with: |
| 31 | + message: | |
| 32 | + ## Deploying with <a href="https://pages.dev">Cloudflare Pages</a> |
| 33 | + <table> |
| 34 | + <tr> |
| 35 | + <td><strong>Latest commit:</strong></td> |
| 36 | + <td><code>${{ github.event.pull_request.head.sha }}</code></td> |
| 37 | + </tr> |
| 38 | + <tr> |
| 39 | + <td><strong>Status:</strong></td><td>⏳ In progress</td> |
| 40 | + </tr> |
| 41 | + </table> |
| 42 | + - name: Checkout code |
| 43 | + uses: actions/checkout@v4 |
| 44 | + # Checkout pull request HEAD commit instead of merge commit. |
| 45 | + with: |
| 46 | + ref: ${{ github.event.pull_request.head.sha }} |
| 47 | + - name: Set up Node.js 20 |
| 48 | + uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: '20.x' |
| 51 | + cache: yarn |
| 52 | + - name: Install dependencies |
| 53 | + run: yarn install --frozen-lockfile |
| 54 | + - name: Build project |
| 55 | + run: yarn build |
| 56 | + - name: Build Storybook |
| 57 | + run: yarn build-storybook |
| 58 | + - name: Publish to Cloudflare Pages |
| 59 | + # Id is needed to access output in a next step. |
| 60 | + id: deploy |
| 61 | + uses: cloudflare/wrangler-action@v3 |
| 62 | + with: |
| 63 | + # Token with Cloudflare Pages edit permission only generated in Cloudflare dashboard -> Manage Account -> Account API Tokens |
| 64 | + apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }} |
| 65 | + # Acquired from Cloudflare dashboard -> Compute > Workers & Pages or dashboard url: https://dash.cloudflare.com/<account-id>/ |
| 66 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 67 | + # Project created via Cloudflare dashboard or CLI command "npx wrangler pages project create <project-name>" |
| 68 | + command: pages deploy ./storybook-static --project-name=oasis-ui --branch ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || '' }} |
| 69 | + # On a subsequent run the original comment will be updated. |
| 70 | + - name: Update PR comment |
| 71 | + uses: mshick/add-pr-comment@v2 |
| 72 | + # We want to update a comment on a pull request event only. |
| 73 | + if: github.event_name == 'pull_request' && always() |
| 74 | + with: |
| 75 | + message: | |
| 76 | + ## Deployed to <a href="https://pages.dev">Cloudflare Pages</a> |
| 77 | + <table> |
| 78 | + <tr> |
| 79 | + <td><strong>Latest commit:</strong></td> |
| 80 | + <td><code>${{ github.event.pull_request.head.sha }}</code></td> |
| 81 | + </tr> |
| 82 | + <tr> |
| 83 | + <td><strong>Status:</strong></td><td>✅ Deploy successful!</td> |
| 84 | + </tr> |
| 85 | + <tr> |
| 86 | + <td><strong>Preview URL:</strong></td> |
| 87 | + <td><a href="${{ steps.deploy.outputs.deployment-url }}">${{ steps.deploy.outputs.deployment-url }}</a></td> |
| 88 | + </tr> |
| 89 | + <tr> |
| 90 | + <td><strong>Alias:</strong></td> |
| 91 | + <td><a href="${{ steps.deploy.outputs.pages-deployment-alias-url }}">${{ steps.deploy.outputs.pages-deployment-alias-url }}</a></td> |
| 92 | + </tr> |
| 93 | + </table> |
| 94 | + message-failure: | |
| 95 | + ## Deployed to <a href="https://pages.dev">Cloudflare Pages</a> |
| 96 | + <table> |
| 97 | + <tr> |
| 98 | + <td><strong>Latest commit:</strong></td> |
| 99 | + <td><code>${{ github.event.pull_request.head.sha }}</code></td> |
| 100 | + </tr> |
| 101 | + <tr> |
| 102 | + <td><strong>Status:</strong></td><td>🚫 Deploy failed!</td> |
| 103 | + </tr> |
| 104 | + </table> |
| 105 | + message-cancelled: | |
| 106 | + ## Deployed to <a href="https://pages.dev">Cloudflare Pages</a> |
| 107 | + <table> |
| 108 | + <tr> |
| 109 | + <td><strong>Status:</strong></td><td>✖️ Deploy cancelled!</td> |
| 110 | + </tr> |
| 111 | + </table> |
0 commit comments