chore: 添加create-release.yml #2
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
# 当任意分支push时,检测package.json中有没有匹配的release,如果没有则创建一个release | |
name: Create release if no matching release exists | |
on: | |
push: | |
branches: | |
- '**' # 对任意分支进行监听 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
- name: Check for release in package.json | |
id: check | |
run: | | |
VERSION=$(node -p "require('./package.json').version") | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
RELEASES=$(gh release list --json version -q ".[] | select(.version == env.VERSION)") | |
if [[ -z "$RELEASES" ]]; then | |
echo "RELEASE_EXISTS=false" >> $GITHUB_ENV | |
else | |
echo "RELEASE_EXISTS=true" >> $GITHUB_ENV | |
- name: Create a new release | |
if: env.RELEASE_EXISTS == 'false' | |
run: gh release create $VERSION | |
# 否则输出RELEASE_EXISTS=true,不执行创建release的操作 | |