Skip to content

1.0.3

1.0.3 #41

Workflow file for this run

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
# Load .env file if it exists
- name: Load .env file if exists
run: |
if [ -f .env ]; then
set -a
source .env
set +a
fi
# Set Environment Variables with fallback to .env
- name: Set Environment Variables with fallback to .env
run: |
echo "NPM_READ_TOKEN=${{ secrets.NPM_READ_TOKEN || env.NPM_READ_TOKEN }}" >> $GITHUB_ENV
echo "NPM_PUBLISH_TOKEN=${{ secrets.NPM_PUBLISH_TOKEN || env.NPM_PUBLISH_TOKEN }}" >> $GITHUB_ENV
# 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=${{ env.NPM_PUBLISH_TOKEN }}" > ~/.npmrc
# Publish to npm (only if version doesn't exist)
- name: Publish to npm
if: steps.version-check.outputs.exists == 'false'
run: yarn start-publish --non-interactive --access public
# 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