-
Notifications
You must be signed in to change notification settings - Fork 687
79 lines (72 loc) · 3.22 KB
/
check-branch-version.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
name: Check branch version
# This is a separate workflow from the main build-and-test workflow
# because we want it to run when a PR's target branch changes, and
# it'd be prohibitively time-consuming to re-run the main workflow
# every time that happens.
"on":
push:
branches:
- master
- release/v*
pull_request:
branches:
- master
- release/v*
types:
- opened # default
- reopened # default
- edited # default
- synchronize # also run if the target branch changes
jobs:
check-branch-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Deps
uses: ./.github/actions/setup-deps
- name: Detect version numbers
id: get-versions
run: |
# Set tag_majorminor
tag_majorminor=$(git describe --tags --match='v*'|sed 's/^v//'|cut -d. -f1,2)
echo "tag_majorminor=${tag_majorminor}" >> $GITHUB_OUTPUT
# Set branch_majorminor
case "$GITHUB_REF" in
refs/heads/*) branch=${GITHUB_REF#refs/heads/};;
refs/pull/*) branch=${GITHUB_BASE_REF#refs/heads/};;
esac
if [[ $branch == master ]]; then
prev_branch_majorminor=$(git for-each-ref --format='%(refname:lstrip=4)' 'refs/remotes/origin/release/v*' | sort --version-sort | tail -n1 | sed 's/^v//')
if [[ "${prev_branch_majorminor%.*}" == "${tag_majorminor%.*}" ]]; then
branch_majorminor="${prev_branch_majorminor%.*}.$((${prev_branch_majorminor##*.}+1))"
else
branch_majorminor="$((${prev_branch_majorminor%.*}+1)).0"
fi
else
branch_majorminor=${branch#release/v}
fi
echo "branch_majorminor=${branch_majorminor}" >> $GITHUB_OUTPUT
# Set relnotes_majorminor
make tools/bin/yq
relnotes_version=$(tools/bin/yq read docs/releaseNotes.yml items[0].version)
relnotes_majorminor=$(cut -d. -f1,2 <<<"$relnotes_version")
echo "relnotes_majorminor=${relnotes_majorminor}" >> $GITHUB_OUTPUT
declare -p tag_majorminor branch_majorminor relnotes_majorminor
- name: Check version numbers
run: |
tag_majorminor=${{ steps.get-versions.outputs.tag_majorminor }}
branch_majorminor=${{ steps.get-versions.outputs.branch_majorminor }}
relnotes_majorminor=${{ steps.get-versions.outputs.relnotes_majorminor }}
declare -p tag_majorminor branch_majorminor relnotes_majorminor
# Check that those all agree
if [[ "$tag_majorminor" != "$branch_majorminor" ]]; then
echo "You seem to be on the Git branch for v${branch_majorminor}.z, but Git tags indicate that this is work for v${tag_majorminor}.z"
echo "Perhaps you need to go yell at the person who set up the release branch for the last .y bump."
exit 1
fi
if [[ "$relnotes_majorminor" != "$tag_majorminor" ]]; then
echo "Your Git tag+branch indicate that you are targeting v${tag_majorminor}.z but your docs/releaseNotes.yml indicate that you are targeting v${relnotes_majorminor}.z"
exit 1
fi