11---
2- name : Build And Publish Package Update
2+ name : Publish New Package Version
33
44on :
55 workflow_dispatch :
66 inputs :
7+ version :
8+ type : string
9+ description : " version"
710 package :
811 type : choice
912 description : Package name
1215 - addresses
1316 - indexer
1417 - mint-manager
18+ publish :
19+ type : boolean
20+ description : Publish to npm
21+ default : false
22+
1523
1624jobs :
1725 build-and-publish :
@@ -30,78 +38,72 @@ jobs:
3038 node-version : 24
3139 registry-url : ' https://registry.npmjs.org/'
3240
33- # - name: Authenticate with NmpJS
34- # run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
35-
36- - name : Install dependencies (root)
37- run : npm install
38-
39- - name : Build selected package
41+ - name : Validate version format and uniqueness
4042 working-directory : packages/${{ inputs.package }}
41- run : npm run build
43+ id : validate-version
44+ env :
45+ INPUT_VERSION : ${{ inputs.version }}
46+ run : |
47+ echo "Validating version: $INPUT_VERSION"
4248
49+ # Ensure semver format
50+ if [[ ! "$INPUT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
51+ echo "❌ Invalid version format. Must follow semantic versioning (e.g., 1.2.3 or 1.2.3-suffix)"
52+ exit 1
53+ fi
4354
44- - name : Determine new version
45- id : versioning
46- run : |
47- PACKAGE="${{ inputs.package }}"
55+ # Extract base semver (strip suffix if present)
56+ BASE_VERSION=$(echo "$INPUT_VERSION" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
4857
49- LATEST_TAG=$(git tag --list "*-${PACKAGE}" --sort=-v:refname | head -n 1)
58+ # Read current version from package.json
59+ CURRENT_VERSION=$(grep '"version":' package.json | head -1 | sed -E 's/.*"([0-9]+\.[0-9]+\.[0-9]+).*"/\1/')
5060
51-
52- if [ -z "$LATEST_TAG" ]; then
53- echo "No version found"
54- NEW_VERSION="1.0.0-$PACKAGE"
55- else
56- echo "Version found: $LATEST_TAG"
57- BASE_VERSION=${LATEST_TAG%-${PACKAGE}}
61+ echo "📦 Current: $CURRENT_VERSION"
62+ echo "🚀 New: $BASE_VERSION"
5863
59- IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
60- PATCH=$((PATCH + 1))
61- NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-$PACKAGE"
64+ npx --yes semver "$BASE_VERSION" -gt "$CURRENT_VERSION"
65+ if [[ $? -ne 0 ]]; then
66+ echo "❌ Provided version ($BASE_VERSION) must be greater than current version ($CURRENT_VERSION)"
67+ exit 1
6268 fi
6369
64- echo "New version: $NEW_VERSION "
70+ echo "✅ Version is valid and properly incremented. "
6571
66- # Set the version as output
67- echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
72+ - name : Install dependencies
73+ run : npm install
6874
69- - name : Update package version in package.json
75+ - name : Build selected package
7076 working-directory : packages/${{ inputs.package }}
71- env :
72- version : ${{ steps.versioning.outputs.version }}
73- run : |
74- PURE_VERSION=${version%-${package}}
75-
76- # Show for debug
77- echo "Original version: $version"
78- echo "Pure version for npm: $PURE_VERSION"
77+ run : npm run build
7978
80- # Run npm version with the pure semver
81- npm version $PURE_VERSION --no-git-tag-version
8279
83- - name : Publish package to npm registry
80+ - name : Update package version in package.json
8481 working-directory : packages/${{ inputs.package }}
85- run : npm publish --provenance --access public
86- env :
87- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
88-
89- - name : Commit and push version bump and tag
90- env :
91- version : ${{ steps.versioning.outputs.version }}
92- package : ${{ inputs.package }}
93- GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
9482 run : |
95- git config user.name "github-actions[bot]"
96- git config user.email "github-actions[bot]@users.noreply.github.com"
97-
98- # Commit the updated package.json with new version
99- git add packages/$package/package.json
100- git commit -m "chore($package): bump version to $version"
101-
102- # Create a tag with the version
103- git tag -a "$version" -m "Release $version"
104-
105- # Push commit and tag
106- git push origin HEAD
107- git push origin "$version"
83+ npm version ${{ inputs.version }} --no-git-tag-version
84+
85+ # - name: Publish package to npm registry
86+ # working-directory: packages/${{ inputs.package }}
87+ # run: npm publish --provenance --access public
88+ # env:
89+ # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
90+
91+ # - name: Commit and push version bump and tag
92+ # env:
93+ # version: ${{ steps.versioning.outputs.version }}
94+ # package: ${{ inputs.package }}
95+ # GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
96+ # run: |
97+ # git config user.name "github-actions[bot]"
98+ # git config user.email "github-actions[bot]@users.noreply.github.com"
99+
100+ # # Commit the updated package.json with new version
101+ # git add packages/$package/package.json
102+ # git commit -m "chore($package): bump version to $version"
103+
104+ # # Create a tag with the version
105+ # git tag -a "$version" -m "Release $version"
106+
107+ # # Push commit and tag
108+ # git push origin HEAD
109+ # git push origin "$version"
0 commit comments