Skip to content

Commit d2f7774

Browse files
committed
add semver
1 parent c989a8c commit d2f7774

File tree

4 files changed

+79
-71
lines changed

4 files changed

+79
-71
lines changed
Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
2-
name: Build And Publish Package Update
2+
name: Publish New Package Version
33

44
on:
55
workflow_dispatch:
66
inputs:
7+
version:
8+
type: string
9+
description: "version"
710
package:
811
type: choice
912
description: Package name
@@ -30,78 +33,81 @@ jobs:
3033
node-version: 24
3134
registry-url: 'https://registry.npmjs.org/'
3235

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
36+
- name: Validate version format and uniqueness
37+
id: validate-version
4038
working-directory: packages/${{ inputs.package }}
41-
run: npm run build
42-
43-
44-
- name: Determine new version
45-
id: versioning
39+
env:
40+
INPUT_VERSION: ${{ inputs.version }}
4641
run: |
47-
PACKAGE="${{ inputs.package }}"
48-
49-
LATEST_TAG=$(git tag --list "*-${PACKAGE}" --sort=-v:refname | head -n 1)
42+
echo "Validating version: $INPUT_VERSION"
5043
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}}
44+
# Extract semver portion (strip suffix like -offchain-manager)
45+
SEMVER=$(echo "$INPUT_VERSION" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
5846
59-
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
60-
PATCH=$((PATCH + 1))
61-
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-$PACKAGE"
47+
if [[ -z "$SEMVER" ]]; then
48+
echo "❌ Invalid version format. Must follow semantic versioning (e.g., 1.0.0)"
49+
exit 1
6250
fi
6351
64-
echo "New version: $NEW_VERSION"
65-
66-
# Set the version as output
67-
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
52+
# Extract current version from package.json
53+
CURRENT_VERSION=$(jq -r '.version' package.json)
54+
55+
echo "Current version in package.json: $CURRENT_VERSION"
56+
echo "Proposed version: $SEMVER"
57+
58+
# Compare versions using node + semver module
59+
RESULT=$(node -p "
60+
const semver = require('semver');
61+
const current = '$CURRENT_VERSION';
62+
const next = '$SEMVER';
63+
if (!semver.valid(next)) {
64+
console.error('❌ Invalid semver:', next);
65+
process.exit(1);
66+
}
67+
if (semver.lte(next, current)) {
68+
console.error('❌ Provided version must be greater than current version.');
69+
process.exit(1);
70+
}
71+
'✅ Version is valid and greater.';
72+
")
73+
74+
echo "$RESULT"
75+
76+
- name: Install dependencies
77+
run: npm install
6878

69-
- name: Update package version in package.json
79+
- name: Build selected package
7080
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"
81+
run: npm run build
7982

80-
# Run npm version with the pure semver
81-
npm version $PURE_VERSION --no-git-tag-version
8283

83-
- name: Publish package to npm registry
84+
- name: Update package version in package.json
8485
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 }}
9486
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"
87+
npm version ${{ inputs.version }} --no-git-tag-version
88+
89+
# - name: Publish package to npm registry
90+
# working-directory: packages/${{ inputs.package }}
91+
# run: npm publish --provenance --access public
92+
# env:
93+
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
94+
95+
# - name: Commit and push version bump and tag
96+
# env:
97+
# version: ${{ steps.versioning.outputs.version }}
98+
# package: ${{ inputs.package }}
99+
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
100+
# run: |
101+
# git config user.name "github-actions[bot]"
102+
# git config user.email "github-actions[bot]@users.noreply.github.com"
103+
104+
# # Commit the updated package.json with new version
105+
# git add packages/$package/package.json
106+
# git commit -m "chore($package): bump version to $version"
107+
108+
# # Create a tag with the version
109+
# git tag -a "$version" -m "Release $version"
110+
111+
# # Push commit and tag
112+
# git push origin HEAD
113+
# git push origin "$version"

changelog/addresses.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"workspaces": [
88
"packages/*"
99
],
10-
"dependencies": {},
1110
"devDependencies": {
12-
"lerna": "^8.1.9"
11+
"lerna": "^8.1.9",
12+
"semver": "^7.7.2"
1313
}
1414
}

0 commit comments

Comments
 (0)