-
Notifications
You must be signed in to change notification settings - Fork 12
141 lines (123 loc) · 4.28 KB
/
preview.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
130
131
132
133
134
135
136
137
138
139
140
141
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Build Preview
on:
# pull_request_target:
# branches:
# - 'main'
issue_comment:
types: [created]
jobs:
watch-contain-target-issue:
if: ${{ github.event.comment.body == 'Deploy preview' && github.event.issue.pull_request != null }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Receive comment
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.PAT }}
comment-id: ${{ github.event.comment.id }}
reactions: rocket
build-dist:
needs: watch-contain-target-issue
runs-on: ubuntu-latest
steps:
- name: Store pull_request info
id: pull_request_info
run: |
echo pull_request.html_url:${{ github.event.issue.pull_request.html_url }}
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ github.event.issue.pull_request.url }} | jq -r '.head' > head.json
echo "repo=`cat head.json | jq -r '.repo.full_name'`" >> $GITHUB_OUTPUT
echo "ref=`cat head.json | jq -r '.ref'`" >> $GITHUB_OUTPUT
echo "sha=`cat head.json | jq -r '.sha'`" >> $GITHUB_OUTPUT
# - name: Test echo
# run: |
# echo repo:${{ steps.pull_request_info.outputs.repo }}
# echo ref :${{ steps.pull_request_info.outputs.ref }}
# echo sha :${{ steps.pull_request_info.outputs.sha }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.pull_request_info.outputs.sha }}
repository: ${{ steps.pull_request_info.outputs.repo }}
- name: Install pnpm
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --no-frozen-lockfile && node scripts/bootstrap.mjs
- name: Build site
env:
BASE_URL: app
run: |
pnpm build
tar -czvf dist.tar.gz dist vercel.json
- name: upload dist and vercel.json
uses: actions/upload-artifact@v2
with:
name: dist
path: dist.tar.gz
deploy-to-vercel-for-preview:
needs: build-dist
runs-on: ubuntu-latest
permissions:
contents: write
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- name: Download dist
uses: actions/download-artifact@v2
with:
name: dist
path: .
- name: Unzip dist
run: |
tar -xzvf dist.tar.gz
rm dist.tar.gz
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '18'
- name: Install Vercel CLI
run: npm add -g vercel
- name: Deploy to Vercel
env:
BASE: None
run: |
mv dist app
vercel --token=${{ secrets.VERCEL_TOKEN }} > deployment-url.txt
echo "PREVIEW_URL=$(cat deployment-url.txt)" >> $GITHUB_ENV
- name: Comment is successful
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.PAT }}
comment-id: ${{ github.event.comment.id }}
issue-number: ${{ github.event.issue.number }}
body: |
**Deploy preview**
- [Preview](${{ env.PREVIEW_URL }})
edit-mode: replace
reactions: hooray
- name: Comment is failed
if: ${{ failure() }}
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.PAT }}
comment-id: ${{ github.event.comment.id }}
issue-number: ${{ github.event.issue.number }}
body: |
**Deploy preview**
- Failed to deploy preview
- [Action detail page](https://github.com/Power-Playground/app/actions/runs/${{ github.run_id }})
edit-mode: replace
reactions: confused