From 8cd9130efb30a0ce096bace9bd5cb69e77646464 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Wed, 7 Feb 2024 07:55:37 +0000 Subject: [PATCH] Fix template. --- .gitlab/workflows/commitlint.yml | 1 + .vscode/settings.json | 1 - template/.commitlintrc.js | 1 + template/.vscode/settings.json | 4 ++- .../workflows/commitlint.yml | 28 +++++++++++++++++++ .../workflows/pr.yml | 22 --------------- .../workflows/commitlint.yml | 16 +++++++++++ .../workflows/mr.yml | 12 -------- 8 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 template/.commitlintrc.js create mode 100644 template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/commitlint.yml delete mode 100644 template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/pr.yml create mode 100644 template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/commitlint.yml delete mode 100644 template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/mr.yml diff --git a/.gitlab/workflows/commitlint.yml b/.gitlab/workflows/commitlint.yml index a88b75be..3f1c8f18 100644 --- a/.gitlab/workflows/commitlint.yml +++ b/.gitlab/workflows/commitlint.yml @@ -2,6 +2,7 @@ commitlint: image: name: commitlint/commitlint:latest entrypoint: [""] + interruptible: true rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == 'merge_request_event' diff --git a/.vscode/settings.json b/.vscode/settings.json index 1f4bcb8c..ef2700b9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,7 +21,6 @@ "automodule", "cobertura", "commitlint", - "conventionalcommits", "deepclean", "deflist", "devcontainer", diff --git a/template/.commitlintrc.js b/template/.commitlintrc.js new file mode 100644 index 00000000..422b1944 --- /dev/null +++ b/template/.commitlintrc.js @@ -0,0 +1 @@ +module.exports = { extends: ['@commitlint/config-conventional'] }; diff --git a/template/.vscode/settings.json b/template/.vscode/settings.json index b2843357..ef2700b9 100644 --- a/template/.vscode/settings.json +++ b/template/.vscode/settings.json @@ -20,6 +20,7 @@ "autofix", "automodule", "cobertura", + "commitlint", "deepclean", "deflist", "devcontainer", @@ -35,6 +36,7 @@ "maxdepth", "modindex", "mypy", + "noninteractive", "pathjoin", "pipenv", "pipx", @@ -151,7 +153,7 @@ ], "vscode-yaml-sort.noCompatMode": true, "vscode-yaml-sort.sortOnSave": 2, - "vscode-yaml-sort.useArrayProcessor": false, + "vscode-yaml-sort.useArrayProcessor": true, "vscode-yaml-sort.useBlockProcessor": false, "vscode-yaml-sort.useCustomSortRecursively": true, "vscode-yaml-sort.useHelmProcessor": false, diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/commitlint.yml b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/commitlint.yml new file mode 100644 index 00000000..2751ce2e --- /dev/null +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/commitlint.yml @@ -0,0 +1,28 @@ +name: CommitLint +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: env | sort + - name: Install commitlint with conventional config + run: npm install --save-dev @commitlint/config-conventional @commitlint/cli + - name: Validate the latest commit message with commitlint + if: github.event_name == 'push' + run: echo "${{ github.event.head_commit.message }}" | npx commitlint + - name: Validate pull request title with commitlint + if: github.event_name == 'pull_request' + run: echo "${{ github.event.pull_request.title }}" | npx commitlint +on: + pull_request: + types: + - opened + - synchronize + - reopened + - edited + push: + branches: + - main diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/pr.yml b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/pr.yml deleted file mode 100644 index eef3cd01..00000000 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/pr.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Lint pull request title -concurrency: - cancel-in-progress: true - group: ${{ github.workflow }}-${{ github.ref }} -jobs: - lint-title: - runs-on: ubuntu-latest - steps: - - name: Check PR Title for Conventional Commit Format - run: | - if ! echo "${{ github.event.pull_request.title }}" | grep -Pq '^(build|chore|ci|doc|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?!?:\s.*'; then - echo 'The title does not conform to the Conventional Commit.' - echo 'Please refer to "https://www.conventionalcommits.org/"' - exit 1 - fi -on: - pull_request: - types: - - opened - - synchronize - - reopened - - edited diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/commitlint.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/commitlint.yml new file mode 100644 index 00000000..3f1c8f18 --- /dev/null +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/commitlint.yml @@ -0,0 +1,16 @@ +commitlint: + image: + name: commitlint/commitlint:latest + entrypoint: [""] + interruptible: true + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + script: + - | + if [ "$CI_PIPELINE_SOURCE" = "push" ]; then + echo "$CI_COMMIT_TITLE" | commitlint + elif [ "$CI_PIPELINE_SOURCE" = "merge_request_event" ]; then + echo "$CI_MERGE_REQUEST_TITLE" | commitlint + fi + stage: ci diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/mr.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/mr.yml deleted file mode 100644 index ca8e8e5f..00000000 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/mr.yml +++ /dev/null @@ -1,12 +0,0 @@ -lint-title: - interruptible: true - rules: - - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - script: - - | - if ! echo "$CI_MERGE_REQUEST_TITLE" | grep -Pq '^(build|chore|ci|doc|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?!?:\s.*'; then - echo "The title does not conform to the Conventional Commit." - echo "Please refer to 'https://www.conventionalcommits.org/'" - exit 1 - fi - stage: ci