Skip to content

Commit

Permalink
upd publish ci
Browse files Browse the repository at this point in the history
  • Loading branch information
extg committed Aug 19, 2024
1 parent f026028 commit 5445e9c
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,35 @@ jobs:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Check if version has changed
id: version_check
- name: Check if version exists on npm
id: npm_version_check
run: |
# Get the current version from package.json
current_version=$(jq -r '.version' package.json)
echo "Current version: $current_version"
# Get the previous version from the last commit
git fetch --depth=2
previous_version=$(git show HEAD^1:package.json | jq -r '.version')
echo "Previous version: $previous_version"
if [ "$current_version" != "$previous_version" ]; then
echo "::set-output name=version_changed::true"
echo "::set-output name=current_version::$current_version"
package_name=$(jq -r '.name' package.json)
echo "Package name: $package_name"
# Check if the version exists on npm
npm_info=$(npm view "$package_name@$current_version" version || echo "not_found")
if [ "$npm_info" == "not_found" ]; then
echo "Version $current_version does not exist on npm."
echo "::set-output name=version_exists::false"
else
echo "::set-output name=version_changed::false"
echo "Version $current_version already exists on npm."
echo "::set-output name=version_exists::true"
fi
- name: Publish to NPM
if: steps.version_check.outputs.version_changed == 'true'
if: steps.npm_version_check.outputs.version_exists == 'false'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_CI_TOKEN }}
run: npm publish
run: |
npm publish
- name: Create GitHub Release
if: steps.version_check.outputs.version_changed == 'true'
if: steps.npm_version_check.outputs.version_exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down

0 comments on commit 5445e9c

Please sign in to comment.