Skip to content

Commit

Permalink
improve published version check
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Jul 24, 2024
1 parent 56434f0 commit 271d4ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
20 changes: 3 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,14 @@ jobs:
- uses: taiki-e/install-action@v2
with: { tool: just }
- uses: actions/checkout@v4
- name: Ensure this crate has not yet been published (on release)
if: github.event_name == 'release'
run: just check-if-published
- uses: Swatinem/rust-cache@v2
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
- run: just ci-test
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2
- name: Get local and published versions
id: get-versions
run: |
echo "local_version=$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')" >> $GITHUB_OUTPUT
CRATE_NAME=$(grep '^name =' Cargo.toml | head -1 | sed -E 's/name = "(.*)"/\1/')
PUBLISHED_VERSION=$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')
echo "published_version=${PUBLISHED_VERSION}" >> $GITHUB_OUTPUT
- name: Test that we haven't published current version yet
run: |
LOCAL_VERSION=${{ steps.get-versions.outputs.local_version }}
PUBLISHED_VERSION=${{ steps.get-versions.outputs.published_version }}
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
echo "The current crate version ($LOCAL_VERSION) has already been published."
exit 1
else
echo "The current crate version ($LOCAL_VERSION) has not been published yet."
fi

msrv:
name: Test MSRV
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,19 @@ cargo-install $COMMAND $INSTALL_CMD="" *ARGS="":
bench:
cargo bench
open target/criterion/report/index.html

# Verify that the current version of the crate is not the same as the one published on crates.io
check-if-published:
#!/usr/bin/env bash
LOCAL_VERSION="$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')"
echo "Detected crate version: $LOCAL_VERSION"
CRATE_NAME="$(grep '^name =' Cargo.toml | head -1 | sed -E 's/name = "(.*)"/\1/')"
echo "Detected crate name: $CRATE_NAME"
PUBLISHED_VERSION="$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')"
echo "Published crate version: $PUBLISHED_VERSION"
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
echo "ERROR: The current crate version has already been published."
exit 1
else
echo "The current crate version has not yet been published."
fi

0 comments on commit 271d4ff

Please sign in to comment.