-
Notifications
You must be signed in to change notification settings - Fork 10
85 lines (77 loc) · 3.33 KB
/
pr-deploy.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
name: Website PR deployment - Sync
on:
pull_request:
types:
- opened
- synchronize
jobs:
build:
timeout-minutes: 20
env:
APP_NAME: 'webuild website'
DEPLOY_PREVIEW_URL: ''
BRANCH_NAME: ''
BOT_NAME: 'github-actions[bot]'
BOT_TYPE: Bot
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get yarn cache
id: yarn-cache
run: 'echo "::set-output name=dir::$(yarn cache dir)"'
- uses: actions/cache@v1
with:
path: '${{ steps.yarn-cache.outputs.dir }}'
key: "${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}"
restore-keys: |
${{ runner.os }}-yarn-
- name: Get BRANCH_NAME
run: |
echo "BRANCH_NAME=$(echo $GITHUB_HEAD_REF | tr / -)" >> $GITHUB_ENV
- name: Install dependencies
run: |
yarn
- name: Netlify deployment
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_APP_ID }}
NETLIFY_AUTH_TOKEN: '${{ secrets.NETLIFY_AUTH_TOKEN }}'
run: >
yarn build
echo "DEPLOY_PREVIEW_URL=$(npx netlify-cli deploy --dir=public --message='Pull Request
$GITHUB_HEAD_REF'| grep "Website Draft URL" | grep -o -E 'https?://[^
]+' )" >> $GITHUB_ENV
- uses: actions/github-script@0.3.0
with:
github-token: '${{secrets.GITHUB_TOKEN}}'
script: >
const comments = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
const commitLink =
`https://github.com/webuild-community/webuild.community/commit/${context.sha}`
const regex = new RegExp('<!--\\s\\[${{ env.APP_NAME
}}-'+context.payload.pull_request.number+'\\]\\s-->\\n')
const commentsOfGithubBot = comments.data.filter(c => c.user.login
=== '${{ env.BOT_NAME }}' && c.user.type === '${{ env.BOT_TYPE }}'
&& regex.test(c.body))
if(commentsOfGithubBot.length === 0) {
const newComment = await github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '<!-- [${{ env.APP_NAME }}-' + `${context.payload.pull_request.number}` + '] -->\n' + 'Deploy preview for _${{ env.APP_NAME }}_ ready!<br/><br/>Built with commit ' + `${context.sha}<br/><br/>` + '${{ env.DEPLOY_PREVIEW_URL }}'
})
return JSON.stringify({commitLink, pullRequestLink: newComment.data.html_url})
} else {
const latestCommentId = commentsOfGithubBot.pop().id
const updatedComment = await github.issues.updateComment({
comment_id: latestCommentId,
owner: context.repo.owner,
repo: context.repo.repo,
body: '<!-- [${{ env.APP_NAME }}-' + `${context.payload.pull_request.number}` + '] -->\n' + 'Deploy preview for _${{ env.APP_NAME }}_ ready!<br/><br/>Built with commit ' + `${context.sha}<br/><br/>` + '${{ env.DEPLOY_PREVIEW_URL }}'
})
return JSON.stringify({commitLink, pullRequestLink: updatedComment.data.html_url})
}
id: githubComment