-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,65 @@ | ||
name: Publish to npm | ||
name: Publish to npm (Only if version changes) | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
publish: | ||
check-and-publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 # Fetch the last commit for comparison | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
registry-url: "https://registry.npmjs.org/" | ||
|
||
- name: Get previous package.json version | ||
id: prev_version | ||
run: | | ||
PREV_VERSION=$(git show HEAD~1:package.json | jq -r '.version') | ||
echo "Previous version: $PREV_VERSION" | ||
echo "PREV_VERSION=$PREV_VERSION" >> $GITHUB_ENV | ||
- name: Get current package.json version | ||
id: current_version | ||
run: | | ||
CUR_VERSION=$(jq -r '.version' package.json) | ||
echo "Current version: $CUR_VERSION" | ||
echo "CUR_VERSION=$CUR_VERSION" >> $GITHUB_ENV | ||
- name: Check if version changed | ||
id: version_check | ||
run: | | ||
if [ "$PREV_VERSION" != "$CUR_VERSION" ]; then | ||
echo "Version changed, proceeding with publish." | ||
echo "PUBLISH=true" >> $GITHUB_ENV | ||
else | ||
echo "Version did not change, skipping publish." | ||
echo "PUBLISH=false" >> $GITHUB_ENV | ||
fi | ||
- name: Install dependencies | ||
if: env.PUBLISH == 'true' | ||
run: npm install | ||
|
||
- name: Build the package (if using TypeScript) | ||
- name: Build package (if necessary) | ||
if: env.PUBLISH == 'true' | ||
run: npm run build || echo "No build step" | ||
|
||
- name: Publish to npm | ||
if: env.PUBLISH == 'true' | ||
run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Skip publishing | ||
if: env.PUBLISH == 'false' | ||
run: echo "No version change detected. Skipping npm publish." |