-
Notifications
You must be signed in to change notification settings - Fork 55
296 lines (273 loc) · 9.79 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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: Main
on:
push:
branches: ["main"]
tags:
- "*-?v[0-9]+*"
pull_request:
branches: ["main"]
types: [opened, synchronize]
env:
GHCR_REGISTRY: ghcr.io
DOCKER_USERNAME: ignisda
permissions:
contents: write
packages: write
jobs:
pre-workflow-checks:
runs-on: ubuntu-latest
outputs:
should-run: ${{ steps.set_outputs.outputs.should-run }}
image-names: ${{ steps.set_outputs.outputs.image-names }}
should-release: ${{ steps.set_outputs.outputs.should-release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set outputs
id: set_outputs
uses: actions/github-script@v7
with:
script: |
const repositoryName = context.payload.repository.name;
const owner = context.repo.owner;
const ghcrRegistry = process.env.GHCR_REGISTRY;
const dockerUsername = process.env.DOCKER_USERNAME;
let imageNames = [
`name=${dockerUsername}/${repositoryName}`,
`name=${ghcrRegistry}/${owner}/${repositoryName}`,
`name=${dockerUsername}/${repositoryName}-pro`,
`name=${ghcrRegistry}/${owner}/${repositoryName}-pro`,
];
let shouldRun = 'false';
if (context.eventName === "push") {
shouldRun = 'true';
} else if (context.eventName === "pull_request") {
const commitMsg = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.payload.pull_request.head.sha
}).then(commit => commit.data.commit.message);
if (commitMsg.includes("Run CI")) {
shouldRun = 'true';
}
}
core.setOutput('should-run', shouldRun);
const shouldRelease = (context.eventName === "push" && context.ref.startsWith("refs/tags/")) ? 'true' : 'false';
core.setOutput('should-release', shouldRelease);
core.setOutput('image-names', imageNames.join('\n'));
create-release:
needs:
- pre-workflow-checks
if: needs.pre-workflow-checks.outputs.should-release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
uses: metcalfc/[email protected]
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body: |
## What's Changed
${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-transactional:
needs: pre-workflow-checks
if: needs.pre-workflow-checks.outputs.should-run == 'true'
runs-on: ubuntu-latest
env:
MOON_TOOLCHAIN_FORCE_GLOBALS: true
steps:
- uses: actions/checkout@v4
- uses: moonrepo/setup-toolchain@v0
with:
auto-install: true
- name: Set up Node.js and caching
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"
- name: Build emails
run: moon run transactional:build
- name: Upload templates artifact
uses: actions/upload-artifact@v4
with:
name: templates
path: |
crates/services/notification/templates/
retention-days: 1
build-backend:
needs:
- pre-workflow-checks
- build-transactional
if: needs.pre-workflow-checks.outputs.should-run == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-unknown-linux-gnu
command: cargo
- target: aarch64-unknown-linux-gnu
command: cross
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: templates
path: ${{ github.workspace }}/crates/services/notification/templates
- name: Extract build information
id: build
env:
TARGET: ${{ matrix.platform.target }}
run: |
echo "version=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
echo "docker-arch=${{ startsWith(matrix.platform.target, 'x86_64') && 'amd64' || 'arm64' }}" >> "$GITHUB_OUTPUT"
- name: Extract rust toolchain
id: toolchain
run: |
echo "channel=$(grep channel rust-toolchain.toml | awk -F' = ' '{printf $2}' | tr -d '\"')" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.toolchain.outputs.channel }}
targets: ${{ matrix.platform.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.platform.target }}-${{ steps.build.outputs.profile }}
save-if: ${{ github.event_name != 'pull_request' }}
- uses: actions/cache@v4
with:
path: target
key: cargo-build-${{ runner.os }}-${{ matrix.platform.target }}-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
restore-keys: |
cargo-build-${{ runner.os }}-${{ matrix.platform.target }}-
- name: Install cross
if: ${{ matrix.platform.command == 'cross' }}
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cross
git: https://github.com/cross-rs/cross
rev: 19be83481fd3e50ea103d800d72e0f8eddb1c90c
locked: false
- name: Build
env:
APP_VERSION: ${{ steps.build.outputs.version }}
DEFAULT_TMDB_ACCESS_TOKEN: ${{ secrets.DEFAULT_TMDB_ACCESS_TOKEN }}
DEFAULT_MAL_CLIENT_ID: ${{ secrets.DEFAULT_MAL_CLIENT_ID }}
TRAKT_CLIENT_ID: ${{ secrets.TRAKT_CLIENT_ID }}
UNKEY_API_ID: ${{ secrets.UNKEY_API_ID }}
run: |
${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --release
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: backend-${{ steps.build.outputs.docker-arch }}
path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/release/backend
retention-days: 1
build-docker:
needs:
- pre-workflow-checks
- build-backend
if: needs.pre-workflow-checks.outputs.should-run == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build artifact for docker
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifact/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the ghcr container registry
uses: docker/login-action@v3
continue-on-error: true
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to the docker hub container registry
uses: docker/login-action@v3
continue-on-error: true
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ needs.pre-workflow-checks.outputs.image-names }}
tags: |
type=ref,event=pr
type=raw,value=develop,enable={{is_default_branch}}
type=semver,pattern=v{{version}},enable=${{ needs.pre-workflow-checks.outputs.should-release == 'true' }}
type=semver,pattern=v{{major}}.{{minor}},enable=${{ needs.pre-workflow-checks.outputs.should-release == 'true' }}
type=semver,pattern=v{{major}},enable=${{ needs.pre-workflow-checks.outputs.should-release == 'true' }}
type=raw,value=latest,enable=${{ needs.pre-workflow-checks.outputs.should-release == 'true' }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
upload-kodi-plugin:
needs:
- pre-workflow-checks
- build-docker
if: needs.pre-workflow-checks.outputs.should-release == 'true'
runs-on: ubuntu-20.04
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MOON_TOOLCHAIN_FORCE_GLOBALS: true
steps:
- uses: actions/checkout@v4
- name: Setup Moon
uses: moonrepo/setup-toolchain@v0
with:
auto-install: true
- name: Set up Node.js and caching
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"
- name: Build plugin
run: moon run kodi:build
- name: Upload plugin to releases
run: gh release upload --clobber ${{ github.ref_name }} "tmp/script.ryot.zip"
deploy-docs:
needs:
- pre-workflow-checks
- build-docker
if: needs.pre-workflow-checks.outputs.should-release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: cd docs && poetry install
- name: Build docs
run: cd docs && poetry run mkdocs build
- name: Push to deployment branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/site
publish_branch: nf-docs
force_orphan: true