-
Notifications
You must be signed in to change notification settings - Fork 1
222 lines (209 loc) · 7.26 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
name: Release
on:
workflow_dispatch:
inputs:
base:
type: string
description: |
The tag of the commit that will be released.
Make sure that you also select that tag as the workflow's run location.
required: false
default: "release-candidate"
is-edge:
type: boolean
description: |
Assign the `edge` tag to this release.
default: true
is-release-candidate:
type: boolean
description: |
Assign the `release-candidate` tag to this release.
default: true
concurrency:
group: "release"
permissions: write-all
env:
BASE: ${{ github.event.inputs.base || 'release-candidate' }}
IS_EDGE: ${{ github.event.inputs.is-edge == 'true' }}
IS_RC: ${{ github.event.inputs.is-release-candidate == 'true' }}
jobs:
determine_version:
name: "determine version"
runs-on: ubuntu-latest
outputs:
version: ${{ steps.find_version.outputs.result }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get tags of base commit
id: get_base_tags
run: |
git fetch --tags
BASE_COMMIT=$(git rev-list -n 1 release-candidate)
BASE_TAGS=$(printf "%s," $(git tag --contains $BASE_COMMIT))
BASE_TAGS=${BASE_TAGS%,}
echo "base_tags=$BASE_TAGS" >> "$GITHUB_OUTPUT"
- name: Find next version
id: find_version
uses: actions/github-script@v7
env:
BASE_TAGS: ${{ steps.get_base_tags.outputs.base_tags }}
with:
result-encoding: string
script: |
const { findMostRecentVersion, makeVersionTag } = require('./.github/scripts/find-version.js');
const tags = process.env.BASE_TAGS.split(',');
const version = findMostRecentVersion(tags);
version.preRelease = null;
return makeVersionTag(version);
build_and_push_api:
name: "build and push api"
needs:
- determine_version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create image
uses: ./.github/actions/create-image
with:
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-api
TAG: latest
OTHER_TAGS: |
type=raw,value=${{ env.IS_EDGE == 'true' && 'edge' || '' }}
type=raw,value=${{ env.IS_RC == 'true' && 'release-candidate' || '' }}
VERSION: ${{ needs.determine_version.outputs.version }}
DOCKERFILE: ./apps/server-asset-sg/docker/Dockerfile
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build_and_push_app:
name: "build and push app"
needs:
- determine_version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create image
uses: ./.github/actions/create-image
with:
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-app
TAG: latest
OTHER_TAGS: |
type=raw,value=${{ env.IS_EDGE == 'true' && 'edge' || '' }}
type=raw,value=${{ env.IS_RC == 'true' && 'release-candidate' || '' }}
VERSION: ${{ needs.determine_version.outputs.version }}
DOCKERFILE: ./apps/client-asset-sg/docker/Dockerfile
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build_and_push_sync:
name: "build and push sync"
needs:
- determine_version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create image
uses: ./.github/actions/create-image
with:
IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}-sync
TAG: latest
OTHER_TAGS: |
type=raw,value=${{ env.IS_EDGE == 'true' && 'edge' || '' }}
type=raw,value=${{ env.IS_RC == 'true' && 'release-candidate' || '' }}
VERSION: ${{ needs.determine_version.outputs.version }}
DOCKERFILE: ./apps/sync-asset-sg/docker/Dockerfile
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag_commit:
name: "tag commit"
needs:
- determine_version
- build_and_push_api
- build_and_push_app
- build_and_push_sync
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: tag latest
uses: ./.github/actions/tag-commit
with:
TAG_NAME: latest
SHA: ${{ github.sha }}
- name: Tag release-candidate
if: ${{ env.IS_RC == 'true' }}
uses: ./.github/actions/tag-commit
with:
TAG_NAME: release-candidate
SHA: ${{ github.sha }}
- name: Tag edge
if: ${{ env.IS_EDGE == 'true' }}
uses: ./.github/actions/tag-commit
with:
TAG_NAME: edge
SHA: ${{ github.sha }}
- name: Tag version
uses: ./.github/actions/tag-commit
with:
TAG_NAME: ${{ needs.determine_version.outputs.version }}
SHA: ${{ github.sha }}
create_release:
name: "create release"
needs:
- determine_version
- build_and_push_api
- build_and_push_app
- build_and_push_sync
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: "${{ needs.determine_version.outputs.version }}"
name: "swissgeol-assets v${{ needs.determine_version.outputs.version }}"
generate_release_notes: true
make_latest: true
cleanup:
name: "cleanup"
needs:
- determine_version
- create_release
- tag_commit
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup node
run: |
npm install @octokit/rest
- name: Get tags
id: get_tags
run: |
git fetch --tags
TAGS=$(printf "%s," $(git tag))
TAGS=${TAGS%,}
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
- name: Remove outdated versions
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_IMAGE_NAME: ${{ vars.BASE_IMAGE_NAME }}
CURRENT_VERSION: ${{ needs.determine_version.outputs.version }}
TAGS: ${{ steps.get_tags.outputs.tags }}
with:
script: |
const { findOutdatedVersions, makeVersionTag } = require('./.github/scripts/find-version.js');
const { removePackageVersions } = require('./.github/scripts/remove-packages.js');
const tags = process.env.TAGS.split(',');
const outdatedVersions = findOutdatedVersions(tags, process.env.CURRENT_VERSION).map(makeVersionTag);
for (const version of outdatedVersions) {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${version}`,
});
}
await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-api`, outdatedVersions);
await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-app`, outdatedVersions);
await removePackageVersions(`${process.env.BASE_IMAGE_NAME}-sync`, outdatedVersions);