From b8d9965c9d35527c5c3e80608afde1e185381315 Mon Sep 17 00:00:00 2001 From: Bernd Ahlers Date: Tue, 2 Apr 2024 09:00:59 +0200 Subject: [PATCH] Add workflow to bump versions in version.yml --- .github/workflows/bump-graylog.yml | 55 ++++++++++++++++++++++++++++++ release.py | 54 +++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 .github/workflows/bump-graylog.yml diff --git a/.github/workflows/bump-graylog.yml b/.github/workflows/bump-graylog.yml new file mode 100644 index 0000000..15637fc --- /dev/null +++ b/.github/workflows/bump-graylog.yml @@ -0,0 +1,55 @@ +name: "Bump Version" +run-name: "Bump Version - ${{ inputs.product }} ${{ inputs.version }} (branch: ${{ inputs.branch }})" + +on: + workflow_dispatch: + inputs: + branch: + description: "The branch to check out" + required: true + version: + description: "The new version and revision. (Example: \"6.0.0-beta.1-1\")" + required: true + product: + description: "The product to bump" + required: true + type: "choice" + default: "graylog" + options: + - "graylog" + - "forwarder" + +defaults: + run: + shell: "bash" + +jobs: + bump: + runs-on: "ubuntu-latest" + + steps: + - name: "Checkout ${{ inputs.branch }}" + uses: "actions/checkout@v4" + with: + ref: "${{ inputs.branch }}" + token: "${{ secrets.GITHUB_TOKEN }}" + + - name: "Install dependencies" + run: "pip3 install -r requirements.txt" + + - name: "Bump version to ${{ inputs.version }}" + run: "./release.py --bump ${{ inputs.product }} --version ${{ inputs.version }}" + + - name: "Generate README" + run: "./release.py --generate-readme" + + - name: "Commit and push" + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git add version.yml README.md + git commit -m "Bump to ${{ inputs.version }}" + git tag -m "Tag ${{ inputs.version }}" "${{ inputs.version }}" + git push origin "${{ inputs.branch }}" + git push --tags diff --git a/release.py b/release.py index 720bbcd..1eb5a25 100755 --- a/release.py +++ b/release.py @@ -14,6 +14,10 @@ help="Get Forwarder image version.", action='store_true') parser.add_argument('--generate-readme', help="Generate a new README.md with the latest tags", action='store_true') +parser.add_argument('--bump', dest='bump', + choices=['graylog', 'forwarder'], help="Bump the given version") +parser.add_argument('--version', dest='version', + help="The new version and revision") if len(sys.argv) == 1: parser.print_help(sys.stderr) @@ -21,6 +25,11 @@ args = parser.parse_args() +if args.bump and not args.version: + parser.error('Missing --version parameter') + +version_parsed = None + with open('version.yml', 'r') as version_file: version_parsed = yaml.safe_load(version_file) @@ -42,3 +51,48 @@ with open("README.md", "w") as readme_file: readme_file.write(j2_template.render(version_parsed)) + + if args.bump == 'graylog': + print(f'Bumping {args.bump} to {args.version}') + + # 6.0.0-alpha.1-1 => version="6.0.0", suffixes=["alpha.1", "1"] + # 6.0.0 => version="6.0.0", suffixes=[] + version, *suffixes = args.version.split('-', 2) + # 6.0.0 => major=6, minor=0, patch= 0 + major, minor, patch = version.split('.', 2) + + suffix = suffixes[0] if len(suffixes) > 0 else None + release = suffixes[1] if len(suffixes) > 1 else 1 + + version_parsed[args.bump]['major_version'] = major + version_parsed[args.bump]['minor_version'] = minor + version_parsed[args.bump]['patch_version'] = f'{patch}-{suffix}' if suffix else patch + version_parsed[args.bump]['release'] = int(release) + + print(version_parsed[args.bump]) + if args.bump == 'forwarder': + print(f'Bumping {args.bump} to {args.version}') + + # 6.0-alpha.1-1 => version="6.0", suffixes=["alpha.1", "1"] + # 6.0 => version="6.0", suffixes=[] + version, *suffixes = args.version.split('-', 2) + suffix = suffixes[0] if len(suffixes) > 0 else None + release = suffixes[1] if len(suffixes) > 1 else 1 + + version_parsed[args.bump]['version'] = f'{version}-{suffix}' if suffix else version + version_parsed[args.bump]['release'] = int(release) + + print(version_parsed[args.bump]) + + +if version_parsed and args.bump: + with open('version.yml', 'w') as f: + yaml.dump(version_parsed, f, sort_keys=False) + + with open('version.yml', 'r+') as f: + content = f.read() + f.seek(0, 0) + # Preserve some comments + f.write('# For pre-releases: patch_version=0-beta.1, patch_version=0-rc.1\n') + f.write('# For GA releases: patch_version=0\n') + f.write(content)