99 - uses : actions/checkout@v3
1010
1111 - run : |
12- version=$(.github/scripts/get-version.sh)
13- version=${version//-SNAPSHOT/}
14- if ! grep --quiet "^## Version $version" CHANGELOG.md; then
15- echo the change log needs to be updated
12+ if [[ $GITHUB_REF_NAME != main ]]; then
13+ echo this workflow should only be run against main
14+ exit 1
15+ fi
16+
17+ if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
18+ echo the change log is missing an \"Unreleased\" section
1619 exit 1
1720 fi
1821
@@ -23,11 +26,15 @@ jobs:
2326 - uses : actions/checkout@v3
2427
2528 - name : Create release branch
26- id : create-release-branch
2729 run : |
2830 version=$(.github/scripts/get-version.sh)
2931 version=${version//-SNAPSHOT/}
30- release_branch_name=$(echo $version | sed -E 's/([0-9]+)\.([0-9]+)\.0/release\/v\1.\2.x/')
32+ if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
33+ release_branch_name=$(echo $version | sed -E 's/([0-9]+)\.([0-9]+)\.0/release\/v\1.\2.x/')
34+ else
35+ echo "unexpected version: $version"
36+ exit 1
37+ fi
3138
3239 git push origin HEAD:$release_branch_name
3340
@@ -37,12 +44,17 @@ jobs:
3744 - name : Update version
3845 run : .github/scripts/update-version.sh $VERSION
3946
47+ - name : Update the change log with the approximate release date
48+ run : |
49+ date=$(date "+%Y-%m-%d")
50+ sed -Ei "s/^## Unreleased$/## Version $VERSION ($date)/" CHANGELOG.md
51+
4052 - name : Set git user
4153 run : .github/scripts/set-git-user.sh
4254
4355 - name : Create pull request against the release branch
4456 env :
45- # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
57+ # not using secrets. GITHUB_TOKEN since pull requests from that token do not run workflows
4658 GITHUB_TOKEN : ${{ secrets.BOT_TOKEN }}
4759 run : |
4860 message="Prepare release $VERSION"
@@ -64,26 +76,33 @@ jobs:
6476 - name : Set environment variables
6577 run : |
6678 version=$(.github/scripts/get-version.sh)
67- if [[ $version =~ ([0-9]+)\.([0-9]+)\.0 ]]; then
79+ version=${version//-SNAPSHOT/}
80+ if [[ $version =~ ^([0-9]+)\.([0-9]+)\.0$ ]]; then
6881 major="${BASH_REMATCH[1]}"
6982 minor="${BASH_REMATCH[2]}"
83+ next_version="$major.$((minor + 1)).0"
7084 else
7185 echo "unexpected version: $version"
7286 exit 1
7387 fi
74- next_version="$major.$((minor + 1)).0"
75- next_version="${next_version}-SNAPSHOT"
76- echo "NEXT_VERSION=$next_version" >> $GITHUB_ENV
88+ echo "NEXT_VERSION=${next_version}-SNAPSHOT" >> $GITHUB_ENV
89+ echo "VERSION=$version" >> $GITHUB_ENV
7790
7891 - name : Update version
7992 run : .github/scripts/update-version.sh $NEXT_VERSION
8093
94+ - name : Update the change log on main
95+ run : |
96+ # the actual release date on main will be updated at the end of the release workflow
97+ date=$(date "+%Y-%m-%d")
98+ sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version $VERSION ($date)/" CHANGELOG.md
99+
81100 - name : Set git user
82101 run : .github/scripts/set-git-user.sh
83102
84103 - name : Create pull request against main
85104 env :
86- # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
105+ # not using secrets. GITHUB_TOKEN since pull requests from that token do not run workflows
87106 GITHUB_TOKEN : ${{ secrets.BOT_TOKEN }}
88107 run : |
89108 message="Update version to $NEXT_VERSION"
0 commit comments