Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
update version check
Browse files Browse the repository at this point in the history
  • Loading branch information
horacioh committed Mar 12, 2024
1 parent 704e4eb commit 8336507
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
51 changes: 17 additions & 34 deletions .github/workflows/desktop-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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 }}
Expand Down
21 changes: 21 additions & 0 deletions scripts/generate-rc-version.sh
Original file line number Diff line number Diff line change
@@ -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 <branch_version>-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

0 comments on commit 8336507

Please sign in to comment.