Skip to content

Commit

Permalink
feat: add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
clFaster committed Dec 21, 2024
1 parent 5885877 commit 5c26483
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: "Release TapToQR"

on:
workflow_dispatch:
inputs:
release-type:
type: choice
description: Which type of release to create?
required: true
default: patch
options:
- patch
- minor
- major

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
# Get the Current Version and Bump it depending on the release-type input
update-version:
runs-on: ubuntu-latest
permissions: write-all
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
steps:
- name: Ensure branch is main
if: github.ref != 'refs/heads/main'
run: |
text="Publish a new version can only be done from the main branch."
echo "::error title=Wrong Branch::$text"
exit 1
- name: Read current version
run: |
echo "Current version: ${{ vars.VERSION }}"
- name: Bump version
id: bump_version
run: |
# Retrieve the increment type from the GitHub Actions input
increment="${{ inputs.release-type }}"
# Split the VERSION variable into its major, minor, and patch components
IFS='.' read -r -a parts <<< "${{ vars.VERSION }}"
# Check if the VERSION variable was split correctly
if [ "${#parts[@]}" -ne 3 ]; then
echo "Invalid version format"
exit 1
fi
major=${parts[0]}
minor=${parts[1]}
patch=${parts[2]}
# Increment the appropriate version component
if [ "$increment" = "major" ]; then
major=$((major + 1))
minor=0
patch=0
elif [ "$increment" = "minor" ]; then
minor=$((minor + 1))
patch=0
elif [ "$increment" = "patch" ]; then
patch=$((patch + 1))
else
echo "Invalid increment type"
exit 1
fi
# Construct the new version string
new_version="$major.$minor.$patch"
# Output the new version
echo "New version: $new_version"
# Set the output variable for GitHub Actions
echo "new_version=$new_version" >> $GITHUB_OUTPUT
- name: Update version var
id: write_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh variable set VERSION --body "${{ steps.bump_version.outputs.new_version }}"

0 comments on commit 5c26483

Please sign in to comment.