diff --git a/README.md b/README.md index 489c803..0703ede 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ The name of the head reference. Default `${{github.sha}}`. 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.* +### `reverse` + +Whether the order of commits should be printed in reverse. Default: 'false' + +### `fetch` + +Whether this action should pull in all other branches and tags. Default: 'true' + ## Outputs ### `changelog` @@ -58,6 +66,25 @@ Or, if you have two specific references you want: base-ref: 'v0.0.1' ``` +If you want to point to a branch containing forward slashes (https://github.com/metcalfc/changelog-generator/issues/179) do the following: + +```yaml + +# let the checkout action do the fetching +- uses: actions/checkout@v3 + with: + fetch-depth: 0 + +- name: Generate changelog + id: changelog + uses: metcalfc/changelog-generator@v4.0.1 #TODO: bump this after release + with: + myToken: ${{ secrets.GITHUB_TOKEN }} + head-ref: 'origin/my/branch/with/slashes' #add 'origin/` in front of your branch name + base-ref: 'v1.0.0' + fetch: false +``` + ### Second block Then you can use the resulting changelog: diff --git a/action.yml b/action.yml index 104b689..7f75741 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,10 @@ inputs: description: 'Git log is chronological order by default. Set to true to reverse chronological order. ' default: 'false' required: false + fetch: + description: 'Whether to have this action fetch all other branches and tags' + default: 'true' + required: false outputs: changelog: description: 'Markdown formatted changelog' diff --git a/changelog.sh b/changelog.sh index 1f8f3c2..be46343 100755 --- a/changelog.sh +++ b/changelog.sh @@ -10,12 +10,16 @@ if [ "$4" == "true" ]; then extra_flags='--reverse' fi +fetch=$5 + # 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. -git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2 -git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2 -git fetch --prune --unshallow 1>&2 +if [ "$fetch" == "true" ]; then + git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2 + git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2 + git fetch --prune --unshallow 1>&2 +fi # if folks don't have a base ref to compare against just use the initial # commit. This will show all the changes since the beginning but I can't @@ -28,7 +32,7 @@ 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}" \ +log=$(git log "${base_ref}"..."${head_ref}" \ --pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \ ${extra_flags}) diff --git a/dist/changelog.sh b/dist/changelog.sh index 1f8f3c2..be46343 100755 --- a/dist/changelog.sh +++ b/dist/changelog.sh @@ -10,12 +10,16 @@ if [ "$4" == "true" ]; then extra_flags='--reverse' fi +fetch=$5 + # 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. -git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2 -git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2 -git fetch --prune --unshallow 1>&2 +if [ "$fetch" == "true" ]; then + git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2 + git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2 + git fetch --prune --unshallow 1>&2 +fi # if folks don't have a base ref to compare against just use the initial # commit. This will show all the changes since the beginning but I can't @@ -28,7 +32,7 @@ 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}" \ +log=$(git log "${base_ref}"..."${head_ref}" \ --pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \ ${extra_flags}) diff --git a/dist/index.js b/dist/index.js index 79a0ddc..f8bdd7f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11641,9 +11641,10 @@ async function run() { 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 fetch = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('fetch') 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_-]*$/ + const regexp = /^[.A-Za-z0-9_/-]*$/ if (!headRef) { headRef = _actions_github__WEBPACK_IMPORTED_MODULE_2__.context.sha @@ -11672,10 +11673,10 @@ async function run() { regexp.test(headRef) && regexp.test(baseRef) ) { - getChangelog(headRef, baseRef, owner + '/' + repo, reverse) + getChangelog(headRef, baseRef, owner + '/' + repo, reverse, fetch) } else { (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed)( - 'Branch names must contain only numbers, strings, underscores, periods, and dashes.' + 'Branch names must contain only numbers, strings, underscores, periods, forward slashes, and dashes.' ) } } catch (error) { @@ -11683,7 +11684,7 @@ async function run() { } } -async function getChangelog(headRef, baseRef, repoName, reverse) { +async function getChangelog(headRef, baseRef, repoName, reverse, fetch) { try { let output = '' let err = '' @@ -11702,7 +11703,7 @@ async function getChangelog(headRef, baseRef, repoName, reverse) { await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)( __nccwpck_require__.ab + "changelog.sh", - [headRef, baseRef, repoName, reverse], + [headRef, baseRef, repoName, reverse, fetch], options ) diff --git a/index.js b/index.js index b17fefc..1a829d3 100644 --- a/index.js +++ b/index.js @@ -10,9 +10,10 @@ async function run() { var baseRef = getInput('base-ref') const myToken = getInput('myToken') const reverse = getInput('reverse') + const fetch = getInput('fetch') const octokit = new getOctokit(myToken) const { owner, repo } = context.repo - const regexp = /^[.A-Za-z0-9_-]*$/ + const regexp = /^[.A-Za-z0-9_/-]*$/ if (!headRef) { headRef = context.sha @@ -41,10 +42,10 @@ async function run() { regexp.test(headRef) && regexp.test(baseRef) ) { - getChangelog(headRef, baseRef, owner + '/' + repo, reverse) + getChangelog(headRef, baseRef, owner + '/' + repo, reverse, fetch) } else { setFailed( - 'Branch names must contain only numbers, strings, underscores, periods, and dashes.' + 'Branch names must contain only numbers, strings, underscores, periods, forward slashes, and dashes.' ) } } catch (error) { @@ -52,7 +53,7 @@ async function run() { } } -async function getChangelog(headRef, baseRef, repoName, reverse) { +async function getChangelog(headRef, baseRef, repoName, reverse, fetch) { try { let output = '' let err = '' @@ -71,7 +72,7 @@ async function getChangelog(headRef, baseRef, repoName, reverse) { await _exec( `${src}/changelog.sh`, - [headRef, baseRef, repoName, reverse], + [headRef, baseRef, repoName, reverse, fetch], options )