-
Notifications
You must be signed in to change notification settings - Fork 69
116 lines (100 loc) · 3.39 KB
/
pull-request.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
name: Pull Request Preview
on:
pull_request_target:
jobs:
prepare:
runs-on: ubuntu-latest
permissions: {} # disable all permission
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: |
yarn install --frozen-lockfile
- name: Ignore OpenAPI
run: |
./scripts/ignore-openapi
- name: Build
env:
NODE_OPTIONS: "--max_old_space_size=7168"
run: |
yarn gen-api-docs
yarn build
- name: Upload build to artifacts
uses: actions/upload-artifact@v4
with:
name: build
path: ./build
deploy:
runs-on: ubuntu-latest
permissions:
pull-requests: write
needs: prepare
steps:
- name: Set up Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: |
npm install netlify-cli -g yarn
- name: Download build from artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ./build
- name: Deploy to Netlify
run: >
netlify deploy
--site ${{ secrets.NETLIFY_SITE_ID }}
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }}
--message "Deploy from GitHub Action (pull-request: ${{ github.event.number }}, ${{ github.event.pull_request.head.sha }})"
--dir ./build
--json > deploy_output.json
- name: Get Netlify Deploy URL
id: netlify
run: |
DEPLOY_URL=$(jq -r '.deploy_url' deploy_output.json)
echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
- name: Add or Update PR comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const sha = `${{ github.event.pull_request.head.sha }}`
const pr_number = `${{ github.event.number }}`;
const deployUrl = `${{ steps.netlify.outputs.deploy_url }}`;
const commentIdentifier = "<!-- deploy-comment -->";
const body = `${commentIdentifier}\n
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | ${sha} |
|<span aria-hidden="true">😎</span> Deploy Preview | ${deployUrl} |
`
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_number,
});
const existingComment = comments.find(comment => comment.body.includes(commentIdentifier));
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_number,
body: body,
});
}