From 1eea31bf789815c991db37c7e4e88e409c8e73f7 Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 16 May 2024 16:31:31 +0800 Subject: [PATCH 1/7] chore(cliff): add cliff config --- cliff.toml | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 cliff.toml diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..b0f88b2 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,89 @@ +# git-cliff ~ default configuration file +# https://git-cliff.org/docs/configuration +# +# Lines starting with "#" are comments. +# Configuration options are organized into tables and keys. +# See documentation for more information on available options. + +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits %} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing s +trim = true +# postprocessors +postprocessors = [ + # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL +] + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [ + # Replace issue numbers + #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, + # Check spelling of the commit with https://github.com/crate-ci/typos + # If the spelling is incorrect, it will be automatically fixed. + #{ pattern = '.*', replace_command = 'typos --write-changes -' }, +] +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "🚀 Features" }, + { message = "^fix", group = "🐛 Bug Fixes" }, + { message = "^doc", group = "📚 Documentation" }, + { message = "^perf", group = "⚡ Performance" }, + { message = "^refactor", group = "🚜 Refactor" }, + { message = "^style", group = "🎨 Styling" }, + { message = "^test", group = "🧪 Testing" }, + { message = "^chore\\(release\\): prepare for", skip = true }, + { message = "^chore\\(deps.*\\)", skip = true }, + { message = "^chore\\(pr\\)", skip = true }, + { message = "^chore\\(pull\\)", skip = true }, + { message = "^chore|^ci", group = "⚙️ Miscellaneous Tasks" }, + { body = ".*security", group = "🛡️ Security" }, + { message = "^revert", group = "◀️ Revert" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = false +# regex for matching git tags +# tag_pattern = "v[0-9].*" +# regex for skipping tags +# skip_tags = "" +# regex for ignoring tags +# ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" +# limit the number of commits included in the changelog. +# limit_commits = 42 From 6d98d69bf20f1f6add8e7e0a4fd03ce7ba3ebbec Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 16 May 2024 16:44:09 +0800 Subject: [PATCH 2/7] =?UTF-8?q?ci(gitlab-ci):=20=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8F=91=E5=B8=83=E7=89=88=E6=9C=AC=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab/ci.yml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.gitlab/ci.yml b/.gitlab/ci.yml index 69e7b4d..b22ac0e 100644 --- a/.gitlab/ci.yml +++ b/.gitlab/ci.yml @@ -22,17 +22,19 @@ build: - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "web" -gitlab-release: - stage: release - image: registry.gitlab.com/gitlab-org/release-cli:latest - script: - - mkdir prview && typst compile --root=. --font-path=fonts template/thesis.typ prview/thesis.pdf - dependencies: - - build - rules: - - if: '$CI_COMMIT_TAG' - when: never - - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH - release: - tag_name: '$CI_COMMIT_TAG' - description: '$CI_COMMIT_TAG' +# TODO: this compile output need to move to pre-release +# gitlab-release: +# stage: release +# image: registry.gitlab.com/gitlab-org/release-cli:latest +# script: +# - mkdir prview && typst compile --root=. --font-path=fonts template/thesis.typ prview/thesis.pdf +# dependencies: +# - build +# rules: +# - if: '$CI_COMMIT_TAG' +# when: never +# - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH +# - if: $CI_PIPELINE_SOURCE == "web" +# release: +# tag_name: '$CI_COMMIT_TAG' +# description: '$CI_COMMIT_TAG' From fbd9bdef5da8eac68e0662df1247ea685a6d577e Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 16 May 2024 17:07:17 +0800 Subject: [PATCH 3/7] ci(gitlab-ci): pull the checks for each merge request --- .gitlab/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab/ci.yml b/.gitlab/ci.yml index b22ac0e..7e522b5 100644 --- a/.gitlab/ci.yml +++ b/.gitlab/ci.yml @@ -14,7 +14,8 @@ before_script: - export PATH="$PATH:$CARGO_HOME/bin" - cargo install typst-cli git-cliff -build: +# each merge request are required to ensure compiling the `.typ`s file successfully. +merge-check: stage: check script: - typst compile --root=$CI_PROJECT_DIR --font-path=$CI_PROJECT_DIR/fonts $CI_PROJECT_DIR/template/thesis.typ From acdeffcee944e2a66d4e29c04d1ff00d04f938bf Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 16 May 2024 21:59:25 +0800 Subject: [PATCH 4/7] ci(gitlab-ci): check when merged to the default branch --- .gitlab/ci.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitlab/ci.yml b/.gitlab/ci.yml index 7e522b5..11e5e0c 100644 --- a/.gitlab/ci.yml +++ b/.gitlab/ci.yml @@ -15,7 +15,7 @@ before_script: - cargo install typst-cli git-cliff # each merge request are required to ensure compiling the `.typ`s file successfully. -merge-check: +check-merge-request: stage: check script: - typst compile --root=$CI_PROJECT_DIR --font-path=$CI_PROJECT_DIR/fonts $CI_PROJECT_DIR/template/thesis.typ @@ -23,7 +23,22 @@ merge-check: - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "web" -# TODO: this compile output need to move to pre-release +check-default-branch: + stage: check + script: + - typst compile \ + --root $CI_PROJECT_DIR \ + --font-path $CI_PROJECT_DIR/fonts \ + $CI_PROJECT_DIR/template/thesis.typ \ + $CI_PROJECT_DIR/thesis_preview.pdf + rules: + - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == "web" + # TODO(#1): the preview pdf should be generated by template repo + # artifacts: + # paths: + # - $CI_PROJECT_DIR/thesis_preview.pdf + # gitlab-release: # stage: release # image: registry.gitlab.com/gitlab-org/release-cli:latest From 10eadd94dac5fd5403b267bd41b3d4a73f3e1251 Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 17 May 2024 11:13:17 +0800 Subject: [PATCH 5/7] ci: change gitlab-ci's trigger rules --- .gitlab/ci.yml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/.gitlab/ci.yml b/.gitlab/ci.yml index 11e5e0c..7593544 100644 --- a/.gitlab/ci.yml +++ b/.gitlab/ci.yml @@ -17,23 +17,17 @@ before_script: # each merge request are required to ensure compiling the `.typ`s file successfully. check-merge-request: stage: check - script: - - typst compile --root=$CI_PROJECT_DIR --font-path=$CI_PROJECT_DIR/fonts $CI_PROJECT_DIR/template/thesis.typ rules: - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - - if: $CI_PIPELINE_SOURCE == "web" + script: + - typst compile --root=$CI_PROJECT_DIR --font-path=$CI_PROJECT_DIR/fonts $CI_PROJECT_DIR/template/thesis.typ check-default-branch: stage: check - script: - - typst compile \ - --root $CI_PROJECT_DIR \ - --font-path $CI_PROJECT_DIR/fonts \ - $CI_PROJECT_DIR/template/thesis.typ \ - $CI_PROJECT_DIR/thesis_preview.pdf rules: - - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH - - if: $CI_PIPELINE_SOURCE == "web" + - if: ($CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH) && ($CI_PIPELINE_SOURCE == "web") + script: + - typst compile --root=$CI_PROJECT_DIR --font-path=$CI_PROJECT_DIR/fonts $CI_PROJECT_DIR/template/thesis.typ $CI_PROJECT_DIR/thesis_preview.pdf # TODO(#1): the preview pdf should be generated by template repo # artifacts: # paths: From 3ba1b6a1c4448e24954bee2e97141ae4a583d6b6 Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 17 May 2024 11:27:32 +0800 Subject: [PATCH 6/7] =?UTF-8?q?ci(gitlab-ci):=20=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 gitlab 页面触发 main 流水线时,自动创建 verion-bump-up 提交,并触发流水线创建 --- .gitlab/ci.yml | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/.gitlab/ci.yml b/.gitlab/ci.yml index 7593544..d1685b3 100644 --- a/.gitlab/ci.yml +++ b/.gitlab/ci.yml @@ -12,7 +12,7 @@ stages: before_script: - export PATH="$PATH:$CARGO_HOME/bin" - - cargo install typst-cli git-cliff + - cargo install typst-cli git-cliff sd # each merge request are required to ensure compiling the `.typ`s file successfully. check-merge-request: @@ -33,18 +33,29 @@ check-default-branch: # paths: # - $CI_PROJECT_DIR/thesis_preview.pdf -# gitlab-release: -# stage: release -# image: registry.gitlab.com/gitlab-org/release-cli:latest -# script: -# - mkdir prview && typst compile --root=. --font-path=fonts template/thesis.typ prview/thesis.pdf -# dependencies: -# - build -# rules: -# - if: '$CI_COMMIT_TAG' -# when: never -# - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH -# - if: $CI_PIPELINE_SOURCE == "web" -# release: -# tag_name: '$CI_COMMIT_TAG' -# description: '$CI_COMMIT_TAG' +release-commit: + stage: release + rules: + - if: ($CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH) && ($CI_PIPELINE_SOURCE == "web") + script: + - git config user.name $GITLAB_USER_NAME && git config user.email $GITLAB_USER_EMAIL + - VERSION=$(git cliff --bumped-version --unrelease) + - git cliff --bump --unreleased > release-note.md + - | + sd 'version = ".*"' 'version = "$VERSION"' $CI_PROJECT_DIR/typst.toml + - git add . && git commit -m "ci(release): $VERSION" + - git tag $VERSION -m --file=release-note.md + - git push --tags + +gitlab-release: + stage: release + needs: + - release-commit + image: registry.gitlab.com/gitlab-org/release-cli:latest + script: + - echo "releasing $CI_COMMIT_TAG on GitLab!" + rules: + - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && '$CI_COMMIT_TAG' + release: + tag_name: '$CI_COMMIT_TAG' + description: '$CI_COMMIT_TAG_MESSAGE' From 3ee312f29b0b108e09ed7332602f48a91471dd6c Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 17 May 2024 11:33:23 +0800 Subject: [PATCH 7/7] ci(gitlab-ci): fix syntax error rasied by wrong use of colon --- .gitlab/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/ci.yml b/.gitlab/ci.yml index d1685b3..585068c 100644 --- a/.gitlab/ci.yml +++ b/.gitlab/ci.yml @@ -43,7 +43,7 @@ release-commit: - git cliff --bump --unreleased > release-note.md - | sd 'version = ".*"' 'version = "$VERSION"' $CI_PROJECT_DIR/typst.toml - - git add . && git commit -m "ci(release): $VERSION" + - git add . && git commit -m "ci(release):$VERSION" - git tag $VERSION -m --file=release-note.md - git push --tags