diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4ca2fe7..7106487 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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: |