Skip to content

Commit

Permalink
Change the order of logs to match git log.
Browse files Browse the repository at this point in the history
Many users are surprised that the default is to reverse the order of
logs. This is not the command line default. At the time I first wrote
this it made sense to me but I do not remember why. So its a breaking
change so we will rev the major. Users that want to keep the old way
will need to add `reverse: true` to their workflow.
  • Loading branch information
metcalfc committed Nov 22, 2021
1 parent cc17b6d commit 7daf4da
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -14,6 +14,10 @@ inputs:
description: 'The name of the base reference'
default: ''
required: false
reverse:
description: 'Git log is chronological order by default. Set to true to reverse chronological order. '
default: 'false'
required: false
outputs:
changelog:
description: 'Markdown formatted changelog'
Expand Down
10 changes: 9 additions & 1 deletion changelog.sh
Expand Up @@ -4,6 +4,11 @@ set -eou pipefail
head_ref=$1
base_ref=$2
repo_url=$3
extra_flags=""

if [ "$4" == "true" ]; then
extra_flags='--reverse'
fi

# By default a GitHub action checkout is shallow. Get all the tags, branches,
# and history. Redirect output to standard error which we can collect in the
Expand All @@ -20,9 +25,12 @@ then
base_ref=$(git rev-list --max-parents=0 HEAD)
fi

# Bash quoting will get you. Do not quote the extra_flags. If its null
# we want it to disappear. If you quote it, it will go to git as an ""
# and thats not a valid arg.
log=$(git log "${base_ref}...${head_ref}" \
--pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \
--reverse)
${extra_flags})

if [ -z "$log" ];
then
Expand Down
7 changes: 6 additions & 1 deletion dist/changelog.sh
Expand Up @@ -5,6 +5,11 @@ head_ref=$1
base_ref=$2
repo_url=$3

reverse = ""
if [ $strval1 != "true" ]; then
reverse = "--reverse"
fi

# By default a GitHub action checkout is shallow. Get all the tags, branches,
# and history. Redirect output to standard error which we can collect in the
# action.
Expand All @@ -22,7 +27,7 @@ fi

log=$(git log "${base_ref}...${head_ref}" \
--pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \
--reverse)
${reverse})

if [ -z "$log" ];
then
Expand Down
11 changes: 8 additions & 3 deletions dist/index.js
Expand Up @@ -7677,6 +7677,7 @@ async function run() {
var headRef = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('head-ref')
var baseRef = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('base-ref')
const myToken = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('myToken')
const reverse = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('reverse')
const octokit = new _actions_github__WEBPACK_IMPORTED_MODULE_2__.getOctokit(myToken)
const { owner, repo } = _actions_github__WEBPACK_IMPORTED_MODULE_2__.context.repo
const regexp = /^[.A-Za-z0-9_-]*$/
Expand Down Expand Up @@ -7708,7 +7709,7 @@ async function run() {
regexp.test(headRef) &&
regexp.test(baseRef)
) {
getChangelog(headRef, baseRef, owner + '/' + repo)
getChangelog(headRef, baseRef, owner + '/' + repo, reverse)
} else {
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed)(
'Branch names must contain only numbers, strings, underscores, periods, and dashes.'
Expand All @@ -7719,7 +7720,7 @@ async function run() {
}
}

async function getChangelog(headRef, baseRef, repoName) {
async function getChangelog(headRef, baseRef, repoName, reverse) {
try {
let output = ''
let err = ''
Expand All @@ -7736,7 +7737,11 @@ async function getChangelog(headRef, baseRef, repoName) {
}
options.cwd = './'

await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)(__nccwpck_require__.ab + "changelog.sh", [headRef, baseRef, repoName], options)
await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)(
__nccwpck_require__.ab + "changelog.sh",
[headRef, baseRef, repoName, reverse],
options
)

if (output) {
console.log(
Expand Down
11 changes: 8 additions & 3 deletions index.js
Expand Up @@ -9,6 +9,7 @@ async function run() {
var headRef = getInput('head-ref')
var baseRef = getInput('base-ref')
const myToken = getInput('myToken')
const reverse = getInput('reverse')
const octokit = new getOctokit(myToken)
const { owner, repo } = context.repo
const regexp = /^[.A-Za-z0-9_-]*$/
Expand Down Expand Up @@ -40,7 +41,7 @@ async function run() {
regexp.test(headRef) &&
regexp.test(baseRef)
) {
getChangelog(headRef, baseRef, owner + '/' + repo)
getChangelog(headRef, baseRef, owner + '/' + repo, reverse)
} else {
setFailed(
'Branch names must contain only numbers, strings, underscores, periods, and dashes.'
Expand All @@ -51,7 +52,7 @@ async function run() {
}
}

async function getChangelog(headRef, baseRef, repoName) {
async function getChangelog(headRef, baseRef, repoName, reverse) {
try {
let output = ''
let err = ''
Expand All @@ -68,7 +69,11 @@ async function getChangelog(headRef, baseRef, repoName) {
}
options.cwd = './'

await _exec(`${src}/changelog.sh`, [headRef, baseRef, repoName], options)
await _exec(
`${src}/changelog.sh`,
[headRef, baseRef, repoName, reverse],
options
)

if (output) {
console.log(
Expand Down

0 comments on commit 7daf4da

Please sign in to comment.