From 9bbb2c4e96fc87016a360f0613ddf41ad4a68cf9 Mon Sep 17 00:00:00 2001 From: Jeeva Ramachandran <120017870+JeevaRamu0104@users.noreply.github.com> Date: Wed, 29 Nov 2023 20:27:31 +0530 Subject: [PATCH] feat: add release new version action (#32) --- .github/cocogitto-changelog-template | 56 ++++++++++++++ .github/git-cliff-changelog.toml | 92 +++++++++++++++++++++++ .github/workflows/release-new-version.yml | 80 ++++++++++++++++++++ CHANGELOG.md | 17 +++++ cog.toml | 21 ++++++ package-lock.json | 4 +- package.json | 2 +- 7 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 .github/cocogitto-changelog-template create mode 100644 .github/git-cliff-changelog.toml create mode 100644 .github/workflows/release-new-version.yml create mode 100644 CHANGELOG.md create mode 100644 cog.toml diff --git a/.github/cocogitto-changelog-template b/.github/cocogitto-changelog-template new file mode 100644 index 000000000..37591139a --- /dev/null +++ b/.github/cocogitto-changelog-template @@ -0,0 +1,56 @@ +{# Using a literal newline to set the newline variable -#} +{% set newline = " +" -%} + +{% set commit_base_url = repository_url ~ "/commit/" -%} +{% set compare_base_url = repository_url ~ "/compare/" -%} +{% set pr_base_url = repository_url ~ "/pull/" -%} + +{% if version.tag -%} + ## {{ version.tag | trim_start_matches(pat="v") }} ({{ date | date(format="%Y-%m-%d") }}) +{% else -%} + {% set from = from.id -%} + {% set to = version.id -%} + + {% set from_shorthand = from.id | truncate(length=7, end="") -%} + {% set to_shorthand = version.id | truncate(length=7, end="") -%} + + ## Unreleased ([`{{ from_shorthand ~ ".." ~ to_shorthand }}`]({{ compare_base_url ~ from_shorthand ~ ".." ~ to_shorthand }})) +{% endif -%} + +{% for type, typed_commits in commits | sort(attribute="type") | group_by(attribute="type") %} +{# The `striptags` removes the HTML comments added while grouping -#} +### {{ type | striptags | trim | upper_first }} +{% for scope, scoped_commits in typed_commits | group_by(attribute="scope") %} +- {{ "**" ~ scope ~ ":" ~ "**" -}} + {% for commit in scoped_commits | sort(attribute="date") -%} + {% set shorthand = commit.id | truncate(length=7, end="") -%} + {% set commit_link = commit_base_url ~ commit.id -%} + {# Replace PR numbers in commit message with PR link -#} + {% set pr_number = commit.summary | split(pat="(#") | last | trim_end_matches(pat=")") -%} + {% set pr_link = "[#" ~ pr_number ~ "](" ~ pr_base_url ~ pr_number ~ ")" -%} + {% if scoped_commits | length != 1 %}{{ newline ~ " - " }}{% else %}{{ " " }}{% endif -%} + {{ commit.summary | upper_first | trim | replace(from="#" ~ pr_number, to=pr_link) }} ([`{{ shorthand }}`]({{ commit_link }})) + {%- endfor -%} +{% endfor -%} + +{% for commit in typed_commits | unscoped | sort(attribute="date") -%} + {% set shorthand = commit.id | truncate(length=7, end="") -%} + {% set commit_link = commit_base_url ~ commit.id -%} + {# Replace PR numbers in commit message with PR link -#} + {% set pr_number = commit.summary | split(pat="(#") | last | trim_end_matches(pat=")") -%} + {% set pr_link = "[#" ~ pr_number ~ "](" ~ pr_base_url ~ pr_number ~ ")" -%} + {{ newline ~ "- "}}{{ commit.summary | upper_first | trim | replace(from="#" ~ pr_number, to=pr_link) }} ([`{{ shorthand }}`]({{ commit_link }})) +{%- endfor %} +{% endfor %} +{% if version.tag and from.tag -%} + **Full Changelog:** [`{{ from.tag ~ "..." ~ version.tag }}`]({{ compare_base_url ~ from.tag ~ "..." ~ version.tag }}) +{%- elif version.tag and from.id -%} + **Full Changelog:** [`{{ from.id ~ "..." ~ version.tag }}`]({{ compare_base_url ~ from.id ~ "..." ~ version.tag }}) +{%- else -%} + {% set from = from.id -%} + {% set to = version.id -%} + {% set from_shorthand = from.id | truncate(length=7, end="") -%} + {% set to_shorthand = version.id | truncate(length=7, end="") -%} + **Full Changelog:** [`{{ from_shorthand ~ "..." ~ to_shorthand }}`]({{ compare_base_url ~ from_shorthand ~ "..." ~ to_shorthand }}) +{%- endif %} diff --git a/.github/git-cliff-changelog.toml b/.github/git-cliff-changelog.toml new file mode 100644 index 000000000..a82c637d8 --- /dev/null +++ b/.github/git-cliff-changelog.toml @@ -0,0 +1,92 @@ +# configuration file for git-cliff +# see https://github.com/orhun/git-cliff#configuration-file + +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to Hyperswitch Control Center will be documented here.\n +""" +# template for the changelog body +# https://tera.netlify.app/docs/#introduction +body = """ +{% set newline = "\n" -%} +{% set commit_base_url = "https://github.com/juspay/hyperswitch-control-center/commit/" -%} +{% set compare_base_url = "https://github.com/juspay/hyperswitch-control-center/compare/" -%} +{% 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") %} + {# The `striptags` removes the HTML comments added while grouping -#} + ### {{ group | striptags | trim | upper_first }} + {% for scope, commits in commits | group_by(attribute="scope") %} + - {{ "**" ~ scope ~ ":" ~ "**" -}} + {% for commit in commits -%} + {% if commits | length != 1 %}{{ newline ~ " - " }}{% else %}{{ " " }}{% endif -%} + {{ commit.message | upper_first | trim }} ([`{{ commit.id | truncate(length=7, end="") }}`]({{ commit_base_url ~ commit.id }})) + {%- endfor -%} + {%- endfor -%} + {%- for commit in commits -%} + {% if commit.scope %}{% else %} + - {{ commit.message | upper_first | trim }} ([`{{ commit.id | truncate(length=7, end="") }}`]({{ commit_base_url ~ commit.id }})) + {%- endif %} + {%- endfor %} +{% endfor %} +{% if previous and previous.commit_id and commit_id -%} + **Full Changelog:** [`{{ previous.version }}...{{ version }}`]({{ compare_base_url }}{{ previous.version }}...{{ version }})\n +{% endif %} +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = "" + +[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 preprocessing the commit messages +commit_preprocessors = [ + { pattern = "^ +", replace = "" }, # remove spaces at the beginning of the message + { pattern = " +", replace = " " }, # replace multiple spaces with a single space + { pattern = "\\(#([0-9]+)\\)", replace = "([#${1}](https://github.com/juspay/hyperswitch-control-center/pull/${1}))" }, # replace PR numbers with links + { pattern = "(\\n?Co-authored-by: .+ <.+@.+>\\n?)+", replace = "" }, # remove co-author information + { pattern = "(\\n?Signed-off-by: .+ <.+@.+>\\n?)+", replace = "" }, # remove sign-off information +] +# regex for parsing and grouping commits +# the HTML comments (``) are a workaround to get sections in custom order, since `git-cliff` sorts sections in alphabetical order +# reference: https://github.com/orhun/git-cliff/issues/9 +commit_parsers = [ + { message = "^(?i)(feat)", group = "Features" }, + { message = "^(?i)(fix)", group = "Bug Fixes" }, + { message = "^(?i)(perf)", group = "Performance" }, + { body = ".*security", group = "Security" }, + { message = "^(?i)(refactor)", group = "Refactors" }, + { message = "^(?i)(test)", group = "Testing" }, + { message = "^(?i)(docs)", group = "Documentation" }, + { message = "^(?i)(chore\\(version\\)): V[\\d]+\\.[\\d]+\\.[\\d]+", skip = true }, + { message = "^(?i)(chore)", group = "Miscellaneous Tasks" }, + { message = "^(?i)(build)", group = "Build System / Dependencies" }, + { message = "^(?i)(ci)", skip = true }, +] +# 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 = true +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" +# limit the number of commits included in the changelog. +# limit_commits = 42 diff --git a/.github/workflows/release-new-version.yml b/.github/workflows/release-new-version.yml new file mode 100644 index 000000000..93f3dc793 --- /dev/null +++ b/.github/workflows/release-new-version.yml @@ -0,0 +1,80 @@ +name: Release a new version + +# on: +# schedule: +# - cron: "30 14 * * 0-4" # Run workflow at 8 PM IST every Sunday-Thursday + +# workflow_dispatch: + +# concurrency: +# group: ${{ github.workflow }}-${{ github.ref }} +# cancel-in-progress: true + + +on: + pull_request_target: + types: + - closed + +env: + # Allow more retries for network requests in cargo (downloading crates) and + # rustup (installing toolchains). This should help to reduce flaky CI failures + # from transient network timeouts or other issues. + CARGO_NET_RETRY: 10 + RUSTUP_MAX_RETRIES: 10 + +jobs: + create-release: + name: Release a new version + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.AUTO_RELEASE_PAT }} + + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable 2 weeks ago + + - name: Install cocogitto + uses: baptiste0928/cargo-install@v2.2.0 + with: + crate: cocogitto + version: 5.4.0 + + - name: Set Git Configuration + shell: bash + run: | + git config --local user.name 'github-actions' + git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' + + - name: Obtain previous and new tag information + shell: bash + # Only consider tags on current branch when setting PREVIOUS_TAG + run: | + PREVIOUS_TAG="$(git tag --sort='version:refname' --merged | tail --lines 1)" + if [[ "$(cog bump --auto --dry-run)" == *"No conventional commits for your repository that required a bump"* ]]; then + NEW_TAG="$(cog bump --patch --dry-run)" + else + NEW_TAG="$(cog bump --auto --dry-run)" + fi + echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV + echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> $GITHUB_ENV + + - name: Update changelog and create tag + shell: bash + if: ${{ env.NEW_TAG != env.PREVIOUS_TAG }} + # Remove prefix 'v' from 'NEW_TAG' as cog bump --version expects only the version number + run: | + cog bump --version ${NEW_TAG#v} + + - name: Push created commit and tag + shell: bash + if: ${{ env.NEW_TAG != env.PREVIOUS_TAG }} + run: | + git push + git push --tags diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..581d2402c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,17 @@ +# Changelog +All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines. + +- - - + +## 1.1.0 (2023-11-29) + +### Features + +- Add-release-new-version-action ([`880a10e`](https://github.com/juspay/hyperswitch-control-center/commit/880a10e0695284bb76a6e4cf156774a8a6e0fb01)) +- Add change log template ([`9475c4a`](https://github.com/juspay/hyperswitch-control-center/commit/9475c4a2863c12110a4f8bf2826fa68cdba7ab09)) + +**Full Changelog:** [`v1.0.2...v1.1.0`](https://github.com/juspay/hyperswitch-control-center/compare/v1.0.2...v1.1.0) + +- - - + +Changelog generated by [cocogitto](https://github.com/cocogitto/cocogitto). \ No newline at end of file diff --git a/cog.toml b/cog.toml new file mode 100644 index 000000000..891bb24ee --- /dev/null +++ b/cog.toml @@ -0,0 +1,21 @@ +tag_prefix = "v" +ignore_merge_commits = true + +# the HTML comments (``) are a workaround to have sections in custom order, since they are alphabetically sorted +[commit_types] +feat = { changelog_title = "Features" } +fix = { changelog_title = "Bug Fixes" } +perf = { changelog_title = "Performance" } +refactor = { changelog_title = "Refactors" } +test = { changelog_title = "Testing" } +docs = { changelog_title = "Documentation" } +chore = { changelog_title = "Miscellaneous Tasks" } +build = { changelog_title = "Build System / Dependencies" } +ci = { changelog_title = "Continuous Integration", omit_from_changelog = true } + +[changelog] +path = "CHANGELOG.md" +template = ".github/cocogitto-changelog-template" +remote = "github.com" +owner = "juspay" +repository = "hyperswitch-control-center" diff --git a/package-lock.json b/package-lock.json index 6e047a0f3..a315ba727 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rescript-euler-dashboard", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rescript-euler-dashboard", - "version": "1.0.1", + "version": "1.0.2", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 6ed8903ce..c2f9c4eac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rescript-euler-dashboard", - "version": "1.0.1", + "version": "1.0.2", "main": "index.js", "author": "Shiva Nandan ", "license": "MIT",