mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 00:43:23 +00:00
Fix GitHub workflow to properly detect version changes
The workflow now detects version changes by: 1. Looking for version bump commits (created by npm version) 2. Checking if package.json was modified and version actually changed This works with the npm version workflow where: 1. Make changes and commit them 2. Run npm version patch (creates version commit) 3. Push both commits - workflow publishes on version commit
This commit is contained in:
21
.github/workflows/publish.yml
vendored
21
.github/workflows/publish.yml
vendored
@@ -35,25 +35,34 @@ jobs:
|
||||
- name: Build
|
||||
run: pnpm build
|
||||
|
||||
- name: Check if version changed
|
||||
- name: Check if should publish
|
||||
id: version-check
|
||||
run: |
|
||||
# Get current version from package.json
|
||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
# Get previous commit's version
|
||||
# Check if this is a version bump commit (created by npm version)
|
||||
COMMIT_MSG=$(git log -1 --pretty=%B)
|
||||
if echo "$COMMIT_MSG" | grep -q "^v[0-9]"; then
|
||||
echo "changed=true" >> $GITHUB_OUTPUT
|
||||
echo "Version bump commit detected: $COMMIT_MSG"
|
||||
# Or check if package.json was modified in this commit
|
||||
elif git diff --name-only HEAD~1 HEAD | grep -q "package.json"; then
|
||||
# Check if the version actually changed
|
||||
git show HEAD~1:package.json > prev-package.json 2>/dev/null || echo '{"version":"0.0.0"}' > prev-package.json
|
||||
PREVIOUS_VERSION=$(node -p "require('./prev-package.json').version")
|
||||
|
||||
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "previous=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
|
||||
echo "changed=true" >> $GITHUB_OUTPUT
|
||||
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
|
||||
else
|
||||
echo "changed=false" >> $GITHUB_OUTPUT
|
||||
echo "Version unchanged: $CURRENT_VERSION"
|
||||
echo "package.json modified but version unchanged: $CURRENT_VERSION"
|
||||
fi
|
||||
else
|
||||
echo "changed=false" >> $GITHUB_OUTPUT
|
||||
echo "No version change detected"
|
||||
fi
|
||||
|
||||
- name: Publish to NPM
|
||||
|
||||
Reference in New Issue
Block a user