Skip to content

feat: remove redundant version update step from GitHub Actions workflow #13

feat: remove redundant version update step from GitHub Actions workflow

feat: remove redundant version update step from GitHub Actions workflow #13

Workflow file for this run

name: Publish to NPM
on:
push:
branches:
- main
- develop
workflow_dispatch:
inputs:
release_type:
description: 'Release type (stable/alpha)'
required: true
default: 'stable'
type: choice
options:
- stable
- alpha
permissions:
contents: write
jobs:
version-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org/'
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Set Release Type
id: release_type
run: |
if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
echo "type=alpha" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "type=stable" >> $GITHUB_OUTPUT
else
echo "type=${{ inputs.release_type }}" >> $GITHUB_OUTPUT
fi
- name: Install Dependencies
run: |
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
pnpm run preinstall:develop && pnpm install
else
pnpm run preinstall:stable && pnpm install
fi
- name: Build
run: |
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
pnpm run build:develop
else
pnpm run build:stable
fi
- name: Get Package Version
id: package_version
run: |
VERSION=$(node -p "require('./package.json').version")
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
VERSION="${VERSION}-alpha.$(date +%s)"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RELEASE_TAG="v${{ steps.package_version.outputs.version }}"
gh release create $RELEASE_TAG \
--target=$GITHUB_SHA \
--title="$RELEASE_TAG" \
--generate-notes
- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [[ "${{ steps.release_type.outputs.type }}" == "alpha" ]]; then
pnpm publish --access=public --tag alpha --no-git-checks
else
pnpm publish --access=public --no-git-checks
fi