From c6644876d50707677e16c788410c939499956d09 Mon Sep 17 00:00:00 2001 From: Feng Kaiyu Date: Sat, 23 Mar 2024 01:59:40 +0800 Subject: [PATCH] ci: automatically generate changelog. --- .github/workflows/release.yml | 79 +++++++++++++++++++++++++++++++++-- cliff.toml | 77 +++++++++++++++++++++++----------- 2 files changed, 129 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aa1c6faf..5a83e145 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,6 @@ jobs: name: cls path: "*.cls" - publish_templates: name: Publish ${{ matrix.template }} runs-on: ubuntu-latest @@ -38,7 +37,16 @@ jobs: strategy: matrix: - template: [graduate-thesis, undergraduate-thesis, lab-report, paper-translation, presentation-slide, undergraduate-thesis-en, reading-report] + template: + [ + graduate-thesis, + undergraduate-thesis, + lab-report, + paper-translation, + presentation-slide, + undergraduate-thesis-en, + reading-report, + ] include: - template: graduate-thesis cls: bithesis @@ -82,7 +90,6 @@ jobs: asset_name: ${{ matrix.template }}.zip tag: ${{ github.ref }} - publish_cls: name: Publish ${{ matrix.cls }} runs-on: ubuntu-latest @@ -105,3 +112,69 @@ jobs: file: ${{ matrix.cls }}.cls asset_name: ${{ matrix.cls }}.cls tag: ${{ github.ref }} + + publish_pdfs: + name: Generate changelog + runs-on: ubuntu-latest + # Makesure it's the last job. + needs: [build, publish_cls, publish_templates] + outputs: + release_body: ${{ steps.git-cliff.outputs.content }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate a changelog + uses: orhun/git-cliff-action@v3 + id: git-cliff + with: + config: cliff.toml + args: -vv --latest --strip header + env: + OUTPUT: CHANGES.md + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@v2 + - name: Download PDF(s) + uses: actions/download-artifact@v3 + with: + name: bithesis + + - name: Upload the releases notes + uses: svenstaro/upload-release-action@v2 + with: + file: bithesis.pdf + repo_token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref }} + overwrite: true + body: | + ${{ steps.git-cliff.outputs.content }} + + update_changelog: + name: Generate changelog + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate a changelog + uses: orhun/git-cliff-action@v3 + with: + config: cliff.toml + args: --verbose + env: + OUTPUT: CHANGELOG.md + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Commit + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + set +e + git add CHANGELOG.md + git commit -m "Update CHANGELOG" + git push https://${{ secrets.GITHUB_TOKEN }}@github.com/BITNP/BIThesis.git main diff --git a/cliff.toml b/cliff.toml index 257386eb..9da6f27f 100644 --- a/cliff.toml +++ b/cliff.toml @@ -1,4 +1,9 @@ -# configuration file for git-cliff (0.1.0) +# 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 @@ -16,7 +21,7 @@ Acronyms: **Bolded text highlights its importance.**\n """ # template for the changelog body -# https://tera.netlify.app/docs/#introduction +# https://keats.github.io/tera/docs/#introduction body = """ {% if version %}\ ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} @@ -30,46 +35,70 @@ body = """ {% endif %}\ {% endif %}\ {% for group, commits in commits | group_by(attribute="group") %} - ### {{ group | upper_first }} + ### {{ group | striptags | trim | upper_first }} {% for commit in commits %} - - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/BITNP/BIThesis/commit/{{ commit.id }}))\ + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/BITNP/BIThesis/commit/{{ commit.id }}))\ {% endfor %} {% endfor %}\n """ -# remove the leading and trailing whitespace from the template -trim = true -# changelog footer +# 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", group = "Miscellaneous Tasks"}, - { body = ".*security", group = "Security"}, + { 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" }, + { message = "CHANGELOG|changelog", skip = true }, + { 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 -# glob pattern for matching git tags -tag_pattern = "v[0-9]*" +# regex for matching git tags +# tag_pattern = "v[0-9].*" # regex for skipping tags -# skip_tags = "v0.1.0-beta.1" +# skip_tags = "" # regex for ignoring tags -ignore_tags = ".*-alpha-.*" -# sort the tags chronologically -date_order = false +# 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