From 0f9510b7f5c69cd5ffd7a5e2cbfa9d7613db55e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Vescera?= Date: Wed, 19 Jul 2023 23:16:14 +0200 Subject: [PATCH] feat(actions): Migliorata Auto Tag & Release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migliorati titoli delle varie fasi dell'action con emoji e resi più esplicativi. Ora l'action genera un changelog migliore, personalizzabile e molto più completo. È in grado di capire ogni commit a quale catogiria appartiene (feat, fix, perf, chore, ecc.), prende tutti i commit di una PR mergiata (prima solo il commit di merge e basta), per ogni commit aggiunge l'id e l'autore, include alla fine il link all'intero Changelog (di GitHub). Il template con cui si genera il changelog è completamente personalizzabile: - è possibile modificare, aggiungere e togliere i gruppi - è possibile aggiungere testi prima, dopo e nei commit - è possibile aggiungere emoji e strutture in markdown --- .github/workflows/autorelease.yml | 51 ++++++++++++-------- .github/workflows/configs/conf.toml | 72 +++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/configs/conf.toml diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index bfeffaade..46c2c72df 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -1,24 +1,18 @@ -name: Auto Tag and Release +name: Auto Tag and Release 🦧 on: push: - branches: - - master - -permissions: - id-token: write - contents: write - packages: write - pull-requests: read + branches: [main, master] jobs: tag: + name: Bumb Tag Version 🚀 runs-on: ubuntu-latest outputs: newtag: ${{ steps.tag.outputs.new-tag }} steps: - - uses: actions/checkout@v3 - - uses: phish108/autotag-action@v1.1.64 + - Auto Tag + uses: phish108/autotag-action@v1.1.64 id: tag with: github-token: ${{ secrets.GITHUB_TOKEN}} @@ -28,13 +22,34 @@ jobs: release-branch: master dry-run: "true" - release: - runs-on: ubuntu-latest + releasse: + name: Create GitHub Release 📰 needs: tag + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: "marvinpinto/action-automatic-releases@latest" + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Generate changelog + uses: orhun/git-cliff-action@v2 + id: git-cliff + with: + config: .github/workflows/configs/conf.toml + args: -vv --latest --unreleased --strip header --tag v${{needs.tag.outputs.newtag}} + env: + OUTPUT: CHANGES.md + + - name: Cat Changelog + run: cat ${{ steps.git-cliff.outputs.changelog }} + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "v${{needs.tag.outputs.newtag}}" - prerelease: false + tag_name: "v${{needs.tag.outputs.newtag}}" + release_name: "v${{needs.tag.outputs.newtag}}" + body: ${{ steps.git-cliff.outputs.content }} + diff --git a/.github/workflows/configs/conf.toml b/.github/workflows/configs/conf.toml new file mode 100644 index 000000000..9c5689227 --- /dev/null +++ b/.github/workflows/configs/conf.toml @@ -0,0 +1,72 @@ +# configuration file for git-cliff (0.1.0) + +[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://tera.netlify.app/docs/#introduction +body = """ +{% set github_repo_link = "https://github.com/Typing-Monkeys/AppuntiUniversita" %} +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}]({{ github_repo_link }}/commit/{{ commit.id }})) by {{ commit.author.name }}\ + {% endfor %} +{% endfor %}\n + +**Full changelog: {{ github_repo_link }}/compare/{{ previous.version }}...{{ version }}**\n +""" +#postprocessors = [{ pattern = ".*", replace_command ='gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28 "/repos/ncvescera/provaactions/commits/$COMMIT_SHA | jq -r .author.login'}] +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" +# postprocessors= [ +# #{pattern = "@username", replace_command='gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28 "/repos/ncvescera/provaactions/commits/$COMMIT_SHA | jq -r .author.login'}, +# {patter="A", replace="X"}, +# ] + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = false +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits + +# commit_preprocessors = [ +# {pattern = "username", replace_command="gh api -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: 2022-11-28' /repos/ncvescera/provaactions/commits/$COMMIT_SHA | jq -r .author.login"}, +# ] +commit_parsers = [ + { message = "^feat", group = "Features 🚀"}, + { message = "^fix", group = "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 = ".*", group = "Commits "}, +] +# 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 skipping tags +skip_tags = "v0.1.0-beta.1" +# 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"