-
Notifications
You must be signed in to change notification settings - Fork 55
194 lines (161 loc) · 6.23 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
name: Release
on:
push:
tags:
- "*-?v[0-9]+*"
env:
GHCR_REGISTRY: ghcr.io
permissions:
contents: write
packages: write
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create or update release
uses: actions/github-script@v7
env:
TAG_NAME: ${{ github.ref_name }}
with:
script: |
const tag = process.env.TAG_NAME || github.ref_name;
const repo = context.repo;
const majorVersion = tag.match(/v(\d+)\.\d+\.\d+/)[1];
const releaseName = `Version ${majorVersion}`;
const date = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
const dynamicBody = `<!-- DYNAMIC START -->\n*Created from tag*: \`${tag}\`\n*Created from git revision*: \`${context.sha}\`\n*Published on*: \`${date}\`\n<!-- DYNAMIC END -->`;
async function findOrCreateRelease() {
const { data: releases } = await github.rest.repos.listReleases(repo);
let existingRelease = releases.find(release => release.name === releaseName);
if (existingRelease) {
const existingBody = existingRelease.body;
const newBody = existingBody.replace(/<!-- DYNAMIC START -->[^]*<!-- DYNAMIC END -->/, dynamicBody);
await github.rest.repos.updateRelease({
...repo,
release_id: existingRelease.id,
tag_name: tag,
body: newBody,
draft: false,
});
console.log("Release updated to associate with new tag.");
} else {
const fullBody = `${dynamicBody}\n\n## Release Notes\n\n- Some bug fixes.`;
await github.rest.repos.createRelease({
...repo,
tag_name: tag,
name: releaseName,
body: fullBody,
draft: false,
prerelease: false
});
console.log("Release created successfully.");
}
}
findOrCreateRelease();
docker-release:
runs-on: ubuntu-latest
needs: create-release
steps:
- uses: actions/checkout@v4
- 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
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to the docker hub container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Get docker image names
id: required_args
uses: actions/github-script@v7
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
with:
script: |
const repoName = context.payload.repository.name;
const refName = context.ref.replace('refs/tags/', '');
core.setOutput('APP_VERSION', refName);
const dockerHubActor = process.env.DOCKER_USERNAME;
const ghcrRegistry = process.env.GHCR_REGISTRY;
const ghcrActor = context.actor;
function generateVersionArray(version) {
const parts = version.split(".");
const versionArray = [];
for (let i = 0; i < parts.length; i++)
versionArray.push(parts.slice(0, i + 1).join("."));
versionArray.push("latest");
return versionArray;
}
const versionTags = generateVersionArray(refName);
const ghcrImageName = `${ghcrRegistry}/${ghcrActor}/${repoName}`;
const ghcrTags = versionTags.map((tag) => `${ghcrImageName}:${tag}`);
const dockerHubImageName = `${dockerHubActor}/${repoName}`;
const dockerHubTags = versionTags.map((tag) => `${dockerHubImageName}:${tag}`);
const imageNames = [...ghcrTags, dockerHubTags].join(",").toLowerCase();
core.setOutput('image_names', imageNames);
- name: Build and push to ghcr
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.required_args.outputs.image_names }}
build-args: |
APP_VERSION=${{ steps.required_args.outputs.APP_VERSION }}
DEFAULT_TMDB_ACCESS_TOKEN=${{ secrets.DEFAULT_TMDB_ACCESS_TOKEN }}
DEFAULT_MAL_CLIENT_ID=${{ secrets.DEFAULT_MAL_CLIENT_ID }}
upload-kodi-plugin:
runs-on: ubuntu-20.04
needs: docker-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Setup Moon
uses: moonrepo/setup-toolchain@v0
with:
auto-install: true
- 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-demo-instance:
runs-on: ubuntu-latest
needs: docker-release
steps:
- uses: actions/checkout@v4
- name: Set up CLI
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy
run: flyctl deploy --remote-only --detach --config ci/fly.toml
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
deploy-docs:
runs-on: ubuntu-latest
needs: docker-release
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