Skip to content

Commit

Permalink
chore(ci): add ci for publishing package on version changed
Browse files Browse the repository at this point in the history
  • Loading branch information
extg5 committed May 20, 2024
1 parent 9987853 commit ef2b310
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn

- name: Build package
run: yarn build

- name: Check if version has changed
id: version_check
run: |
# Get the current version from package.json
current_version=$(jq -r '.version' package.json)
# Get the previous version from the last commit
git fetch --depth=2
previous_version=$(git show HEAD^1:package.json | jq -r '.version')
echo "Current version: $current_version"
echo "Previous version: $previous_version"
if [ "$current_version" != "$previous_version" ]; then
echo "::set-output name=version_changed::true"
else
echo "::set-output name=version_changed::false"
fi
- name: Publish to NPM
if: steps.version_check.outputs.version_changed == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_CI_TOKEN }}
run: npm publish --dry-run

0 comments on commit ef2b310

Please sign in to comment.