Merge pull request #30 from oneWalker/dev #1
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: NPM Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js with caching | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' # Enables npm dependency caching | |
| cache-dependency-path: '**/package-lock.json' # Cache key based on lockfile | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Check version change | |
| id: check_version | |
| run: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| PREV_VERSION=$(git show HEAD^:package.json | grep '"version":' | sed -E 's/.*"version": *"([^"]+)".*/\1/') | |
| if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then | |
| echo "Version changed from $PREV_VERSION to $CURRENT_VERSION" | |
| echo "version_changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version unchanged: $CURRENT_VERSION" | |
| echo "version_changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish to npm | |
| if: steps.check_version.outputs.version_changed == 'true' | |
| run: npm publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |