-
Notifications
You must be signed in to change notification settings - Fork 18
222 lines (213 loc) · 8.13 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: Tag and Release
on:
workflow_dispatch:
inputs:
tag:
description: "current tag: The tag for this release"
required: true
default: v0.1.0-rc.2
prev_tag:
description: "previous tag: Tag from which to start calculating the changelog"
required: true
default: v0.1.0-beta.0
commit_ref:
description: "commit ref: The branch, tag or SHA of the commit to use for the release."
required: false
default: main
jobs:
build_and_test:
name: Build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.commit_ref }}
- id: info
uses: konveyor/get-env-info@v1
- uses: actions/setup-go@v2
with:
go-version: ${{ steps.info.outputs.go_version }}
- run: make ci
- run: make test-coverage
- name: upload coverage
uses: codecov/codecov-action@v1
- if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: "#BD3232"
SLACK_ICON: https://github.com/actions.png?size=48
SLACK_MESSAGE: "Build and test failed for move2kube-api on tag ${{ github.event.inputs.tag }}"
SLACK_TITLE: Failed
SLACK_USERNAME: GitHubActions
tag:
needs: [build_and_test]
name: Tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.commit_ref }}
- id: get_sha
run: |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- uses: actions/github-script@v3
with:
github-token: ${{ secrets.MOVE2KUBE_PATOKEN }}
script: |
const tag = '${{ github.event.inputs.tag }}';
const sha = '${{ steps.get_sha.outputs.sha }}';
let tag_exists = false;
try {
const resp = await github.git.getRef({...context.repo, ref: `tags/${tag}`});
tag_exists = true;
core.info(`the tag ${tag} already exists on ${resp.data.object.type} ${resp.data.object.sha}`);
} catch(err) {
if(err.status !== 404){
throw err;
}
}
if(tag_exists) {
core.info(`deleting the tag ${tag}`);
const resp = await github.git.deleteRef({...context.repo, ref: `tags/${tag}`});
}
core.info(`creating the tag ${tag} on the commit ${sha}`);
// create the tag
github.git.createRef({
...context.repo,
ref: `refs/tags/${tag}`,
sha
});
if(!tag.endsWith('-beta.0')) {
return;
}
// create the release branch
const major_minor = /^v(\d+\.\d+)/.exec(tag);
if(!major_minor || major_minor.length !== 2){
return core.setFailed(`The tag is not a valid semantic version. tag: ${tag}`);
}
const branch_name = `release-${major_minor[1]}`;
github.git.createRef({
...context.repo,
ref: `refs/heads/${branch_name}`,
sha
});
create_release_draft:
needs: [tag]
name: Create release draft
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.commit_ref }}
fetch-depth: 0
- name: create release draft
uses: konveyor/create-release-draft@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.tag }}
prev_tag: ${{ github.event.inputs.prev_tag }}
config: releasenotes-config.js
- id: info
uses: konveyor/get-env-info@v1
- uses: actions/setup-go@v2
with:
go-version: ${{ steps.info.outputs.go_version }}
- run: VERSION='${{ github.event.inputs.tag }}' make dist
- name: upload release assets
uses: konveyor/upload-release-action@v3
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.tag }}
file: _dist/output/*
file_glob: true
overwrite: true
- name: slack notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_ICON: https://github.com/actions.png?size=48
SLACK_MESSAGE: "Release draft for move2kube-api ${{ github.event.inputs.tag }} created: https://github.com/konveyor/move2kube-api/releases"
SLACK_TITLE: Success
SLACK_USERNAME: GitHubActions
image_build:
needs: [tag]
name: Image build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.commit_ref }}
- id: info
uses: konveyor/get-env-info@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: pull latest image to reuse layers
run: |
docker pull quay.io/konveyor/move2kube-api:latest || true
docker pull quay.io/konveyor/move2kube-api-builder:latest || true
- run: echo "${{ secrets.QUAY_BOT_PASSWORD }}" | docker login --username "${{ secrets.QUAY_BOT_USERNAME }}" --password-stdin quay.io
- name: build container image
run: VERSION='${{ github.event.inputs.tag }}' GO_VERSION='${{ steps.info.outputs.go_version }}' make cmultibuildpush
- name: success slack notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_ICON: https://github.com/actions.png?size=48
SLACK_MESSAGE: "Built and pushed quay.io/konveyor/move2kube-api:${{ github.event.inputs.tag }}"
SLACK_TITLE: Success
SLACK_USERNAME: GitHubActions
- if: failure()
name: failure slack notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: "#BD3232"
SLACK_ICON: https://github.com/actions.png?size=48
SLACK_MESSAGE: "Failed to build and push image quay.io/konveyor/move2kube-api:${{ github.event.inputs.tag }}"
SLACK_TITLE: Failed
SLACK_USERNAME: GitHubActions
trigger_other_repos:
needs: [image_build]
name: Trigger release in other repos
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
github-token: ${{ secrets.MOVE2KUBE_PATOKEN }}
script: |
const create_release_workflow = 'release.yml';
const repos = [
"move2kube-ui",
];
const promises = repos.map(repo => github.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo,
workflow_id: create_release_workflow,
ref: context.ref,
inputs: context.payload.inputs,
}));
await Promise.all(promises);
update_draft_title:
needs: [create_release_draft, trigger_other_repos]
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
github-token: ${{ secrets.MOVE2KUBE_PATOKEN }}
script: |
const tag = '${{ github.event.inputs.tag }}';
const response = await github.repos.listReleases({ ...context.repo });
const drafts = response.data.filter(release => release.draft && release.tag_name === tag);
if(drafts.length !== 1) {
return core.setFailed(`Expected to find exactly one draft release with the tag ${tag}. Found: ${drafts.length}`);
}
const draft = drafts[0];
if(!draft.name.startsWith('[WIP] ')) {
return core.setFailed(`Expected the draft name to begin with [WIP]. Found: ${draft.name}`);
}
const new_name = draft.name.replace(/^\[WIP\] /, '');
await github.repos.updateRelease({...context.repo, release_id: draft.id, name: new_name, tag_name: draft.tag_name});