-
-
Notifications
You must be signed in to change notification settings - Fork 31
81 lines (77 loc) · 2.62 KB
/
bump-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
80
81
name: Bump Version
on:
release:
types: [ released ]
workflow_dispatch:
inputs:
release_tag:
description: 'Use release notes of'
type: string
required: false
jobs:
bump-version:
name: Bump version and update changelog
runs-on: ubuntu-latest
steps:
# Setup environment
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
# Fail if the release was not triggered from the master branch
- name: Verify branch
if: github.event_name == 'release'
run: |
if \
git fetch --depth=1 origin refs/heads/master && \
[ "$(git show-ref -s refs/heads/master)" != "$(git show-ref -s HEAD)" ]
then
msg="The release does not point to the master branch. This means the"
msg="$msg branch has been updated after the release, or the release"
msg="$msg was created on a different branch. Please trigger this"
msg="$msg workflow manually on the correct branch."
echo "::error::$msg"
exit 1
fi
# Setup cache
- name: Setup cache for Gradle and dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: "gradle-\
${{runner.os}}-\
${{hashFiles('gradle/wrapper/gradle-wrapper.properties')}}-\
${{hashFiles('gradle.properties', '**/*.gradle.kts')}}"
# Update files
- name: Obtain release notes
uses: actions/github-script@v7
with:
script: |
await require('.github/scripts/get-release-notes.js')({
github, context, core,
outputFile: 'release_note.md',
releaseTagInput: 'release_tag',
allowFallbackToLatest: true,
});
- name: Update files with Gradle
run: ./gradlew --stacktrace metadata patchChangelog --release-note="$(<release_note.md)" bumpVersion
# Commit and push
- name: Commit files
run: |
version="$(cat build/metadata/version.txt)"
git -c user.name='github-actions[bot]' \
-c user.email='41898282+github-actions[bot]@users.noreply.github.com' \
commit -am "Bump version after releasing v$version"
- name: Push changes
env:
BASE_COMMIT: ${{ github.sha }}
TARGET_BRANCH: ${{ github.event_name == 'release' && 'refs/heads/master' || github.ref }}
run: |
git push origin \
--force-with-lease="$TARGET_BRANCH:$BASE_COMMIT" \
"HEAD:$TARGET_BRANCH"