This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (195 loc) · 6.78 KB
/
main.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Verify, Build, & Deploy
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
install:
name: Install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache Node Modules
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules/
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
# Any way to encapsulate all of this with cache-hit?
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: Install Packages
run: npm ci --ignore-scripts
lint:
name: Lint
runs-on: ubuntu-latest
needs: [install]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Cache Node Modules
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules/
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Linting
run: npm run lint
coverage:
name: Coverage
runs-on: ubuntu-latest
needs: [install]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Cache Node Modules
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules/
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Coverage
run: npm run test:coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
build:
name: Build
runs-on: ubuntu-latest
needs: [install]
steps:
- uses: actions/checkout@v2
- name: Cache Node Modules
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules/
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Cache NextJS
id: cache-nextjs
uses: actions/cache@v3
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Build
run: npm run build
semantic:
name: Semantic Release
runs-on: ubuntu-latest
needs: [lint, coverage, build]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
published: ${{ steps.semantic.outputs.new_release_published }}
major: ${{ steps.semantic.outputs.new_release_major_version }}
minor: ${{ steps.semantic.outputs.new_release_minor_version }}
patch: ${{ steps.semantic.outputs.new_release_patch_version }}
steps:
- uses: actions/checkout@v2
- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy-docker:
name: Deploy (Docker Hub)
runs-on: ubuntu-latest
needs: semantic
if: needs.semantic.outputs.published == 'true'
steps:
- uses: actions/checkout@v2
- name: Cache Node Modules
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules/
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Cache NextJS
id: cache-nextjs
uses: actions/cache@v3
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: rainbowcafe/silvy
tags: |
type=raw,value=${{ needs.semantic.outputs.major }}
type=raw,value=${{ needs.semantic.outputs.major }}.${{ needs.semantic.outputs.minor }}
type=raw,value=${{ needs.semantic.outputs.major }}.${{ needs.semantic.outputs.minor }}.${{ needs.semantic.outputs.patch }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Push README to Dockerhub
uses: christian-korneck/update-container-description-action@v1
env:
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASS: ${{ secrets.DOCKER_PASSWORD }}
with:
destination_container_repo: rainbowcafe/silvy
provider: dockerhub
readme_file: 'README.md'
deploy-netlify:
name: Deploy (Netlify)
runs-on: ubuntu-latest
needs: semantic
if: needs.semantic.outputs.published == 'true'
steps:
- uses: actions/checkout@v2
- name: Cache Node Modules
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules/
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Cache NextJS
id: cache-nextjs
uses: actions/cache@v3
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Deploy Database
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: npm run deploy:database
- name: Deploy to Netlify
run: curl -X POST ${{ secrets.DEPLOY_URL }}