From 5ff7a11f7bae89dbd53151fb23abb15aa9db6c48 Mon Sep 17 00:00:00 2001 From: unknowIfGuestInDream Date: Fri, 15 Nov 2024 21:42:23 +0800 Subject: [PATCH 1/2] ci: Add pr.yml Signed-off-by: unknowIfGuestInDream --- .github/workflows/pr.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 000000000..2aeb311fc --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,20 @@ +name: Pull Request Author Check +on: + pull_request: + branches: [ 'master' ] + +jobs: + pr_check: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + - name: set PR info + run: | + echo PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }') >> $GITHUB_ENV + echo PR_TITLE=$(jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH") >> $GITHUB_ENV + echo PR_URL=$(jq --raw-output .pull_request.html_url "$GITHUB_EVENT_PATH") >> $GITHUB_ENV + echo PR_USER=$(jq --raw-output .pull_request.user.login "$GITHUB_EVENT_PATH") >> $GITHUB_ENV + + - name: print env + run: printenv From a0cbb2e9b276221368758a9d45ec00e4ef5fdffa Mon Sep 17 00:00:00 2001 From: unknowIfGuestInDream Date: Fri, 15 Nov 2024 22:04:01 +0800 Subject: [PATCH 2/2] ci: Add commit-check.yml Signed-off-by: unknowIfGuestInDream --- .commit-check.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/artifact.yml | 1 + .github/workflows/commit-check.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/pr.yml | 20 -------------------- 4 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 .commit-check.yml create mode 100644 .github/workflows/commit-check.yml delete mode 100644 .github/workflows/pr.yml diff --git a/.commit-check.yml b/.commit-check.yml new file mode 100644 index 000000000..05818cb2a --- /dev/null +++ b/.commit-check.yml @@ -0,0 +1,30 @@ +checks: + + - check: message + regex: '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)' + error: "The commit message should be structured as follows:\n\n + [optional scope]: \n + [optional body]\n + [optional footer(s)]\n\n + More details please refer to https://www.conventionalcommits.org" + suggest: please check your commit message whether matches above regex + + - check: branch + regex: ^(bugfix|feature|release|hotfix|task|chore)\/.+|(master)|(main)|(HEAD)|(PR-.+) + error: "Branches must begin with these types: bugfix/ feature/ release/ hotfix/ task/ chore/" + suggest: run command `git checkout -b type/branch_name` + + - check: author_name + regex: ^[A-Za-z ,.\'-]+$|.*(\[bot]) + error: The committer name seems invalid + suggest: run command `git config user.name "Your Name"` + + - check: author_email + regex: ^.+@.+$ + error: The committer email seems invalid + suggest: run command `git config user.email yourname@example.com` + + - check: merge_base + regex: master # it can be master, develop, devel etc based on your project. + error: Current branch is not rebased onto target branch + suggest: please ensure your branch is rebased with the target branch diff --git a/.github/workflows/artifact.yml b/.github/workflows/artifact.yml index 6f6e4d17c..3662e76f9 100644 --- a/.github/workflows/artifact.yml +++ b/.github/workflows/artifact.yml @@ -21,6 +21,7 @@ on: - 'qodana.yaml' - 'SECURITY.md' - '.imgbotconfig' + - '.commit-check.yml' workflow_dispatch: concurrency: # On master/release, we don't want any jobs cancelled so the sha is used to name the group diff --git a/.github/workflows/commit-check.yml b/.github/workflows/commit-check.yml new file mode 100644 index 000000000..efe9bf25a --- /dev/null +++ b/.github/workflows/commit-check.yml @@ -0,0 +1,29 @@ +name: Commit Check + +on: + pull_request: + branches: 'master' + +jobs: + commit-check: + runs-on: ubuntu-latest + permissions: # use permissions because of use pr-comments + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} # checkout PR HEAD commit + fetch-depth: 0 # required for merge-base check + - uses: commit-check/commit-check-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.CHANGELOG }} # use GITHUB_TOKEN because of use pr-comments + with: + message: false + branch: false + author-name: true + author-email: true + commit-signoff: true + merge-base: false + job-summary: true + pr-comments: true diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 2aeb311fc..000000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Pull Request Author Check -on: - pull_request: - branches: [ 'master' ] - -jobs: - pr_check: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v4 - - name: set PR info - run: | - echo PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }') >> $GITHUB_ENV - echo PR_TITLE=$(jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH") >> $GITHUB_ENV - echo PR_URL=$(jq --raw-output .pull_request.html_url "$GITHUB_EVENT_PATH") >> $GITHUB_ENV - echo PR_USER=$(jq --raw-output .pull_request.user.login "$GITHUB_EVENT_PATH") >> $GITHUB_ENV - - - name: print env - run: printenv