diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.yml index b22030950..6e67fc91c 100644 --- a/.github/workflows/desktop-release.yml +++ b/.github/workflows/desktop-release.yml @@ -21,41 +21,24 @@ jobs: get-version: runs-on: ubuntu-latest outputs: - version: ${{ steps.vars.outputs.version }} - steps: - - uses: actions/checkout@v4 - - - name: Get Latest Release - id: get_latest_release - uses: cardinalby/git-get-release-action@v1 - with: - latest: true - prerelease: true - # excludes: rc, alpha, beta # Optional. Exclude keywords like rc, alpha, beta releases. - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + version: ${{ steps.set_version.outputs.version }} - - name: Bump possible release candidate version - id: bump_version - uses: christian-draeger/increment-semantic-version@1.0.2 - with: - current-version: ${{ steps.get_latest_release.outputs.name }} - version-fragment: "rc" - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - - name: Check out the branch or tag - id: vars - run: | - # echo "version=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" - - if [[ $GITHUB_REF =~ ^refs/tags/ ]]; then - VERSION=${{ github.ref_name }} - elif [[ $GITHUB_REF =~ ^refs/heads/release/.* ]]; then - VERSION=${{ steps.bump_version.outputs.next-version }} - else - VERSION=0.0.1 - fi - echo "version=$VERSION" >> "$GITHUB_OUTPUT" + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set Version + id: set_version + run: | + if [[ $GITHUB_REF =~ ^refs/tags/ ]]; then + VERSION=${{ github.ref_name }} + elif [[ $GITHUB_REF =~ ^refs/heads/release/.* ]]; then + chmod +x ./scripts/generate-rc-version.sh + VERSION=$(echo ./scripts/generate-rc-version.sh ${{ github.ref }}) + else + VERSION=0.0.1 + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" build-binaries: name: Build ${{ matrix.config.os }} @ ${{ matrix.config.arch }} diff --git a/scripts/generate-rc-version.sh b/scripts/generate-rc-version.sh new file mode 100755 index 000000000..88ffed1bb --- /dev/null +++ b/scripts/generate-rc-version.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +BRANCH_NAME=$1 + +# Extract version number from the branch name +VERSION=$(echo $BRANCH_NAME | grep -oP 'release\/\K\d+\.\d+\.\d+') + +# Check if there are any releases matching the branch's version pattern +RELEASES=$(git tag --list "$VERSION-rc*" | sort -V) + +if [ -z "$RELEASES" ]; then + # If no releases are found, set the version to -rc0 + VERSION="$VERSION-rc0" +else + # If there are releases, find the latest release and increment the version + LATEST_RELEASE=$(echo "$RELEASES" | tail -n 1) + NEXT_RC_NUMBER=$(echo "$LATEST_RELEASE" | grep -oP '\d+$' | awk '{print $1 + 1}') + VERSION="$VERSION-rc$NEXT_RC_NUMBER" +fi + +echo $VERSION