From 658ebeced55553d8446c178a57be33a07322fb7b Mon Sep 17 00:00:00 2001 From: lexara-prime-ai Date: Sat, 1 Jun 2024 07:18:04 +0000 Subject: [PATCH] Updated workflows --- .github/workflows/cargo-publish.yml | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cargo-publish.yml b/.github/workflows/cargo-publish.yml index 0f40662..79e998c 100644 --- a/.github/workflows/cargo-publish.yml +++ b/.github/workflows/cargo-publish.yml @@ -1,21 +1,50 @@ name: Publish to crates.io + 'on': push: branches: [ "master" ] tags: '*' + jobs: publish: name: Publish runs-on: ubuntu-latest steps: - - name: Chekout sources + - name: Checkout sources uses: actions/checkout@v2 + - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - - run: 'cargo publish --token ${CRATES_IO_TOKEN}' + + - name: Extract current version + id: extract_version + run: | + current_version=$(grep '^version' Cargo.toml | sed -E 's/version = "(.*)"/\1/') + echo "current_version=${current_version}" >> $GITHUB_ENV + + - name: Get latest published version + id: get_latest_version + run: | + crate_name=$(grep '^name' Cargo.toml | sed -E 's/name = "(.*)"/\1/') + latest_version=$(curl -s https://crates.io/api/v1/crates/${crate_name} | jq -r .crate.max_version) + echo "latest_version=${latest_version}" >> $GITHUB_ENV + + - name: Compare versions + id: compare_versions + run: | + if [ "${{ env.current_version }}" == "${{ env.latest_version }}" ]; then + echo "Version is already published." + exit 1 + else + echo "New version detected." + fi + + - name: Publish to crates.io + if: steps.compare_versions.outcome == 'success' + run: 'cargo publish --token ${CRATES_IO_TOKEN}' env: - CRATES_IO_TOKEN: '${{secrets.CRATES_IO_TOKEN}}' + CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}