v1.0.1 #12
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: Verify and Deploy to npmjs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| deploy_npmjs_package: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Use Node.js 20 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20.x" | |
| registry-url: "https://registry.npmjs.org" | |
| scope: "@proangular" | |
| cache: "npm" | |
| - name: Install | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Lint (optional) | |
| if: hashFiles('.eslintrc*') != '' | |
| run: npm run lint --if-present | |
| - name: Test (optional) | |
| run: npm test --if-present | |
| - name: Read package version | |
| id: pkg | |
| shell: bash | |
| run: | | |
| VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("package.json","utf8")).version') | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Check if version already exists on npm | |
| id: check | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
| run: | | |
| set -e | |
| PKG=$(node -p "require('./package.json').name") | |
| CURRENT=$(npm view "$PKG" version --registry=https://registry.npmjs.org || echo "0.0.0") | |
| echo "current_registry_version=$CURRENT" >> "$GITHUB_OUTPUT" | |
| if [ "$CURRENT" = "${{ steps.pkg.outputs.version }}" ]; then | |
| echo "should_publish=false" >> "$GITHUB_OUTPUT" | |
| echo "Version $CURRENT already exists on npm. Skipping publish." | |
| else | |
| echo "should_publish=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Publish to npm | |
| if: steps.check.outputs.should_publish == 'true' | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: true | |
| run: npm publish --access public --registry=https://registry.npmjs.org |