Skip to content

Commit

Permalink
Add workflow to bump versions in version.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
bernd committed Apr 2, 2024
1 parent f8960c6 commit b8d9965
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/bump-graylog.yml
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@
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)
sys.exit(1)

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)

Expand All @@ -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)

0 comments on commit b8d9965

Please sign in to comment.