diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml new file mode 100644 index 0000000..30cbe43 --- /dev/null +++ b/.github/workflows/version-check.yml @@ -0,0 +1,38 @@ +name: Version Check + +on: + push: + branches: [main] + pull_request: + +jobs: + check-version: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract versions + id: versions + run: | + CARGO_VER=$(grep '^version' Cargo.toml | head -n1 | cut -d'"' -f2) + NPM_VER=$(node -p "require('./package.json').version") + echo "cargo=$CARGO_VER" >> $GITHUB_OUTPUT + echo "npm=$NPM_VER" >> $GITHUB_OUTPUT + + - name: Verify version consistency + run: | + if [ "${{ steps.versions.outputs.cargo }}" != "${{ steps.versions.outputs.npm }}" ]; then + echo "Version mismatch: Cargo.toml (${{ steps.versions.outputs.cargo }}) vs package.json (${{ steps.versions.outputs.npm }})" + exit 1 + fi + + - name: Prevent duplicate release + run: | + VER="${{ steps.versions.outputs.cargo }}" + if git tag -l "v$VER" | grep -q "^v$VER$"; then + echo "Tag v$VER already exists. Duplicate release prevented." + exit 1 + fi