v1.0.1 - Minor Improvements and Enhanced Functionality #3
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 Release | |
| on: | |
| release: | |
| types: [published] | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| - name: Cache npm dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Run tests | |
| run: | | |
| npm ci | |
| npm test | |
| - name: Validate package version | |
| run: | | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| if npm show stringwise version > /dev/null 2>&1; then | |
| CURRENT_VERSION=$(npm show stringwise version) | |
| if [ "$CURRENT_VERSION" = "$NEW_VERSION" ]; then | |
| echo "The version $NEW_VERSION is already published. Exiting." | |
| exit 1 | |
| fi | |
| else | |
| echo "Package not found in registry. Proceeding with first publish." | |
| fi | |
| - name: Authenticate to npm | |
| run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| - name: Publish to npm | |
| run: | | |
| npm ci | |
| npm publish --access public --loglevel verbose |