Release #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| description: Release a new version of spmgraph. The internal https://github.com/getyourguide/actions/tree/main/semver-release inspires it. | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| updateType: | |
| description: 'Semver release type' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| version: | |
| description: 'Optionally set the version manually' | |
| type: string | |
| required: false | |
| concurrency: | |
| group: '${{ github.workflow }}-${{ github.head_ref || github.run_id }}' | |
| cancel-in-progress: true | |
| jobs: | |
| release: | |
| name: Release a new version | |
| runs-on: [ubuntu-latest] | |
| permissions: | |
| id-token: write | |
| contents: write | |
| actions: write | |
| checks: write | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v5 | |
| timeout-minutes: 2 | |
| - name: Get the latest release tag | |
| if: ${{ !inputs.version }} | |
| run: | | |
| git fetch --prune --prune-tags | |
| latest_tag=$(git tag --sort=committerdate | tail -1) | |
| echo "latest_tag=$latest_tag" >> $GITHUB_ENV | |
| - name: Bump version | |
| if: ${{ !inputs.version }} | |
| run: | | |
| # Read the latest tag from the GITHUB_ENV and extract the values from it | |
| latest_tag=${{ env.latest_tag }} | |
| if [[ $latest_tag =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
| major="${BASH_REMATCH[1]}" | |
| minor="${BASH_REMATCH[2]}" | |
| patch="${BASH_REMATCH[3]}" | |
| else | |
| echo "Invalid version format. Expected 'X.X.X'." | |
| exit 1 | |
| fi | |
| # Bumps the version based on the input argument | |
| case ${{ github.event.inputs.updateType }} in | |
| major) | |
| major=$((major + 1)) | |
| minor=0 | |
| patch=0 | |
| ;; | |
| minor) | |
| minor=$((minor + 1)) | |
| patch=0 | |
| ;; | |
| patch) | |
| patch=$((patch + 1)) | |
| ;; | |
| *) | |
| echo "Usage: $0 [--major|--minor|--patch]" | |
| echo " --major: Bump the major version." | |
| echo " --minor: Bump the minor version." | |
| echo " --patch: Bump the patch version." | |
| exit 1 | |
| ;; | |
| esac | |
| # Defines the updated tag and adds it to the GITHUB_ENV | |
| new_tag="${major}.${minor}.${patch}" | |
| echo "new_tag=$new_tag" >> $GITHUB_ENV | |
| - name: Set the new tag based on the input | |
| if: ${{ inputs.version }} | |
| run: echo "new_tag=${{ inputs.version }}" >> $GITHUB_ENV | |
| - name: Create the release | |
| run: | | |
| gh release create "$new_tag" --generate-notes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |