Skip to content

fix: use npm instead of pnpm for auto release #3

fix: use npm instead of pnpm for auto release

fix: use npm instead of pnpm for auto release #3

Workflow file for this run

# .github/workflows/release.yml
name: Create Release
on:
push:
branches:
- master
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Get version from package.json
id: package_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ steps.package_version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Configure Git
if: steps.check_tag.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Delete and recreate release branch
if: steps.check_tag.outputs.exists == 'false'
run: |
# Check if release branch exists remotely
if git ls-remote --heads origin release | grep -q release; then
echo "Deleting existing release branch..."
git push origin --delete release
fi
# Create fresh release branch from master
git checkout -b release
# Add built files
git add -f dist/
# Commit built files
git commit -m "build: release v${{ steps.package_version.outputs.version }}"
# Force push release branch
git push -f origin release
- name: Create Git tag on release branch
if: steps.check_tag.outputs.exists == 'false'
run: |
git tag -a "v${{ steps.package_version.outputs.version }}" -m "Release v${{ steps.package_version.outputs.version }}"
git push origin "v${{ steps.package_version.outputs.version }}"
- name: Create Release
if: steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.package_version.outputs.version }}
name: Release v${{ steps.package_version.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
target_commitish: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Skip - Release already exists
if: steps.check_tag.outputs.exists == 'true'
run: |
echo "Release v${{ steps.package_version.outputs.version }} already exists. Skipping release creation."
echo "To create a new release, bump the version in package.json"