...
1name: Check branch version
2
3# This is a separate workflow from the main build-and-test workflow
4# because we want it to run when a PR's target branch changes, and
5# it'd be prohibitively time-consuming to re-run the main workflow
6# every time that happens.
7
8"on":
9 push:
10 branches:
11 - master
12 - release/v*
13 pull_request:
14 branches:
15 - master
16 - release/v*
17 types:
18 - opened # default
19 - reopened # default
20 - edited # default
21 - synchronize # also run if the target branch changes
22
23jobs:
24 check-branch-version:
25 runs-on: ubuntu-latest
26 steps:
27 - uses: actions/checkout@v3
28 with:
29 fetch-depth: 0
30 - name: Install Deps
31 uses: ./.github/actions/setup-deps
32 - name: Detect version numbers
33 id: get-versions
34 run: |
35 # Set tag_majorminor
36 tag_majorminor=$(git describe --tags --match='v*'|sed 's/^v//'|cut -d. -f1,2)
37 echo "tag_majorminor=${tag_majorminor}" >> $GITHUB_OUTPUT
38
39 # Set branch_majorminor
40 case "$GITHUB_REF" in
41 refs/heads/*) branch=${GITHUB_REF#refs/heads/};;
42 refs/pull/*) branch=${GITHUB_BASE_REF#refs/heads/};;
43 esac
44 if [[ $branch == master ]]; then
45 prev_branch_majorminor=$(git for-each-ref --format='%(refname:lstrip=4)' 'refs/remotes/origin/release/v*' | sort --version-sort | tail -n1 | sed 's/^v//')
46 if [[ "${prev_branch_majorminor%.*}" == "${tag_majorminor%.*}" ]]; then
47 branch_majorminor="${prev_branch_majorminor%.*}.$((${prev_branch_majorminor##*.}+1))"
48 else
49 branch_majorminor="$((${prev_branch_majorminor%.*}+1)).0"
50 fi
51 else
52 branch_majorminor=${branch#release/v}
53 fi
54 echo "branch_majorminor=${branch_majorminor}" >> $GITHUB_OUTPUT
55
56 # Set relnotes_majorminor
57 make tools/bin/yq
58 relnotes_version=$(tools/bin/yq read docs/releaseNotes.yml items[0].version)
59 relnotes_majorminor=$(cut -d. -f1,2 <<<"$relnotes_version")
60 echo "relnotes_majorminor=${relnotes_majorminor}" >> $GITHUB_OUTPUT
61
62 declare -p tag_majorminor branch_majorminor relnotes_majorminor
63 - name: Check version numbers
64 run: |
65 tag_majorminor=${{ steps.get-versions.outputs.tag_majorminor }}
66 branch_majorminor=${{ steps.get-versions.outputs.branch_majorminor }}
67 relnotes_majorminor=${{ steps.get-versions.outputs.relnotes_majorminor }}
68 declare -p tag_majorminor branch_majorminor relnotes_majorminor
69
70 # Check that those all agree
71 if [[ "$tag_majorminor" != "$branch_majorminor" ]]; then
72 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"
73 echo "Perhaps you need to go yell at the person who set up the release branch for the last .y bump."
74 exit 1
75 fi
76 if [[ "$relnotes_majorminor" != "$tag_majorminor" ]]; then
77 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"
78 exit 1
79 fi
View as plain text