-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (161 loc) · 5.22 KB
/
ci-and-cd.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: CI and CD
on:
push:
branches:
- main
pull_request:
branches:
- main
merge_group:
jobs:
lint:
name: Run ESLint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup Node.js with Volta
uses: ./.github/actions/setup-node
with:
NODE_AUTH_TOKEN: ${{ secrets.AUTH_TOKEN_FOR_GITHUBPKG }}
- name: Run ESLint
run: yarn lint
format:
name: Run Prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup Node.js with Volta
uses: ./.github/actions/setup-node
with:
NODE_AUTH_TOKEN: ${{ secrets.AUTH_TOKEN_FOR_GITHUBPKG }}
- name: Run Prettier
run: yarn format
test:
name: Run Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup Node.js with Volta
uses: ./.github/actions/setup-node
with:
NODE_AUTH_TOKEN: ${{ secrets.AUTH_TOKEN_FOR_GITHUBPKG }}
- name: Run coverage tests
run: yarn test:coverage
- name: Edit result file
run: tail -n +2 coverage/result-jest.txt | head -n -1 > result.txt
- name: Write coverages to summary
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require("fs").promises;
const jest = await fs.readFile("./result.txt").then((b) => b.toString());
const output = `\n${jest}`;
await core.summary
.addHeading('Jest Coverages')
.addRaw(output)
.write();
build:
name: Run Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Setup Node.js with Volta
uses: ./.github/actions/setup-node
with:
NODE_AUTH_TOKEN: ${{ secrets.AUTH_TOKEN_FOR_GITHUBPKG }}
- name: Restore Next.js build cache
uses: actions/cache@v3
with:
path: |
.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
- name: Make envfile
run: |
cat > .env <<EOD
NODE_ENV=${{ vars.NODE_ENV }}
NEXT_PUBLIC_BACKEND_API_URL=${{ secrets.NEXT_PUBLIC_BACKEND_API_URL }}
NEXT_PUBLIC_MS_APP_CLIENT_ID=${{ secrets.NEXT_PUBLIC_MS_APP_CLIENT_ID }}
NEXT_PUBLIC_MS_APP_REDIRECT_URL=${{ vars.NEXT_PUBLIC_MS_APP_REDIRECT_URL }}
EOD
- name: Run build
run: yarn build
- uses: actions/upload-artifact@v3
with:
name: output
path: out
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
deployments: write
needs:
- lint
- format
- test
- build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: output
path: out
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
id: cf
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }}
accountId: 9e9e88e2b19878c4a911c3c8a715a168
projectName: seichi-portal
directory: out
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Output short git SHA
id: sha
if: always() && github.event_name == 'pull_request'
run: |
SHORT_SHA=$(git log --format='%h' -n 1)
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_OUTPUT
- name: Output deployment status
id: content
if: always() && github.event_name == 'pull_request'
run: |
outputStatus() { echo "CONTENT=$1" >> $GITHUB_OUTPUT; }
if [ $STATUS = 'success' ]; then
outputStatus "✅ Deployment succeeded."
else
outputStatus "🚫 Deployment failed."
fi
env:
STATUS: ${{ steps.cf.outcome }}
- name: Notify deployment status and its URL
uses: actions-cool/maintain-one-comment@v3
if: always() && github.event_name == 'pull_request'
with:
body: |
## Deploying with <a href="https://pages.dev"><img alt="Cloudflare Pages" src="https://user-images.githubusercontent.com/23264/106598434-9e719e00-654f-11eb-9e59-6167043cfa01.png" width="16"></a> Cloudflare Pages
<table>
<tr>
<td><strong>Latest commit:</strong> </td>
<td><code>${{ steps.sha.outputs.SHORT_SHA }}</code></td>
</tr>
<tr>
<td><strong>Status:</strong></td>
<td>${{ steps.content.outputs.CONTENT }}</td>
</tr>
<tr>
<td><strong>Deployment URL:</strong></td>
<td><a href="${{ steps.cf.outputs.url }}">${{ steps.cf.outputs.url }}</a></td>
</tr>
</table>
body-include: '<!-- Created by actions-cool/maintain-one-comment -->'