Publish to npm #14
Workflow file for this run
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 to npm | |
| # on: | |
| # push: | |
| # tags: | |
| # - 'v*.*.*' # e.g. v1.0.0 | |
| # jobs: | |
| # build: | |
| # runs-on: ubuntu-latest | |
| # steps: | |
| # - name: Checkout repo | |
| # uses: actions/checkout@v4 | |
| # - name: Setup Node.js | |
| # uses: actions/setup-node@v4 | |
| # with: | |
| # node-version: '20' | |
| # registry-url: 'https://registry.npmjs.org/' | |
| # - name: Install dependencies | |
| # run: npm install | |
| # - name: Build project | |
| # run: npm run build | |
| # # - name: Run tests | |
| # # run: npm test | |
| # publish: | |
| # needs: build | |
| # runs-on: ubuntu-latest | |
| # steps: | |
| # - name: Checkout repo | |
| # uses: actions/checkout@v4 | |
| # - name: Setup Node.js | |
| # uses: actions/setup-node@v4 | |
| # with: | |
| # node-version: '20' | |
| # registry-url: 'https://registry.npmjs.org/' | |
| # - name: Install dependencies | |
| # run: npm install | |
| # - name: Build project | |
| # run: npm run build | |
| # - name: Publish to npm | |
| # run: npm publish --access public | |
| # env: | |
| # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| name: Publish to npm & GitHub Release | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" # e.g. v1.0.0 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org/" | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Build project | |
| run: npm run build | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org/" | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Build project | |
| run: npm run build | |
| - name: Check if version already exists | |
| id: check | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| NAME=$(node -p "require('./package.json').name") | |
| if npm view $NAME@$VERSION > /dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish to npm | |
| if: steps.check.outputs.exists == 'false' | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |