mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 00:43:23 +00:00
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
83 lines
2.7 KiB
YAML
83 lines
2.7 KiB
YAML
name: Publish to NPM
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
registry-url: 'https://registry.npmjs.org'
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v2
|
|
with:
|
|
version: 10
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Run tests
|
|
run: pnpm test:int
|
|
|
|
- name: Build
|
|
run: pnpm build
|
|
|
|
- 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
|
|
|
|
# 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")
|
|
|
|
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
|
|
echo "changed=false" >> $GITHUB_OUTPUT
|
|
echo "No version change detected"
|
|
fi
|
|
|
|
- name: Publish to NPM
|
|
if: steps.version-check.outputs.changed == 'true'
|
|
run: npm publish
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
|
|
- name: Create GitHub Release
|
|
if: steps.version-check.outputs.changed == 'true'
|
|
uses: actions/create-release@v1
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
tag_name: v${{ steps.version-check.outputs.current }}
|
|
release_name: Release v${{ steps.version-check.outputs.current }}
|
|
draft: false
|
|
prerelease: false |