-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (126 loc) · 4.26 KB
/
ci.yaml
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
name: CI
on:
push:
branches:
- main
pull_request:
jobs:
lint:
name: Lint with ESLint and Prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get node version from Volta
id: get-node-version
uses: keita-hino/get-node-version-from-volta@main
- uses: actions/setup-node@v3
with:
node-version: ${{ steps.get-node-version.outputs.nodeVersion }}
cache: yarn
- name: Install dependencies
run: yarn install
- name: Run Prettier
run: yarn fmt
- name: Run ESLint
run: yarn lint
build:
name: Run Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get node version from Volta
id: get-node-version
uses: keita-hino/get-node-version-from-volta@main
- uses: actions/setup-node@v3
with:
node-version: ${{ steps.get-node-version.outputs.nodeVersion }}
cache: yarn
- name: Install dependencies
run: yarn install
- 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
- name: Delete cache
run: rm -rf .next/cache
- uses: actions/upload-artifact@v3
with:
name: output
path: .next
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
deployments: write
needs:
- lint
- build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: output
path: .next
- 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: .next
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 -->'