Skip to content

Commit e20ba5a

Browse files
committed
Adjust action to check latest published
1 parent 1ca66ba commit e20ba5a

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

.github/workflows/publish.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Publish to npm on Version Bump
22

3-
# Trigger the workflow on push events to the main branch
3+
# Trigger the workflow on push events to the master branch
44
on:
55
push:
66
branches:
@@ -38,23 +38,20 @@ jobs:
3838
CURRENT_VERSION=$(node -p "require('./package.json').version")
3939
echo "current_version=$CURRENT_VERSION" >> $GITHUB_ENV
4040
41-
# 5. Get the previous version from the last commit's package.json
42-
- name: Get previous version
43-
id: previous_version
41+
# 5. Get the latest published version from npm
42+
- name: Get latest published version from npm
43+
id: latest_version
4444
run: |
45-
# Check if there is a previous commit
46-
if git rev-parse HEAD~1 >/dev/null 2>&1; then
47-
PREVIOUS_VERSION=$(git show HEAD~1:package.json | node -p "require('./package.json').version")
48-
else
49-
PREVIOUS_VERSION=$CURRENT_VERSION
50-
fi
51-
echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_ENV
45+
PACKAGE_NAME=$(node -p "require('./package.json').name")
46+
# Fetch the latest version from npm registry
47+
LATEST_VERSION=$(npm view "$PACKAGE_NAME" version || echo "0.0.0")
48+
echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV
5249
5350
# 6. Compare versions to detect a bump
5451
- name: Check for version bump
5552
id: version_check
5653
run: |
57-
if [ "$current_version" != "$previous_version" ]; then
54+
if [ "$(printf '%s\n' "$LATEST_VERSION" "$CURRENT_VERSION" | sort -V | tail -n1)" = "$CURRENT_VERSION" ] && [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
5855
echo "version_bumped=true" >> $GITHUB_ENV
5956
else
6057
echo "version_bumped=false" >> $GITHUB_ENV
@@ -70,4 +67,4 @@ jobs:
7067
# 8. Notify if no version bump detected (optional)
7168
- name: Notify no version bump
7269
if: env.version_bumped != 'true'
73-
run: echo "No version bump detected. Skipping npm publish."
70+
run: echo "No version bump detected. Skipping npm publish."

0 commit comments

Comments
 (0)