-
Notifications
You must be signed in to change notification settings - Fork 2
257 lines (228 loc) · 8.58 KB
/
release.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
name: Build and Release
on:
push:
branches:
- "release/v*.*.*"
tags-ignore:
- "v*.*.*-*"
workflow_dispatch:
inputs:
memos-tag:
description: |
Upstream tag to build.
The action will fail if a matching tag already exists on this repository.
required: false
type: string
memos-release:
description: |
Upstream release to build.
The action will fail if a matching tag already exists on this repository.
required: false
type: string
env:
DOCKER_PLATFORMS: |
linux/386
linux/amd64
linux/amd64/v2
linux/amd64/v3
linux/arm/v5
linux/arm/v6
linux/arm/v7
linux/arm64
linux/ppc64le
linux/riscv64
linux/s390x
QEMU_PLATFORMS: |
linux/386
linux/amd64
linux/arm/v6
linux/arm/v7
linux/arm64
linux/ppc64le
linux/riscv64
linux/s390x
# Variables set by scripts/ci.py
GORELEASER_CURRENT_TAG: "[not set]"
BUILD_VERSION: "[not set]"
CACHE_KEY: "[not set]"
jobs:
front-end:
name: Build front-end
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
# setup deps
- name: Setup Task
uses: jaxxstorm/action-install-gh-release@71d17cb091aa850acb2a1a4cf87258d183eb941b
with:
repo: go-task/task
cache: enable
tag: "v3.34.1"
- name: Setup pnpm
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d
with:
version: 8
- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version: 20
cache: pnpm
cache-dependency-path: "memos/web/pnpm-lock.yaml"
# /setup deps
# When running the workflow manually, allows to build a specific tag or release.
# If the build is triggered by other events, will build whatever is already commited to the subtree.
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-release == '' && github.event.inputs.memos-tag != '' }}
name: Pull usememos/memos:tags/${{ inputs.memos-tag }} to subtree
run: python scripts/ci.py pull-subtree --branch=tags/${{ inputs.memos-tag }}
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-tag == '' && github.event.inputs.memos-release != '' }}
name: Pull usememos/memos:releases/${{ inputs.memos-release }} to subtree
run: python scripts/ci.py pull-subtree --branch=heads/release/${{ inputs.memos-release }}
# Run after subtree pull, in case version.go changed.
- name: Setup environment variables
run: python scripts/ci.py setup-env
- name: Cache front-end build
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319
with:
path: |
build/frontend
.task/checksum/build-frontend
key: |
frontend-${{env.BUILD_VERSION}}-${{ env.CACHE_KEY }}
restore-keys: |
frontend-${{env.BUILD_VERSION}}-
- name: Build front-end
run: task build:frontend
- name: Upload front-end artifact
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
with:
name: frontend_${{env.BUILD_VERSION}}
compression-level: 9
if-no-files-found: error
path: |
build/frontend/
.task/checksum/build-frontend
goreleaser:
name: Build back-end and Release
runs-on: ubuntu-22.04
permissions:
actions: read # required by wait action
contents: write
discussions: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
# setup deps
- name: Setup Task
uses: jaxxstorm/action-install-gh-release@71d17cb091aa850acb2a1a4cf87258d183eb941b
with:
repo: go-task/task
cache: enable
tag: "v3.34.1"
- name: Setup buf
uses: bufbuild/buf-setup-action@88db93f5d74ffa329bb43e42aa95cd822697d214
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: 1.29.0
- name: Setup UPX
uses: crazy-max/ghaction-upx@0fc45e912669ba9e8fa2b430e97c8da2a632e29b
with:
install-only: true
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: ">=1.22"
check-latest: true
cache-dependency-path: memos/go.sum
# /setup deps
# When running the workflow manually, allows to build a specific tag or release.
# If the build is triggered by other events, will build whatever is already commited to the subtree.
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-release == '' && github.event.inputs.memos-tag != '' }}
name: Pull usememos/memos:tags/${{ inputs.memos-tag }} to subtree
run: |
python scripts/ci.py pull-subtree --branch=tags/${{ inputs.memos-tag }}
python scripts/ci.py retag --tag=v${{ inputs.memos-tag }} --push
- if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.memos-tag == '' && github.event.inputs.memos-release != '' }}
name: Pull usememos/memos:releases/${{ inputs.memos-release }} to subtree
run: |
python scripts/ci.py pull-subtree --branch=heads/release/${{ inputs.memos-release }}
python scripts/ci.py retag --tag=${{ inputs.memos-release }} --push
# Run after subtree pull, in case version.go changed.
- name: Setup environment variables
run: python scripts/ci.py setup-env
### Front-end ###
- name: Wait for the front-end build to finish
uses: yogeshlonkar/wait-for-jobs@e63eb7009ce730db926a5c4eeb9ba2bb5b2acb59
with:
jobs: "Build front-end"
interval: "2000"
ttl: "10"
- name: Download front-end artifact
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427
with:
name: frontend_${{env.BUILD_VERSION}}
### /Front-end ###
- name: go.mod tidy
run: task build:backend-tidy
- name: Generate protobuf-related code
run: task build:buf
- name: Build and release with Goreleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8
with:
distribution: goreleaser
version: v1.24
args: release --clean --timeout 60m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
### Docker ###
- name: Rename goreleaser builds to the format expected by current Dockerfile
run: python scripts/ci.py rename-to-docker
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3
with:
platforms: ${{ env.QEMU_PLATFORMS }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c
with:
version: latest
install: true
platforms: ${{ env.DOCKER_PLATFORMS }}
- name: Log-in to Docker Hub
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
username: lincolnthalles
password: ${{ secrets.DOCKER_TOKEN }}
- name: Log-in to GitHub's Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |
lincolnthalles/memos
ghcr.io/lincolnthalles/memos-builds
tags: |
type=raw,value=latest
type=semver,pattern={{version}},value=${{ env.BUILD_VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.BUILD_VERSION }}
- name: Build and Push Docker images
id: docker_build
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: ./
file: ./docker/Dockerfile
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
### /Docker ###