Skip to content

Commit

Permalink
chore: update husky and add release workflow (#6041)
Browse files Browse the repository at this point in the history
* chore: update husky

* chore: update github workflows

* chore: update scripts

* chore: fix workflow
  • Loading branch information
Aarebecca authored Jul 16, 2024
1 parent a82369e commit 36b9c6b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
@@ -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.'
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -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 }}
9 changes: 9 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 36b9c6b

Please sign in to comment.