1.0.5 #43
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 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout the repository | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # Set up Node.js environment | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18" | |
| registry-url: "https://registry.npmjs.org/" | |
| # Enable Corepack | |
| - name: Enable Corepack | |
| run: corepack enable | |
| # Use the correct Yarn version | |
| - name: Use the correct Yarn version | |
| run: corepack prepare [email protected] --activate | |
| # Install dependencies | |
| - name: Install dependencies | |
| run: yarn install --immutable | |
| # Extract version from git tag | |
| - name: Extract version from tag | |
| run: | | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "Extracted version: $VERSION" | |
| # Check if version already exists on npm | |
| - name: Check if version exists on npm | |
| id: version-check | |
| run: | | |
| if npm view @devlander/utils@${{ env.VERSION }} version >/dev/null 2>&1; then | |
| echo "Version ${{ env.VERSION }} already exists on npm" | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version ${{ env.VERSION }} is new and will be published" | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| # Generate changelog | |
| - name: Generate changelog | |
| run: yarn changelog | |
| # Set up .npmrc for authentication | |
| - name: Set up .npmrc for authentication | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| echo "registry=https://registry.npmjs.org/" >> ~/.npmrc | |
| # Publish to npm (only if version doesn't exist) | |
| - name: Publish to npm | |
| if: steps.version-check.outputs.exists == 'false' | |
| run: | | |
| echo "Publishing version ${{ env.VERSION }} to npm..." | |
| yarn start-publish --non-interactive --access public | |
| echo "Successfully published version ${{ env.VERSION }}" | |
| # Skip publish if version exists | |
| - name: Skip publish - version already exists | |
| if: steps.version-check.outputs.exists == 'true' | |
| run: | | |
| echo "Skipping npm publish - version ${{ env.VERSION }} already exists" | |
| echo "This is normal if the tag was pushed multiple times" | |
| # Create GitHub release with changelog | |
| - name: Create GitHub release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref }} | |
| release_name: Release ${{ github.ref_name }} | |
| body_path: CHANGELOG.md | |
| draft: false | |
| prerelease: false |