publish-npm #3
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-npm | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version number to use' | |
| required: true | |
| jobs: | |
| process-release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Extract version from the release tag | |
| run: | | |
| VERSION=${{ github.event.inputs.version }} | |
| echo "The version from the tag is: $VERSION" | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Checkout code for the release tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.VERSION }} | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Run the build script | |
| run: npm run build | |
| - name: List files after build | |
| run: ls -al ./dist | |
| - name: Extract version from package.json in dist folder | |
| id: package_version | |
| run: | | |
| VERSION=$(node -p "require('./dist/package.json').version") | |
| echo "Version from package.json: $VERSION" | |
| # Save to environment variable explicitly accessible by later steps | |
| echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV" | |
| - name: Compare Git tag version to package.json version explicitly | |
| run: | | |
| echo "env.VERSION = ${{ env.VERSION }}" | |
| echo "env.PACKAGE_VERSION = ${{ env.PACKAGE_VERSION }}" | |
| if [ "${{ env.VERSION }}" != "v${{ env.PACKAGE_VERSION }}" ]; then | |
| echo "❌ Versions mismatch: Git tag version (${{ env.VERSION }}) and package.json version (v${{ env.PACKAGE_VERSION }}) explicitly differ! Stopping." | |
| exit 1 | |
| else | |
| echo "✅ Versions match explicitly: Git tag version and package.json version both are (${{ env.VERSION }})" | |
| fi | |
| - name: Publish to npm | |
| working-directory: ./dist | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Use npm token from repository secrets | |
| run: npm publish --dry-run |