From 8fc8bdadb9ab444cb7becc84d2101b90683bf677 Mon Sep 17 00:00:00 2001 From: Norton-Lin <358154247@qq.com> Date: Mon, 18 Nov 2024 16:49:57 +0800 Subject: [PATCH] feat: add workflow --- .github/workflows/commitlint.yml | 33 ++++++++++++++++++++++++++++++ .github/workflows/go_fmt_check.yml | 27 ++++++++++++++++++++++++ .github/workflows/prcheck.yml | 20 ++++++++++++++++++ README.md | 6 +++++- go.mod | 3 +++ src/main.go | 4 ++++ 6 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/commitlint.yml create mode 100644 .github/workflows/go_fmt_check.yml create mode 100644 .github/workflows/prcheck.yml create mode 100644 go.mod create mode 100644 src/main.go diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000..3692a9f --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,33 @@ + +name: Commitlint + +on: + push: + branches-ignore: ["main"] # 排除 main 分支的 push 事件 + pull_request: # 针对 pull_request 事件 + branches: + - main + - dev # 添加 dev 分支的 PR 检查 + workflow_dispatch: # 手动触发 workflow + + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # 确保可以获取完整的提交历史 + - uses: actions/setup-node@v3 + with: + node-version: '16' # 使用稳定的 Node.js 版本 + - run: npm install -g @commitlint/cli @commitlint/config-conventional + - run: | + echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js + - name: Check commits + run: | + if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then + commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose + else + commitlint --from $(git rev-list --max-parents=0 HEAD) --to HEAD --verbose + fi diff --git a/.github/workflows/go_fmt_check.yml b/.github/workflows/go_fmt_check.yml new file mode 100644 index 0000000..c092682 --- /dev/null +++ b/.github/workflows/go_fmt_check.yml @@ -0,0 +1,27 @@ +name: Go Format Check + +on: + push: + branches: + - "**" # 监听所有分支的 push + pull_request: # 针对所有 PR + branches: + - "**" + workflow_dispatch: # 手动触发 workflow + +jobs: + go-format-check: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.22" # 使用稳定的 Go 版本 + + - name: Check Go formatting + run: | + go fmt ./... + git diff --exit-code || (echo "❌ Go files are not properly formatted. Run 'go fmt' locally to fix." && exit 1) diff --git a/.github/workflows/prcheck.yml b/.github/workflows/prcheck.yml new file mode 100644 index 0000000..e04bd43 --- /dev/null +++ b/.github/workflows/prcheck.yml @@ -0,0 +1,20 @@ +name: Pull Request Title Check + +on: + pull_request: + branches: + - main + - dev + +jobs: + pr-title-check: + runs-on: ubuntu-latest + steps: + - name: Check pull request title + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: | + if ! echo "$PR_TITLE" | grep -Eq "^(feat|fix|docs|style|refactor|test|chore): .+"; then + echo "❌ Pull request title does not follow the conventional format (e.g., 'feat: description')" + exit 1 + fi diff --git a/README.md b/README.md index 9dbe68b..a7d42ce 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# hinghwa-dict-basic-service \ No newline at end of file +# hinghwa-dict-basic-service +文聚 - 基架组基础仓库 +提供 CI CD 组件 +后续提供基础权限控制框架 +## 项目结构 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..020ef36 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.22.2 diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..da29a2c --- /dev/null +++ b/src/main.go @@ -0,0 +1,4 @@ +package main + +func main() { +}