From 05a6da0b056c92414e9ee5d032722131f74c744e Mon Sep 17 00:00:00 2001 From: Richard Carruthers Date: Sat, 4 Oct 2025 18:39:51 -0500 Subject: [PATCH 1/2] ci(publish): make JavaScript version update step idempotent Check current package.json version before updating to avoid unnecessary npm version commands when the version is already set to the target value. This prevents potential errors and makes the workflow more resilient to re-runs. --- .github/workflows/publish.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4545559..30d2802 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -64,10 +64,17 @@ jobs: node-version: '20.x' registry-url: 'https://registry.npmjs.org' - - name: Update package.json version + - name: Check and update package.json version if needed working-directory: src/JavaScript/devpossible-ton run: | - npm version ${{ needs.read-version.outputs.version }} --no-git-tag-version + CURRENT_VERSION=$(node -p "require('./package.json').version") + TARGET_VERSION="${{ needs.read-version.outputs.version }}" + if [ "$CURRENT_VERSION" != "$TARGET_VERSION" ]; then + echo "Updating version from $CURRENT_VERSION to $TARGET_VERSION" + npm version $TARGET_VERSION --no-git-tag-version + else + echo "Version already set to $TARGET_VERSION, skipping update" + fi - name: Install dependencies working-directory: src/JavaScript/devpossible-ton From da9fb205440f0dc96e3f666a61c7cab63654890c Mon Sep 17 00:00:00 2001 From: Richard Carruthers Date: Sat, 4 Oct 2025 18:44:21 -0500 Subject: [PATCH 2/2] ci: change publish workflow to verify versions instead of updating Replace automatic version updates with strict verification in publish workflow. The workflow now fails if package.json or setup.py versions don't match version.json, instead of auto-correcting them. This ensures version-check.yml catches mismatches before publish runs, maintaining version consistency across the project. Changes: - Rename steps to "Verify" instead of "Update/Check and update" - Add version output logging for debugging - Exit with error on version mismatch instead of updating - Remove npm version and sed update commands --- .github/workflows/publish.yml | 24 ++++--- .github/workflows/version-check.yml | 107 ++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/version-check.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 30d2802..a925c35 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -64,16 +64,17 @@ jobs: node-version: '20.x' registry-url: 'https://registry.npmjs.org' - - name: Check and update package.json version if needed + - name: Verify package.json version working-directory: src/JavaScript/devpossible-ton run: | CURRENT_VERSION=$(node -p "require('./package.json').version") TARGET_VERSION="${{ needs.read-version.outputs.version }}" + echo "package.json version: $CURRENT_VERSION" + echo "version.json version: $TARGET_VERSION" if [ "$CURRENT_VERSION" != "$TARGET_VERSION" ]; then - echo "Updating version from $CURRENT_VERSION to $TARGET_VERSION" - npm version $TARGET_VERSION --no-git-tag-version - else - echo "Version already set to $TARGET_VERSION, skipping update" + echo "❌ Version mismatch detected!" + echo "This should not happen - version-check.yml should have caught this." + exit 1 fi - name: Install dependencies @@ -112,14 +113,19 @@ jobs: python -m pip install --upgrade pip pip install build twine - - name: Update version in setup.py + - name: Verify setup.py version working-directory: src/Python/devpossible_ton run: | VERSION="${{ needs.read-version.outputs.version }}" - # Convert alpha format (1.0.0-alpha to 1.0.0a0) PYTHON_VERSION=$(echo $VERSION | sed 's/-alpha/a0/') - sed -i "s/version=\"[^\"]*\"/version=\"$PYTHON_VERSION\"/" setup.py - cat setup.py | grep version= + CURRENT_VERSION=$(grep 'version=' setup.py | sed -n 's/.*version="\([^"]*\)".*/\1/p') + echo "setup.py version: $CURRENT_VERSION" + echo "Expected version: $PYTHON_VERSION" + if [ "$CURRENT_VERSION" != "$PYTHON_VERSION" ]; then + echo "❌ Version mismatch detected!" + echo "This should not happen - version-check.yml should have caught this." + exit 1 + fi - name: Build package working-directory: src/Python/devpossible_ton diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml new file mode 100644 index 0000000..5fd9257 --- /dev/null +++ b/.github/workflows/version-check.yml @@ -0,0 +1,107 @@ +name: Version Check + +on: + pull_request: + branches: [ main ] + paths: + - 'version.json' + - 'src/CSharp/DevPossible.Ton/DevPossible.Ton.csproj' + - 'src/JavaScript/devpossible-ton/package.json' + - 'src/Python/devpossible_ton/setup.py' + +jobs: + check-version-increment: + name: Verify Version Incremented + runs-on: ubuntu-latest + + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Get PR version + id: pr-version + run: | + PR_VERSION=$(jq -r '.library_version' version.json) + echo "version=$PR_VERSION" >> $GITHUB_OUTPUT + echo "PR Version: $PR_VERSION" + + - name: Checkout main branch + uses: actions/checkout@v4 + with: + ref: main + + - name: Get main version + id: main-version + run: | + MAIN_VERSION=$(jq -r '.library_version' version.json) + echo "version=$MAIN_VERSION" >> $GITHUB_OUTPUT + echo "Main Version: $MAIN_VERSION" + + - name: Compare versions + run: | + PR_VERSION="${{ steps.pr-version.outputs.version }}" + MAIN_VERSION="${{ steps.main-version.outputs.version }}" + + echo "Comparing versions:" + echo " Main branch: $MAIN_VERSION" + echo " PR branch: $PR_VERSION" + + # Function to compare semantic versions + compare_versions() { + # Remove any -alpha, -beta suffixes for comparison + local v1=$(echo $1 | sed 's/-.*$//') + local v2=$(echo $2 | sed 's/-.*$//') + + # Split into major.minor.patch + IFS='.' read -ra V1 <<< "$v1" + IFS='.' read -ra V2 <<< "$v2" + + # Compare major + if [ "${V1[0]}" -gt "${V2[0]}" ]; then + return 0 # v1 > v2 + elif [ "${V1[0]}" -lt "${V2[0]}" ]; then + return 1 # v1 < v2 + fi + + # Compare minor + if [ "${V1[1]}" -gt "${V2[1]}" ]; then + return 0 + elif [ "${V1[1]}" -lt "${V2[1]}" ]; then + return 1 + fi + + # Compare patch + if [ "${V1[2]}" -gt "${V2[2]}" ]; then + return 0 + elif [ "${V1[2]}" -lt "${V2[2]}" ]; then + return 1 + fi + + # Versions are equal + return 2 + } + + compare_versions "$PR_VERSION" "$MAIN_VERSION" + RESULT=$? + + if [ $RESULT -eq 0 ]; then + echo "✅ Version has been incremented correctly" + echo " $MAIN_VERSION → $PR_VERSION" + exit 0 + elif [ $RESULT -eq 2 ]; then + echo "❌ Version has not been incremented!" + echo " Both main and PR have version: $MAIN_VERSION" + echo "" + echo "Please update version.json to a higher version before merging." + echo "You can use: ./update-version.ps1" + exit 1 + else + echo "❌ PR version is LOWER than main version!" + echo " Main: $MAIN_VERSION" + echo " PR: $PR_VERSION" + echo "" + echo "Please update version.json to a version higher than $MAIN_VERSION" + exit 1 + fi