-
Notifications
You must be signed in to change notification settings - Fork 1
194 lines (187 loc) · 6.44 KB
/
publish.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
name: Build and publish Docker image
on:
push:
branches: [main, beta]
release:
types:
- published
jobs:
npm_build_frontend:
name: Build frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Cache node modules
uses: actions/cache@v3
id: cache
env:
cache-name: cache-node-modules-frontend-v2
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
- name: Cache npm cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
env:
cache-name: cache-npm-cache-frontend-v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Install frontend dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --prefer-offline --no-audit
- name: Build frontend
run: npm run build
npm_build_backend:
name: Build backend
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Cache node modules
uses: actions/cache@v3
id: cache
env:
cache-name: cache-node-modules-backend-v2
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('backend/package-lock.json') }}
- name: Cache npm cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
env:
cache-name: cache-npm-cache-backend-v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('backend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Install backend dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --prefer-offline --no-audit
- name: Link backend dependencies in `/common`
run: ln -s ../backend/node_modules ../common/node_modules
- name: Build backend
run: npm run build
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs:
- npm_build_frontend
- npm_build_backend
steps:
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: jojomatik/blockcluster
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
cache-from: type=gha,scope=blockcluster
cache-to: type=gha,scope=blockcluster,mode=max
build-args: |
git_sha=${{github.sha}}
git_ref=${{github.ref}}
semantic-release:
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' }}
name: Create a semantic release
runs-on: ubuntu-latest
needs:
- npm_build_frontend
- npm_build_backend
- push_to_registry
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN }}
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Cache node modules
uses: actions/cache@v3
id: cache
env:
cache-name: cache-node-modules-frontend-v2
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
- name: Cache npm cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
env:
cache-name: cache-npm-cache-frontend-v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Install frontend dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --prefer-offline --no-audit
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
GIT_AUTHOR_NAME: ${{ secrets.BUMP_GIT_NAME }}
GIT_AUTHOR_EMAIL: ${{ secrets.BUMP_GIT_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.BUMP_GIT_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.BUMP_GIT_EMAIL }}
run: npm run semantic-release
sync_main_to_beta:
if: ${{ github.ref == 'refs/heads/main' }}
name: Sync branch `main` to `beta` (fast-forward enabled)
runs-on: ubuntu-latest
needs:
- semantic-release
steps:
- name: Keep `beta` up to date with `main` (fast-forward enabled)
uses: jojomatik/sync-branch@v2
with:
git_committer_name: ${{ secrets.BUMP_GIT_NAME }}
git_committer_email: ${{ secrets.BUMP_GIT_EMAIL }}
github_token: ${{ secrets.GH_TOKEN }}
sync_beta_to_updates:
if: ${{ github.ref == 'refs/heads/beta' }}
name: Sync branch `beta` to `updates` (fast-forward enabled)
runs-on: ubuntu-latest
needs:
- semantic-release
steps:
- name: Keep `updates` up to date with `beta` (fast-forward enabled)
uses: jojomatik/sync-branch@v2
with:
target: "updates"
git_committer_name: ${{ secrets.BUMP_GIT_NAME }}
git_committer_email: ${{ secrets.BUMP_GIT_EMAIL }}
github_token: ${{ secrets.GH_TOKEN }}