mirror of
https://github.com/xtr-dev/payload-notifications.git
synced 2025-12-08 00:33:23 +00:00
Add GitHub Actions workflows for PR version check and NPM publishing
This commit is contained in:
43
.github/workflows/pr-version-check.yml
vendored
Normal file
43
.github/workflows/pr-version-check.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
name: PR Version Check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
types: [opened, synchronize]
|
||||
|
||||
jobs:
|
||||
version-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get PR branch package.json version
|
||||
id: pr-version
|
||||
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Get main branch package.json version
|
||||
id: main-version
|
||||
run: |
|
||||
git checkout main
|
||||
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Compare versions
|
||||
run: |
|
||||
PR_VERSION="${{ steps.pr-version.outputs.version }}"
|
||||
MAIN_VERSION="${{ steps.main-version.outputs.version }}"
|
||||
|
||||
echo "PR branch version: $PR_VERSION"
|
||||
echo "Main branch version: $MAIN_VERSION"
|
||||
|
||||
if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
|
||||
echo "❌ Version must be updated in package.json"
|
||||
echo "Current version: $MAIN_VERSION"
|
||||
echo "Please increment the version number before merging to main"
|
||||
exit 1
|
||||
else
|
||||
echo "✅ Version has been updated from $MAIN_VERSION to $PR_VERSION"
|
||||
fi
|
||||
49
.github/workflows/version-and-publish.yml
vendored
Normal file
49
.github/workflows/version-and-publish.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
name: Publish to NPM
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- 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@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Run tests
|
||||
run: pnpm test
|
||||
|
||||
- name: Run build
|
||||
run: pnpm build
|
||||
|
||||
- name: Get package version
|
||||
id: package-version
|
||||
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create and push git tag
|
||||
run: |
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email "actions@github.com"
|
||||
git tag -a "v${{ steps.package-version.outputs.version }}" -m "Release v${{ steps.package-version.outputs.version }}"
|
||||
git push origin "v${{ steps.package-version.outputs.version }}"
|
||||
|
||||
- name: Publish to NPM
|
||||
run: pnpm publish --access public --no-git-checks
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
Reference in New Issue
Block a user