fix: npm publish #4
This file contains 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 Package | |
on: | |
push: | |
branches: [main] | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
registry-url: 'https://npm.pkg.github.com' | |
- name: Create Beta Tag | |
id: tag | |
run: | | |
set -e | |
# Get current version | |
current_version=$(node -p "require('./package.json').version") | |
# Generate a beta tag using GitHub run number | |
beta_tag="beta.${GITHUB_RUN_NUMBER}" | |
# Create full version with beta tag | |
base_version=$(echo $current_version | cut -f1,2 -d.) | |
patch_version=$(echo $current_version | cut -f3 -d.) | |
new_patch_version=$((patch_version + 1)) | |
new_version="${current_version}-${beta_tag}" | |
new_version="${base_version}.${new_patch_version}-${beta_tag}" | |
# Create an annotated tag | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
git tag -a "$new_version" -m "Release version $new_version" | |
# Set output for later steps | |
echo "::set-output name=tag_name::$new_version" | |
- name: Push Beta Tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
git push origin "${{ steps.tag.outputs.tag_name }}" | |
- name: Configure .npmrc | |
run: | | |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc | |
- name: Install Dependencies | |
run: npm install | |
- name: Publish Package | |
# run: npm publish --tag "${{ steps.tag.outputs.tag_name }}" | |
run: | | |
set -e | |
npm version "${{ steps.tag.outputs.tag_name }}" --no-git-tag-version | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |