diff --git a/.github/workflows/soroban-contract-ci.yml b/.github/workflows/soroban-contract-ci.yml index 40085b13..72c3938d 100644 --- a/.github/workflows/soroban-contract-ci.yml +++ b/.github/workflows/soroban-contract-ci.yml @@ -10,6 +10,40 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check contract version bump + env: + HAS_SKIP_VERSION_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'skip-version-check') }} + run: | + if [ "$HAS_SKIP_VERSION_LABEL" = "true" ]; then + echo "Skipping contract version check because skip-version-check label is present." + exit 0 + fi + + git fetch origin main + + if ! git diff --name-only origin/main...HEAD | grep -qx 'contracts/src/lib.rs'; then + echo "contracts/src/lib.rs did not change; no contract version bump required." + exit 0 + fi + + BASE_VERSION=$(git show origin/main:contracts/Cargo.toml | sed -n 's/^version = "\(.*\)"/\1/p' | head -n 1) + HEAD_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' contracts/Cargo.toml | head -n 1) + + if [ -z "$BASE_VERSION" ] || [ -z "$HEAD_VERSION" ]; then + echo "Unable to read contracts/Cargo.toml package version." + exit 1 + fi + + if [ "$BASE_VERSION" = "$HEAD_VERSION" ]; then + echo "contracts/src/lib.rs changed, but contracts/Cargo.toml version stayed at $HEAD_VERSION." + echo "Bump contracts/Cargo.toml package.version so CONTRACT_VERSION changes, or apply the skip-version-check label for trivial doc-only changes." + exit 1 + fi + + echo "Contract version changed from $BASE_VERSION to $HEAD_VERSION." - name: Cache rustup toolchains uses: actions/cache@v4 diff --git a/contracts/README.md b/contracts/README.md index d258ec73..46db8c22 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -1,5 +1,17 @@ # Stellar Bounty Board Contract +## Versioning + +The contract exposes `CONTRACT_VERSION` from the `version` field in +`contracts/Cargo.toml`. Any pull request that changes `contracts/src/lib.rs` +must bump that package version so deployed contract behavior can be traced back +to a semver release. + +The contract CI workflow diffs pull requests against `main` and fails when +`contracts/src/lib.rs` changes without a `contracts/Cargo.toml` version bump. +Maintainers may apply the `skip-version-check` label for trivial doc-only +changes that touch `lib.rs` but do not affect contract behavior. + ## Error Codes The contract uses named error codes for all invalid operations. These codes are emitted as panic messages in tests.