From 36b9c6b4c329d2c6ee105e2cb4bd167fc5893c7d Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 16 Jul 2024 15:35:47 +0800 Subject: [PATCH] chore: update husky and add release workflow (#6041) * chore: update husky * chore: update github workflows * chore: update scripts * chore: fix workflow --- .github/workflows/release-pr.yml | 27 ++++++++++++++++++++++++ .github/workflows/release.yml | 31 ++++++++++++++++++++++++++++ .github/workflows/version.yml | 35 ++++++++++++++++++++++++++++++++ .husky/pre-commit | 9 ++++++++ package.json | 3 ++- packages/g6/package.json | 2 +- 6 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release-pr.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/version.yml diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml new file mode 100644 index 00000000000..31893d0c8d3 --- /dev/null +++ b/.github/workflows/release-pr.yml @@ -0,0 +1,27 @@ +# 创建发布分支和 PR / Create release branch and PR +name: Create release PR + +on: + workflow_dispatch: + +jobs: + create_release_pr: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Create release branch + run: | + git checkout -b release + git add . + git commit -m "Update for automated release PR" || true + git push --set-upstream origin release + + - name: Create PR + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + base: v5 + title: '[Bot] Automated PR from release to v5' + body: 'This PR was created automatically by GitHub Actions.' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..fdb0bca4221 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +# 合并 release 分支到 v5 分支时自动发布到 npm +name: Auto Release +on: + pull_request: + types: [closed] + branches: + - v5 + +jobs: + release: + runs-on: ubuntu-latest + if: github.event.pull_request.head.ref == 'release' && github.event.pull_request.merged == true + + steps: + - uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Install pnpm and dependencies + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: pnpm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} & pnpm release diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 00000000000..391a68af5ac --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,35 @@ +# 自动更新版本号 / Auto Update Version +name: Auto Update Version +on: + push: + branches: + - release + +jobs: + version: + name: Update Package Version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Install pnpm and dependencies + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Update Version + run: | + cd ./packages/g6 + npm run version + + - name: Create Release Pull Request + uses: changesets/action@v1 + with: + commit: 'chore(release): update version' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.husky/pre-commit b/.husky/pre-commit index d24fdfc601b..66d55acb030 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,13 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +protected_branches="master v5" +current_branch=$(git rev-parse --abbrev-ref HEAD) +for branch in $protected_branches; do + if [ "$current_branch" == "$branch" ]; then + echo "\033[31mDirect commit to '$branch' branch are not allowed!\033[0m" + exit 1 + fi +done + npx lint-staged diff --git a/package.json b/package.json index 06a0d05ba85..1043a06157d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "build": "turbo build --filter=!@antv/g6-site", "ci": "turbo run ci --filter=!@antv/g6-site", "contribute": "node ./scripts/contribute.mjs", - "publish": "pnpm publish -r --publish-branch v5" + "publish": "pnpm publish -r --publish-branch v5", + "release": "changeset release" }, "commitlint": { "extends": [ diff --git a/packages/g6/package.json b/packages/g6/package.json index ac119166306..c9653c9667d 100644 --- a/packages/g6/package.json +++ b/packages/g6/package.json @@ -45,7 +45,7 @@ "fix": "eslint ./src ./__tests__ --fix && prettier ./src __tests__ --write ", "jest": "node --expose-gc --max-old-space-size=1024 --unhandled-rejections=strict ../../node_modules/jest/bin/jest --coverage --logHeapUsage --detectOpenHandles", "lint": "eslint ./src __tests__ --quiet && prettier ./src __tests__ --check", - "prepublishOnly": "run-s version ci readme", + "prepublishOnly": "run-s ci readme", "readme": "cp ../../README.* ./", "size": "limit-size", "start": "rimraf ./lib && tsc --module commonjs --outDir lib --watch",