Skip to content

Commit

Permalink
ci: add a github action to ensure no package version regression
Browse files Browse the repository at this point in the history
  • Loading branch information
lmatz committed Jun 14, 2024
1 parent 8ebe2b7 commit 00b2170
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/package_version_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Check if package version is greater than the latest release version

on:
pull_request:
types: [opened, edited]
branches:
- 'main'

jobs:
list-and-pick-latest-release-branch:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: List branches
run: |
git fetch --all
release_branches=$(git branch -r | grep -E 'origin/release-[0-9]+\.[0-9]+' | sed 's/origin\///')
echo "Release branches:"
echo "$release_branches"
echo "$release_branches" > release_branches.txt
- name: Pick latest release branch
run: |
latest_branch=$(echo "$release_branches" | sort -t. -k1,1 -k2,2 -Vr | head -n 1)
echo "Latest release branch: $latest_branch"
latest_version=$(echo "$latest_branch" | sed -E 's/release-([0-9]+\.[0-9]+)/\1/' | sed 's/^[ \t]*//')
echo "Latest release version: $latest_version"
echo "$latest_version" > latest_release_version.txt
- name: Read Cargo.toml version
run: |
cargo_version=$(grep -oP '(?<=^version = ")[0-9]+\.[0-9]+' Cargo.toml)
echo "Cargo.toml version: $cargo_version"
echo "$cargo_version" > cargo_version.txt
- name: Compare versions
run: |
latest_version=$(cat latest_release_version.txt)
cargo_version=$(cat cargo_version.txt)
latest_major=$(echo $latest_version | cut -d. -f1)
latest_minor=$(echo $latest_version | cut -d. -f2)
cargo_major=$(echo $cargo_version | cut -d. -f1)
cargo_minor=$(echo $cargo_version | cut -d. -f2)
if [ "$cargo_major" -lt "$latest_major" ] || { [ "$cargo_major" -eq "$latest_major" ] && [ "$cargo_minor" -lt "$latest_minor" ]; }; then
echo "Error: Cargo.toml package version $cargo_version is not larger than $latest_version"
exit 1
else
echo "Cargo.toml version $cargo_version is larger than or equal to $latest_version"
fi

0 comments on commit 00b2170

Please sign in to comment.