From 1359c793f9bef8a30515e2063061ebe49763cc2d Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Sun, 23 Feb 2025 08:42:29 +0700 Subject: [PATCH] ci: add version-based release check - Add should-release job to check if version should be released - Update release and publish jobs to depend on should-release check - Change release condition to check version and main branch --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45df374..c9cdaa6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -318,12 +318,35 @@ jobs: with: name: criterion-${{ matrix.benchmark_group.group }}-results path: benchmark_results.md + should-release: + name: Should Release + runs-on: ubuntu-latest + outputs: + yes: ${{ steps.check.outputs.yes }} + steps: + - uses: actions/checkout@v4 + - run: | + # get current cargo version from Cargo.toml using cargo CLI tool + # then use `cargo info` to see if it's already released + cargo_version=$(cargo pkgid | cut -d# -f2) + if cargo info "yek@$cargo_version"; then + echo "yek@$cargo_version is already released" + echo "yes=false" >> $GITHUB_OUTPUT + else + if git tag -l "v$cargo_version" | grep -q "v$cargo_version"; then + echo "yes=true" >> $GITHUB_OUTPUT + else + echo "Error: Git tag v$cargo_version is not pushed" + echo "yes=false" >> $GITHUB_OUTPUT + fi + fi + id: check release: name: Release needs: [test, lint, build] runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/v') && endsWith(github.event.base_ref, 'main') + if: ${{ needs.should-release.outputs.yes }} == 'true' && github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 @@ -351,7 +374,7 @@ jobs: name: Publish to crates.io needs: [test, lint, build] runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/v') && endsWith(github.event.base_ref, 'main') + if: ${{ needs.should-release.outputs.yes }} == 'true' && github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable