Skip to content

ci(github): rename command #9

ci(github): rename command

ci(github): rename command #9

Workflow file for this run

name: Release
on:
push:
tags:
- "v*.*.*"
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
env:
# Skip all npm/pnpm scripts
npm_config_ignore_scripts: true
# Skip Husky installation and execution on CI
HUSKY_SKIP_INSTALL: 1
HUSKY_SKIP_HOOKS: 1
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Install pnpm
run: npm install -g pnpm@10
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Run linting
run: pnpm run lint
- name: Run type checking
run: pnpm run typecheck
- name: Run tests
run: pnpm run test
- name: Build package
run: pnpm run build
- name: Extract tag version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Update package.json version
run: |
npm version ${{ steps.get_version.outputs.VERSION }} \
--no-git-tag-version \
--allow-same-version
- name: Configure Git for push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit version bump
run: |
git add package.json
git commit -m "chore: bump version to ${{ steps.get_version.outputs.VERSION }}" || echo "No changes to commit"
- name: Detect base branch and push version bump
run: |
BRANCH=$(git branch -r --contains $GITHUB_SHA | grep -v '\->' | grep -Eo '[^/]+$' | head -n 1)
echo "Pushing to $BRANCH"
git push origin HEAD:$BRANCH
- name: Publish to npm
run: NPM_CONFIG_PROVENANCE=true pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Pack package
run: pnpm pack
- name: Get existing release by tag
id: get_release
run: |
TAG=${{ github.ref_name }}
RELEASE_JSON=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG)
# Extract the "id" field from the JSON
RELEASE_ID=$(echo "$RELEASE_JSON" | grep '"id":' | head -n1 | sed -E 's/.*"id":[[:space:]]*([0-9]+).*/\1/')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
- name: Upload package asset
run: |
ASSET_FILE=$(ls *.tgz)
curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$ASSET_FILE" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets?name=$ASSET_FILE&label=$ASSET_FILE"