Skip to content

Commit

Permalink
Adjust action to check latest published
Browse files Browse the repository at this point in the history
  • Loading branch information
stultusmundi committed Oct 27, 2024
1 parent 1ca66ba commit e20ba5a
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Publish to npm on Version Bump

# Trigger the workflow on push events to the main branch
# Trigger the workflow on push events to the master branch
on:
push:
branches:
Expand Down Expand Up @@ -38,23 +38,20 @@ jobs:
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "current_version=$CURRENT_VERSION" >> $GITHUB_ENV
# 5. Get the previous version from the last commit's package.json
- name: Get previous version
id: previous_version
# 5. Get the latest published version from npm
- name: Get latest published version from npm
id: latest_version
run: |
# Check if there is a previous commit
if git rev-parse HEAD~1 >/dev/null 2>&1; then
PREVIOUS_VERSION=$(git show HEAD~1:package.json | node -p "require('./package.json').version")
else
PREVIOUS_VERSION=$CURRENT_VERSION
fi
echo "previous_version=$PREVIOUS_VERSION" >> $GITHUB_ENV
PACKAGE_NAME=$(node -p "require('./package.json').name")
# Fetch the latest version from npm registry
LATEST_VERSION=$(npm view "$PACKAGE_NAME" version || echo "0.0.0")
echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV
# 6. Compare versions to detect a bump
- name: Check for version bump
id: version_check
run: |
if [ "$current_version" != "$previous_version" ]; then
if [ "$(printf '%s\n' "$LATEST_VERSION" "$CURRENT_VERSION" | sort -V | tail -n1)" = "$CURRENT_VERSION" ] && [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
echo "version_bumped=true" >> $GITHUB_ENV
else
echo "version_bumped=false" >> $GITHUB_ENV
Expand All @@ -70,4 +67,4 @@ jobs:
# 8. Notify if no version bump detected (optional)
- name: Notify no version bump
if: env.version_bumped != 'true'
run: echo "No version bump detected. Skipping npm publish."
run: echo "No version bump detected. Skipping npm publish."

0 comments on commit e20ba5a

Please sign in to comment.