|
1 | | -name: Netlify deploy-preview success |
| 1 | +name: Netlify deploy-preview |
2 | 2 | on: |
3 | 3 | workflow_dispatch: |
4 | 4 | inputs: |
5 | 5 | issue: |
6 | 6 | description: Issue number |
| 7 | + required: true |
| 8 | + type: number |
| 9 | + status: |
| 10 | + description: Deployment status |
| 11 | + required: true |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - in_progress |
| 15 | + - failure |
| 16 | + - success |
7 | 17 | log: |
8 | 18 | description: Netlify log URL |
| 19 | + required: true |
| 20 | + type: string |
9 | 21 |
|
10 | 22 | jobs: |
11 | 23 | notify: |
12 | 24 | name: Notify about deployment |
13 | 25 | runs-on: ubuntu-latest |
14 | | - environment: |
15 | | - name: staging-${{ github.event.inputs.issue }} |
16 | | - url: ${{ steps.get-url.outputs.url }} |
17 | | - |
18 | 26 | steps: |
19 | | - - name: Get deployment URL |
20 | | - id: get-url |
| 27 | + - name: Create deployment |
| 28 | + id: deployment |
| 29 | + env: |
| 30 | + GH_REPO: ${{ github.repository }} |
| 31 | + GH_TOKEN: ${{ secrets.GH_TOKEN_MANAGE_ENVS }} |
21 | 32 | run: | |
22 | | - echo "url=https://staging-${{ github.event.inputs.issue }}.cmbuckley.co.uk" >> $GITHUB_OUTPUT |
| 33 | + ref=$(gh pr view ${{ github.event.inputs.issue }} --json headRefOid -q .headRefOid) |
| 34 | + env=staging-${{ github.event.inputs.issue }} |
| 35 | + url=https://$env.cmbuckley.co.uk |
| 36 | + echo "url=$url" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + # create environment, deployment and success status |
| 39 | + gh api -X PUT repos/{owner}/{repo}/environments/$env |
| 40 | + deployment=$(gh api repos/{owner}/{repo}/deployments \ |
| 41 | + -f ref=$ref \ |
| 42 | + -f environment=$env \ |
| 43 | + -F required_contexts[]=netlify/{owner}/deploy-preview -q .id) |
| 44 | + gh api -X POST repos/{owner}/{repo}/deployments/$deployment/statuses \ |
| 45 | + -f state=success \ |
| 46 | + -f environment_url=$url |
| 47 | +
|
| 48 | + - name: Get comment text |
| 49 | + id: get-text |
| 50 | + uses: actions/github-script@v7 |
| 51 | + with: |
| 52 | + script: | |
| 53 | + const status = github.events.inputs.status, |
| 54 | + data = { |
| 55 | + in_progress: ['👷', 'in progress', false], |
| 56 | + failure: ['❌', 'failed', false], |
| 57 | + success: ['✅', 'ready', true], |
| 58 | + }; |
| 59 | +
|
| 60 | + core.setOutput('emoji', data[status][0]); |
| 61 | + core.setOutput('title', data[status][1]); |
| 62 | + core.setOutput('preview', data[status][2]); |
23 | 63 |
|
24 | 64 | - name: Find Comment |
25 | | - uses: peter-evans/find-comment@v3 |
26 | 65 | id: find-comment |
| 66 | + uses: peter-evans/find-comment@v3 |
27 | 67 | with: |
28 | 68 | issue-number: ${{ github.event.inputs.issue }} |
29 | 69 | comment-author: 'github-actions[bot]' |
30 | | - body-includes: Deploy Preview ready |
| 70 | + body-includes: Deploy Preview |
31 | 71 |
|
32 | 72 | - name: Create comment |
33 | 73 | uses: peter-evans/create-or-update-comment@v4 |
|
36 | 76 | comment-id: ${{ steps.find-comment.outputs.comment-id }} |
37 | 77 | edit-mode: replace |
38 | 78 | body: | |
39 | | - ### <span aria-hidden="true">✅</span> Deploy Preview ready! |
| 79 | + ### <span aria-hidden="true">${{ steps.get-text.outputs.emoji }}</span> Deploy Preview ${{ steps.get-text.outputs.title }}! |
40 | 80 |
|
41 | | - | Name | Link | |
42 | | - |----------------|----------------------------------| |
43 | | - | Deploy Preview | ${{ steps.get-url.outputs.url }} | |
44 | | - | Deploy Log | ${{ github.event.inputs.log }} | |
| 81 | + | Name | Link | |
| 82 | + |----------------|------| |
| 83 | + ${{ steps.get-text.outputs.preview && format('| Deploy Preview | {0} |\n', steps.deployment.outputs.url) || ''}} |
| 84 | + | Deploy Log | ${{ github.event.inputs.log }} | |
0 commit comments