Skip to content

Release publish NPM #12

Release publish NPM

Release publish NPM #12

name: Release publish NPM
on:
push:
branches:
- release
jobs:
release-publish-npm:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci
- name: Run unit tests
run: npm test
- name: Install dependencies
run: npm ci
- name: Initialize git user email
run: git config --global user.email "${{ env.RELEASE_USER_EMAIL }}"
- name: Initialize git user name
run: git config --global user.name "Release publish workflow"
- name: Initialize npm config
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Fetch latest release info
run: |
RELEASE_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases")
if [ $? -ne 0 ]; then
echo "Failed to fetch releases"
exit 1
fi
LATEST_RELEASE_NAME=$(echo "$RELEASE_JSON" | jq -r '.[0].name')
IS_PRE_RELEASE=$(echo "$RELEASE_JSON" | jq -r '.[0].prerelease')
echo "LATEST_RELEASE_NAME=$LATEST_RELEASE_NAME" >> $GITHUB_ENV
echo "IS_PRE_RELEASE=$IS_PRE_RELEASE" >> $GITHUB_ENV
- name: Fetch and checkout to release branch
run: |
git fetch --all
git checkout ${{ vars.RELEASE_BRANCH_NAME }}
- name: Publish to npm (pre-release)
if: env.IS_PRE_RELEASE == 'true'
run: npm publish --tag beta
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm
if: env.IS_PRE_RELEASE == 'false'
run: npm publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}