Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump the version using the #flags from the PR description #85

Merged
merged 8 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,19 @@ jobs:
permissions:
contents: write
outputs:
new_tag: ${{ steps.bump_version.outputs.new_tag }}
new_version: ${{ steps.bump_version.outputs.new_version }}
steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Read version from file
run: |
# Read the version from the version file, only store the number (without the 'v')
INITIAL_VERSION=$(source version && echo ${VERSION#v})
echo "Current version: $INITIAL_VERSION"
echo "INITIAL_VERSION=${INITIAL_VERSION}" >> $GITHUB_ENV

- name: Bump version
- name: Compute new version
id: bump_version
uses: anothrNick/github-tag-action@v1
env:
DEFAULT_BUMP: minor
DRY_RUN: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INITIAL_VERSION: ${{ env.INITIAL_VERSION }}
WITH_V: true

PR_BODY: ${{ github.event.pull_request.body }}
run: |
source version
new_version=$(.github/workflows/compute_version.sh "$VERSION" "${PR_BODY//[^a-zA-Z0-9#]/}")
echo "new_version=$new_version" >> $GITHUB_OUTPUT

update-version-file:
needs: compute-version
Expand All @@ -49,18 +40,18 @@ jobs:

- name: Update version file with new version
run: |
echo "New version: ${{ needs.compute-version.outputs.new_tag }}"
echo "VERSION=${{ needs.compute-version.outputs.new_tag }}" > version
echo "New version: ${{ needs.compute-version.outputs.new_version }}"
echo "VERSION=${{ needs.compute-version.outputs.new_version }}" > version
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add version
git commit -m "chore: update version file to ${{ needs.compute-version.outputs.new_tag }}"
git commit -m "chore: update version file to ${{ needs.compute-version.outputs.new_version }}"
git push

- name: Push new tag
run: |
git tag ${{ needs.compute-version.outputs.new_tag }}
git push origin ${{ needs.compute-version.outputs.new_tag }}
git tag ${{ needs.compute-version.outputs.new_version }}
git push origin ${{ needs.compute-version.outputs.new_version }}


create-release:
Expand All @@ -73,7 +64,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.compute-version.outputs.new_tag }}
ref: ${{ needs.compute-version.outputs.new_version }}

- name: Build release packages
uses: docker/build-push-action@v6
Expand All @@ -93,7 +84,7 @@ jobs:
uses: ncipollo/release-action@v1
with:
artifacts: "/tmp/artifacts/release/*"
tag: ${{ needs.compute-version.outputs.new_tag }}
tag: ${{ needs.compute-version.outputs.new_version }}
body: ${{ github.event.pull_request.body }}

build-and-run-release-tests:
Expand All @@ -104,7 +95,7 @@ jobs:
uses: docker/build-push-action@v6
with:
build-args: |
RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/download/${{ needs.compute-version.outputs.new_tag }}
RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/download/${{ needs.compute-version.outputs.new_version }}
push: false
tags: release_tester_core
target: release_test_core
Expand All @@ -117,7 +108,7 @@ jobs:
uses: docker/build-push-action@v6
with:
build-args: |
RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/download/${{ needs.compute-version.outputs.new_tag }}
RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/download/${{ needs.compute-version.outputs.new_version }}
push: false
tags: release_tester_gui
target: release_test_gui
Expand Down Expand Up @@ -154,32 +145,32 @@ jobs:
push: true
tags: |
ghcr.io/kit-mrt/arbitration_graphs:latest
ghcr.io/kit-mrt/arbitration_graphs:${{ needs.compute-version.outputs.new_tag }}
ghcr.io/kit-mrt/arbitration_graphs:${{ needs.compute-version.outputs.new_version }}
target: install

- name: Build and push Pacman demo Docker image
uses: docker/build-push-action@v6
with:
build-args: |
VERSION=${{ needs.compute-version.outputs.new_tag }}
VERSION=${{ needs.compute-version.outputs.new_version }}
context: demo
file: demo/Dockerfile
push: true
tags: |
ghcr.io/kit-mrt/arbitration_graphs_pacman_demo:latest
ghcr.io/kit-mrt/arbitration_graphs_pacman_demo:${{ needs.compute-version.outputs.new_tag }}
ghcr.io/kit-mrt/arbitration_graphs_pacman_demo:${{ needs.compute-version.outputs.new_version }}
target: demo

- name: Build and push Pacman tutorial Docker image
uses: docker/build-push-action@v6
with:
build-args: |
VERSION=${{ needs.compute-version.outputs.new_tag }}
VERSION=${{ needs.compute-version.outputs.new_version }}
context: demo
file: demo/Dockerfile
push: true
tags: |
ghcr.io/kit-mrt/arbitration_graphs_pacman_tutorial:latest
ghcr.io/kit-mrt/arbitration_graphs_pacman_tutorial:${{ needs.compute-version.outputs.new_tag }}
ghcr.io/kit-mrt/arbitration_graphs_pacman_tutorial:${{ needs.compute-version.outputs.new_version }}
target: tutorial

39 changes: 39 additions & 0 deletions .github/workflows/compute_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <version> <input_string>"
exit 1
fi

initial_version=${1//[^0-9.]/}
input_string=${2//[^a-zA-Z0-9#]/}

initial_major=$(echo "$initial_version" | cut -d'.' -f1)
initial_minor=$(echo "$initial_version" | cut -d'.' -f2)
initial_patch=$(echo "$initial_version" | cut -d'.' -f3)

# Determine the bump type based on input string
if [[ "$input_string" == *"#major"* ]]; then
new_major=$((initial_major + 1))
new_minor=0
new_patch=0
elif [[ "$input_string" == *"#minor"* ]]; then
new_major=$initial_major
new_minor=$((initial_minor + 1))
new_patch=0
elif [[ "$input_string" == *"#patch"* ]]; then
new_major=$initial_major
new_minor=$initial_minor
new_patch=$((initial_patch + 1))
else
# Default to minor bump
new_major=$initial_major
new_minor=$((initial_minor + 1))
new_patch=0
fi

new_version="v${new_major}.${new_minor}.${new_patch}"
echo "${new_version}"