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:
29
.github/workflows/publish.yml
vendored
29
.github/workflows/publish.yml
vendored
@@ -35,25 +35,34 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
- name: Check if version changed
|
- name: Check if should publish
|
||||||
id: version-check
|
id: version-check
|
||||||
run: |
|
run: |
|
||||||
# Get current version from package.json
|
# Get current version from package.json
|
||||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||||
|
|
||||||
# Get previous commit's version
|
|
||||||
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 "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "previous=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
|
# 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 "changed=true" >> $GITHUB_OUTPUT
|
||||||
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
|
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")
|
||||||
|
|
||||||
|
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 "package.json modified but version unchanged: $CURRENT_VERSION"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "changed=false" >> $GITHUB_OUTPUT
|
echo "changed=false" >> $GITHUB_OUTPUT
|
||||||
echo "Version unchanged: $CURRENT_VERSION"
|
echo "No version change detected"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Publish to NPM
|
- name: Publish to NPM
|
||||||
|
|||||||
Reference in New Issue
Block a user