-
Notifications
You must be signed in to change notification settings - Fork 3.1k
109 lines (93 loc) · 3.98 KB
/
finalize-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
name: Finalize release
on:
workflow_dispatch:
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Discover pending release
id: discover
env:
GH_TOKEN: "${{ github.token }}"
run: |
gh --repo="${{ github.repository }}" \
pr list --base master --state open --json number,headRefName \
--jq 'map(select(.headRefName | startswith("release-")))' \
> /tmp/release-prs.json
if jq -e 'length < 1' /tmp/release-prs.json > /dev/null; then
echo "No open release pull requests found."
exit 1
elif jq -e 'length > 1' /tmp/release-prs.json > /dev/null; then
echo "Multiple open release pull requests found:"
jq -r '.[] | "https://github.com/${{ github.repository }}/pull/\(.number)"' /tmp/release-prs.json
exit 1
fi
jq -r '.[] | "prNumber=\(.number)", "version=\(.headRefName | ltrimstr("release-"))"' \
/tmp/release-prs.json >> "$GITHUB_OUTPUT"
# When you use the default github.token to make changes in the repository,
# it does not trigger further GitHub pipelines. We want to trigger CI for
# the pull request and artifact building for the release, so we have to use
# an app token.
- name: Generate authentication token
id: gen-token
uses: actions/create-github-app-token@v1
with:
app-id: "${{ secrets.CVAT_BOT_APP_ID }}"
private-key: "${{ secrets.CVAT_BOT_PRIVATE_KEY }}"
- name: Install dependencies
run:
sudo apt-get install -y pandoc
- uses: actions/checkout@v4
with:
ref: "release-${{ steps.discover.outputs.version }}"
- name: Verify that the release is new
env:
NEW_VERSION: "${{ steps.discover.outputs.version }}"
run: |
if git ls-remote --exit-code origin "refs/tags/v$NEW_VERSION" > /dev/null; then
echo "Release v$NEW_VERSION already exists"
exit 1
fi
# Do post-release tasks before publishing the release. If anything goes wrong,
# the dev-release-* branch can be deleted, and the whole process restarted again;
# whereas we can't unmerge the release PR.
- name: Create post-release branch
run:
git checkout -b "dev-release-${{ steps.discover.outputs.version }}"
- name: Bump version
run:
./dev/update_version.py --minor
- name: Commit post-release changes
run: |
git -c user.name='cvat-bot[bot]' -c user.email='147643061+cvat-bot[bot]@users.noreply.github.com' \
commit -a -m "Update ${{ github.ref_name }} after v${{ steps.discover.outputs.version }}"
- name: Push post-release branch
run:
git push -u origin "dev-release-${{ steps.discover.outputs.version }}"
- name: Create post-release pull request
env:
GH_TOKEN: "${{ steps.gen-token.outputs.token }}"
run: |
gh pr create \
--base="${{ github.ref_name }}" \
--title="Update ${{ github.ref_name }} after v${{ steps.discover.outputs.version }}" \
--body=""
# Now publish the release.
- name: Merge release pull request
env:
GH_TOKEN: "${{ steps.gen-token.outputs.token }}"
run:
gh pr merge --merge "${{ steps.discover.outputs.prNumber }}" --delete-branch
- name: Create release
env:
GH_TOKEN: "${{ steps.gen-token.outputs.token }}"
NEW_VERSION: "${{ steps.discover.outputs.version }}"
run: |
# We could grab the release notes from the PR description, but it could
# be outdated if any changes were made on the release branch. So instead,
# just re-extract them from the changelog again.
./dev/gh_release_notes.sh \
| gh release create "v$NEW_VERSION" \
--target=master \
--title="v$NEW_VERSION" \
--notes-file=-