diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 28a29d3..3e465a9 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -99,6 +99,20 @@ jobs: filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}' show-emoji: false remove-type: true + + - name: Order Changelog (ASC) + uses: ./ + with: + filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}' + show-emoji: false + remove-type: true + + - name: Order Changelog (DESC) + uses: ./ + with: + filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}' + show-emoji: false + remove-type: true - name: Generate Changelog (outputs.changelog) run: echo "${{ steps.changelogEmoji.outputs.changelog }}" diff --git a/README.md b/README.md index 49dc4ef..0c8ba89 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ Only use the following Git Commit Messages. A simple and small footprint is crit - `base-ref` The name of the second branch. Defaults to the `tag_name` of the latest GitHub release. *This must be a GitHub release. Git tags or branches will not work.* - `original-markdown` Default `true`, Output clean markdown content. - `gh-pages` Default `gh-pages`, Specify the branch name to get the hash from +- `order` Default `asc`, Should the log results be displayed in descending (desc) or ascending (asc) order - `path` Only commits containing this file path will be returned. - `template` Define the log display template ([#111](https://github.com/jaywcjlove/changelog-generator/issues/111#issuecomment-1594085749)). - `show-emoji` Show emoji icons. Default `true`. diff --git a/action.yml b/action.yml index 5d5f27b..64e7ee6 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,10 @@ inputs: description: 'Specify the branch name to get the hash from' default: 'gh-pages' required: false + order: + description: 'Should the log results be displayed in descending (desc) or ascending (asc) order' + default: 'asc' + required: false base-ref: description: 'The name of the base reference' default: '' diff --git a/src/index.ts b/src/index.ts index 3240fae..9b089ee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ const getOptions = () => { baseRef: getInput('base-ref'), myToken, myPath: getInput('path'), + order: getInput('asc') as 'asc' | 'desc', template: getInput('template'), /** @example `type🆎,chore💄,fix🐞` Use commas to separate */ customEmoji: getInput('custom-emoji') || '', @@ -167,7 +168,8 @@ async function run() { let commitLog = []; info(`ResultData Lenght:${resultData.length}`) - for (const data of resultData) { + const resData = options.order == 'asc' ? resultData : resultData.reverse(); + for (const data of resData) { const message = data.commit.message.split('\n\n')[0]; const author = data.author || data.committer || { login: '-' }; startGroup(`Commit: \x1b[34m${message}\x1b[0m \x1b[34m${(data.commit.author || {}).name}(${author.login})\x1b[0m ${data.sha}`);