This file contains hidden or 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
| name: Publish Package | ||
|
Check failure on line 1 in .github/workflows/publish.yml
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Setup node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18.x' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| cache: 'npm' | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| - name: Run test | ||
| run: npm test | ||
| - name: Build | ||
| run: npm run build --if-present | ||
| - name: Version check | ||
| id: check-version | ||
| run: | | ||
| PACKAGE_NAME=$(node -p "require('./package.json').name") | ||
| CURRENT_VERSION=$(node -p "require('./package.json').version") | ||
| NPM_VERSION=$(npm view $PACKAGE_NAME) versions --json | ||
| if $NPM_VERSION | grep -q "\"$CURRENT_VERSION\""; then | ||
| echo "version_exists=true" >> $GITHUB_OUTPUT | ||
| echo "Version $CURRENT_VERSION already exists on npm" | ||
| else | ||
| echo "version_exists=false" >> $GITHUB_OUTPUT | ||
| echo "Version $CURRENT_VERSION is new and will be published" | ||
| fi | ||
| - name: Publish | ||
| if: steps.check-version.outputs.version_exists == 'false' | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| - name: Get package version | ||
| id: package-version | ||
| run: echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT | ||
| - name: Create release | ||
| if: steps.check-version.outputs.version_exists == 'false' | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| generate_release_notes: true | ||
| tag_name: v${{ steps.check-version.outputs.version | ||
| release_name: Release ${{ steps.check-version.outputs.version | ||