chore: fix build_release wf #3
Workflow file for this run
This file contains 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: Version Checks | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
version_check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Extract Branch Name | |
run: | | |
echo "PR head ref: ${{ github.head_ref }}" | |
BRANCH_NAME="${{ github.head_ref }}" | |
echo "Branch Name: $BRANCH_NAME" | |
- name: Determine Expected Version | |
id: expected_version | |
run: | | |
if [[ "$BRANCH_NAME" == rc/* ]]; then | |
EXPECTED_VERSION="${BRANCH_NAME#rc/}" | |
echo "::set-output name=version::$EXPECTED_VERSION" | |
elif [[ "$BRANCH_NAME" == hotfix/* ]]; then | |
# Fetch tags and increment patch version | |
git fetch --tags | |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
if [ -z "$LATEST_TAG" ]; then | |
echo "No existing tags found. Cannot proceed with hotfix versioning." | |
exit 1 | |
fi | |
IFS='.' read -r -a VERSION_PARTS <<< "${LATEST_TAG#v}" | |
MAJOR="${VERSION_PARTS[0]}" | |
MINOR="${VERSION_PARTS[1]}" | |
PATCH="${VERSION_PARTS[2]}" | |
PATCH=$((PATCH + 1)) | |
EXPECTED_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
echo "::set-output name=version::$EXPECTED_VERSION" | |
else | |
echo "Not an rc/* or hotfix/* branch. Skipping version check." | |
exit 0 | |
fi | |
- name: Check Version Consistency | |
if: steps.expected_version.outputs.version | |
run: | | |
CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -n 1 | awk -F\" '{print $2}') | |
echo "Version in Cargo.toml: $CARGO_VERSION" | |
echo "Expected version: ${{ steps.expected_version.outputs.version }}" | |
if [ "$CARGO_VERSION" != "${{ steps.expected_version.outputs.version }}" ]; then | |
echo "Version mismatch! Cargo.toml version ($CARGO_VERSION) does not match expected version (${{ steps.expected_version.outputs.version }})." | |
exit 1 | |
else | |
echo "Version matches." | |
fi |