generated from OceanGlidersCommunity/Oxygen_SOP
-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (126 loc) · 4.95 KB
/
preview-book.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: preview-site
on:
workflow_run:
workflows:
- deploy-site
types:
- requested
- completed
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- name: Set message value
run: |
echo "comment_message=This pull request is being automatically built with [GitHub Actions](https://github.com/features/actions) and [Netlify](https://www.netlify.com/). To see the status of your deployment, click below." >> $GITHUB_ENV
- name: Find Pull Request
uses: actions/github-script@v4
id: find-pull-request
with:
script: |
let pullRequestNumber = ''
let pullRequestHeadSHA = ''
core.info('Finding pull request...')
const pullRequests = await github.pulls.list({owner: context.repo.owner, repo: context.repo.repo})
for (let pullRequest of pullRequests.data) {
if(pullRequest.head.sha === context.payload.workflow_run.head_commit.id) {
pullRequestHeadSHA = pullRequest.head.sha
pullRequestNumber = pullRequest.number
break
}
}
core.setOutput('number', pullRequestNumber)
core.setOutput('sha', pullRequestHeadSHA)
if(pullRequestNumber === '') {
core.info(
`No pull request associated with git commit SHA: ${context.payload.workflow_run.head_commit.id}`
)
}
else{
core.info(`Found pull request ${pullRequestNumber}, with head sha: ${pullRequestHeadSHA}`)
}
- name: Find Comment
uses: peter-evans/find-comment@v1
if: steps.find-pull-request.outputs.number != ''
id: fc
with:
issue-number: '${{ steps.find-pull-request.outputs.number }}'
comment-author: 'github-actions[bot]'
body-includes: '${{ env.comment_message }}'
- name: Create comment
if: |
github.event.workflow_run.conclusion != 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
body: |
${{ env.comment_message }}
🚧 Deployment in progress for git commit SHA: ${{ steps.find-pull-request.outputs.sha }}
- name: Update comment
if: |
github.event.workflow_run.conclusion != 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
${{ env.comment_message }}
🚧 Deployment in progress for git commit SHA: ${{ steps.find-pull-request.outputs.sha }}
- name: Download Artifact site
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
uses: dawidd6/action-download-artifact@v2.14.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: deploy.yaml
run_id: ${{ github.event.workflow_run.id }}
name: site-zip
- name: Unzip site
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
run: |
rm -rf _build/html
unzip site.zip
rm -f site.zip
# Push the site's HTML to Netlify and get the preview URL
- name: Deploy to Netlify
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
id: netlify
uses: nwtgck/actions-netlify@v1.2
with:
publish-dir: _build/html
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-commit-comment: false
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 5
- name: Update site Preview comment
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
${{ env.comment_message }}
🔍 Git commit SHA: ${{ steps.find-pull-request.outputs.sha }}
✅ Deployment Preview URL: ${{ steps.netlify.outputs.deploy-url }}