diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..98baf55 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }}"