Skip to content

Commit 663c7d8

Browse files
committed
Add script to increment version automatically and hook it into the release
1 parent e64aa61 commit 663c7d8

File tree

4 files changed

+116
-8
lines changed

4 files changed

+116
-8
lines changed

.github/workflows/release.yml

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,37 @@ name: Release
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
artifact_version:
7-
description: 'Target version for artifacts to build and publish'
8-
required: true
95

106
jobs:
117
gradle:
128
runs-on: ubuntu-latest
139
permissions:
1410
checks: write
15-
contents: read
11+
contents: write
1612
packages: write
1713
pages: write
1814
steps:
15+
- name: Setup Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.13'
1919
- name: Checkout sources
2020
uses: actions/[email protected]
2121
- name: Run Gradle Test
2222
uses: ./actions/gradle-test
2323
with:
24-
artifacts_version: "${{ inputs.artifact_version }}"
2524
gradle_args: "-PreleaseBuild=true"
25+
26+
# Always push a version bump back to main. There are failure scenarios that can result
27+
# in published artifacts but an erroneous build, and it's safer to have version gaps
28+
- name: Configure Git
29+
if: always()
30+
run: |
31+
git config --global user.name 'FoundationDB CI'
32+
git config --global user.email '[email protected]'
33+
- name: Increment Version
34+
if: always()
35+
run: python build/increment_version.py gradle.properties --commit
36+
- name: Push Changes
37+
if: always()
38+
run: git push

actions/gradle-test/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ runs:
4646
run: sed -i -e "s/^org\.gradle\..*/#&/g" gradle.properties
4747
- name: Run build and test
4848
shell: bash
49-
run: ARTIFACT_VERSION="${{ inputs.artifact_version }}" GRADLE_OPTS="-XX:+HeapDumpOnOutOfMemoryError -Xverify:none -XX:+TieredCompilation -Xmx4096m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED" ./gradlew --no-daemon --console=plain -b ./build.gradle build destructiveTest -PcoreNotStrict ${{ inputs.gradle_args }}
49+
run: GRADLE_OPTS="-XX:+HeapDumpOnOutOfMemoryError -Xverify:none -XX:+TieredCompilation -Xmx4096m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED" ./gradlew --no-daemon --console=plain -b ./build.gradle build destructiveTest -PcoreNotStrict ${{ inputs.gradle_args }}
5050
- name: Copy Test Reports
5151
shell: bash
5252
if: always()

build/increment_version.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/python3
2+
#
3+
# increment_version.py
4+
#
5+
# This source file is part of the FoundationDB open source project
6+
#
7+
# Copyright 2015-2025 Apple Inc. and the FoundationDB project authors
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
#
21+
22+
import argparse
23+
import re
24+
import subprocess
25+
import sys
26+
27+
28+
VERSION_POSITIONS = ['MAJOR', 'MINOR', 'BUILD', 'PATCH']
29+
VERSION_LINE = re.compile(r'version\s*\=\s*(\d+)\.(\d+)\.(\d+)\.(\d+)')
30+
31+
32+
def incremented_version(version: (int, int, int, int), update_type: str) -> tuple[int, int, int, int]:
33+
update_pos = VERSION_POSITIONS.index(update_type)
34+
new_version = []
35+
for i in range(len(version)):
36+
if i < update_pos:
37+
new_version.append(version[i])
38+
elif i == update_pos:
39+
new_version.append(version[i] + 1)
40+
else:
41+
new_version.append(0)
42+
return tuple(new_version)
43+
44+
45+
def version_string(version: tuple[int, int, int, int]) -> str:
46+
return '.'.join(map(str, version))
47+
48+
49+
def update_version(filename: str, update_type: str) -> tuple[int, int, int, int]:
50+
lines = []
51+
found = False
52+
version = None
53+
new_version = None
54+
with open(filename, 'r') as fin:
55+
for l in fin:
56+
m = VERSION_LINE.match(l)
57+
if m:
58+
if version is not None:
59+
raise ValueError('File contains multiple version lines')
60+
version = (int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4)))
61+
new_version = incremented_version(version, update_type)
62+
lines.append(f'version={version_string(new_version)}\n')
63+
found = True
64+
else:
65+
lines.append(l)
66+
67+
if not found:
68+
raise ValueError(f'Unable to find version in {filename}')
69+
70+
with open(filename, 'w') as fout:
71+
for l in lines:
72+
fout.write(l)
73+
print(f'Update version file {filename}')
74+
return new_version
75+
76+
77+
def main(argv: list[str]):
78+
parser = argparse.ArgumentParser(prog='increment_version',
79+
description='Utility to increment the project version stored in a version file')
80+
parser.add_argument('filename', type=str, help='File containing version to increment')
81+
parser.add_argument('-u', '--update-type', type=str, default='BUILD', choices=VERSION_POSITIONS,
82+
help='Type of update. Determines which position within the build number is updated')
83+
parser.add_argument('-c', '--commit', action='store_true', default=False, help='Whether to commit the update or not')
84+
85+
args = parser.parse_args(argv)
86+
new_version = update_version(args.filename, args.update_type)
87+
88+
if args.commit:
89+
subprocess.check_output(['git', 'add', args.filename])
90+
subprocess.check_output(['git', 'commit', '-m', f'Updating version to {version_string(new_version)}'])
91+
print('Version update committed')
92+
93+
94+
if __name__ == '__main__':
95+
main(sys.argv[1:])

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020

2121
rootProject.name=fdb-record-layer
22-
version=4.0
22+
version=4.0.570.0
2323
releaseBuild=false
2424

2525
# this should be false for release branches (i.e. if there is no -SNAPSHOT on the above version)

0 commit comments

Comments
 (0)