Skip to content

use token to trigger #12

use token to trigger

use token to trigger #12

# test
name: version, tag and github release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci') }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: pnpm/action-setup@v4
- name: Check if version already exists
id: version-check
working-directory: apps/cli
run: |
package_version=$(node -p "require('./package.json').version")
exists=$(gh api repos/${{ github.repository }}/releases/tags/v$package_version >/dev/null 2>&1 && echo "true" || echo "")
if [ -n "$exists" ]; then
echo "Version v$package_version already exists"
echo "::warning file=package.json,line=1::Version v$package_version already exists - no release will be created. If you want to create a new release, please update the version in package.json and push again."
echo "skipped=true" >> $GITHUB_OUTPUT
else
echo "Version v$package_version does not exist. Creating release..."
echo "version=$package_version" >> $GITHUB_OUTPUT
echo "skipped=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies and build
if: ${{ steps.version-check.outputs.skipped == 'false' }}
working-directory: apps/cli
run: |
pnpm install
pnpm run build
- name: Generate oclif README
if: ${{ steps.version-check.outputs.skipped == 'false' }}
id: oclif-readme
working-directory: apps/cli
run: |
pnpm exec oclif readme
if [ -n "$(git status --porcelain)" ]; then
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add README.md
git commit -m "docs: update readme [skip ci]"
git push
fi
- name: Create Release
if: ${{ steps.version-check.outputs.skipped == 'false' }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: v${{ steps.version-check.outputs.version }}
name: v${{ steps.version-check.outputs.version }}
draft: false
prerelease: false