Skip to content

Commit 6745040

Browse files
authored
Merge pull request #188 from metcalfc/pr_183
Fix up PR 183. The broken test is because the action isn't deployed yet.
2 parents ead7f3a + afbb436 commit 6745040

File tree

8 files changed

+87
-19
lines changed

8 files changed

+87
-19
lines changed

.github/workflows/branchtest.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test branches with slash in name
2+
on: [push]
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
steps:
8+
# To use this repository's private action, you must check out the repository
9+
- uses: actions/checkout@v3
10+
with:
11+
fetch-depth: 0
12+
13+
- name: Generate changelog
14+
id: changelog
15+
uses: metcalfc/changelog-generator@main
16+
with:
17+
myToken: ${{ secrets.GITHUB_TOKEN }}
18+
head-ref: 'origin/test/branch' #add 'origin/` in front of your branch name
19+
base-ref: 'v1.0.0'
20+
fetch: false
21+
22+
- name: Get the changelog
23+
run: |
24+
cat << "EOF"
25+
${{ steps.changelog.outputs.changelog }}
26+
EOF
27+

.github/workflows/changelog.yml .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: test
1+
name: Test the changelog action
22
on: [push]
33

44
jobs:

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ The name of the head reference. Default `${{github.sha}}`.
2424

2525
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.*
2626

27+
### `reverse`
28+
29+
Whether the order of commits should be printed in reverse. Default: 'false'
30+
31+
### `fetch`
32+
33+
Whether this action should pull in all other branches and tags. Default: 'true'
34+
2735
## Outputs
2836

2937
### `changelog`
@@ -58,6 +66,25 @@ Or, if you have two specific references you want:
5866
base-ref: 'v0.0.1'
5967
```
6068
69+
If you want to point to a branch containing forward slashes (https://github.com/metcalfc/changelog-generator/issues/179) do the following:
70+
71+
```yaml
72+
73+
# let the checkout action do the fetching
74+
- uses: actions/checkout@v3
75+
with:
76+
fetch-depth: 0
77+
78+
- name: Generate changelog
79+
id: changelog
80+
uses: metcalfc/[email protected] #TODO: bump this after release
81+
with:
82+
myToken: ${{ secrets.GITHUB_TOKEN }}
83+
head-ref: 'origin/my/branch/with/slashes' #add 'origin/` in front of your branch name
84+
base-ref: 'v1.0.0'
85+
fetch: false
86+
```
87+
6188
### Second block
6289
6390
Then you can use the resulting changelog:

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ inputs:
1818
description: 'Git log is chronological order by default. Set to true to reverse chronological order. '
1919
default: 'false'
2020
required: false
21+
fetch:
22+
description: 'Whether to have this action fetch all other branches and tags'
23+
default: 'true'
24+
required: false
2125
outputs:
2226
changelog:
2327
description: 'Markdown formatted changelog'

changelog.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ if [ "$4" == "true" ]; then
1010
extra_flags='--reverse'
1111
fi
1212

13+
fetch=$5
14+
1315
# By default a GitHub action checkout is shallow. Get all the tags, branches,
1416
# and history. Redirect output to standard error which we can collect in the
1517
# action.
16-
git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2
17-
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2
18-
git fetch --prune --unshallow 1>&2
18+
if [ "$fetch" == "true" ]; then
19+
git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2
20+
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2
21+
git fetch --prune --unshallow 1>&2
22+
fi
1923

2024
# if folks don't have a base ref to compare against just use the initial
2125
# commit. This will show all the changes since the beginning but I can't
@@ -28,7 +32,7 @@ fi
2832
# Bash quoting will get you. Do not quote the extra_flags. If its null
2933
# we want it to disappear. If you quote it, it will go to git as an ""
3034
# and thats not a valid arg.
31-
log=$(git log "${base_ref}...${head_ref}" \
35+
log=$(git log "${base_ref}"..."${head_ref}" \
3236
--pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \
3337
${extra_flags})
3438

dist/changelog.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ if [ "$4" == "true" ]; then
1010
extra_flags='--reverse'
1111
fi
1212

13+
fetch=$5
14+
1315
# By default a GitHub action checkout is shallow. Get all the tags, branches,
1416
# and history. Redirect output to standard error which we can collect in the
1517
# action.
16-
git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2
17-
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2
18-
git fetch --prune --unshallow 1>&2
18+
if [ "$fetch" == "true" ]; then
19+
git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2
20+
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2
21+
git fetch --prune --unshallow 1>&2
22+
fi
1923

2024
# if folks don't have a base ref to compare against just use the initial
2125
# commit. This will show all the changes since the beginning but I can't
@@ -28,7 +32,7 @@ fi
2832
# Bash quoting will get you. Do not quote the extra_flags. If its null
2933
# we want it to disappear. If you quote it, it will go to git as an ""
3034
# and thats not a valid arg.
31-
log=$(git log "${base_ref}...${head_ref}" \
35+
log=$(git log "${base_ref}"..."${head_ref}" \
3236
--pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \
3337
${extra_flags})
3438

dist/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -11641,9 +11641,10 @@ async function run() {
1164111641
var baseRef = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('base-ref')
1164211642
const myToken = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('myToken')
1164311643
const reverse = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('reverse')
11644+
const fetch = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('fetch')
1164411645
const octokit = new _actions_github__WEBPACK_IMPORTED_MODULE_2__.getOctokit(myToken)
1164511646
const { owner, repo } = _actions_github__WEBPACK_IMPORTED_MODULE_2__.context.repo
11646-
const regexp = /^[.A-Za-z0-9_-]*$/
11647+
const regexp = /^[.A-Za-z0-9_/-]*$/
1164711648

1164811649
if (!headRef) {
1164911650
headRef = _actions_github__WEBPACK_IMPORTED_MODULE_2__.context.sha
@@ -11672,18 +11673,18 @@ async function run() {
1167211673
regexp.test(headRef) &&
1167311674
regexp.test(baseRef)
1167411675
) {
11675-
getChangelog(headRef, baseRef, owner + '/' + repo, reverse)
11676+
getChangelog(headRef, baseRef, owner + '/' + repo, reverse, fetch)
1167611677
} else {
1167711678
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed)(
11678-
'Branch names must contain only numbers, strings, underscores, periods, and dashes.'
11679+
'Branch names must contain only numbers, strings, underscores, periods, forward slashes, and dashes.'
1167911680
)
1168011681
}
1168111682
} catch (error) {
1168211683
(0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed)(error.message)
1168311684
}
1168411685
}
1168511686

11686-
async function getChangelog(headRef, baseRef, repoName, reverse) {
11687+
async function getChangelog(headRef, baseRef, repoName, reverse, fetch) {
1168711688
try {
1168811689
let output = ''
1168911690
let err = ''
@@ -11702,7 +11703,7 @@ async function getChangelog(headRef, baseRef, repoName, reverse) {
1170211703

1170311704
await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)(
1170411705
__nccwpck_require__.ab + "changelog.sh",
11705-
[headRef, baseRef, repoName, reverse],
11706+
[headRef, baseRef, repoName, reverse, fetch],
1170611707
options
1170711708
)
1170811709

index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ async function run() {
1010
var baseRef = getInput('base-ref')
1111
const myToken = getInput('myToken')
1212
const reverse = getInput('reverse')
13+
const fetch = getInput('fetch')
1314
const octokit = new getOctokit(myToken)
1415
const { owner, repo } = context.repo
15-
const regexp = /^[.A-Za-z0-9_-]*$/
16+
const regexp = /^[.A-Za-z0-9_/-]*$/
1617

1718
if (!headRef) {
1819
headRef = context.sha
@@ -41,18 +42,18 @@ async function run() {
4142
regexp.test(headRef) &&
4243
regexp.test(baseRef)
4344
) {
44-
getChangelog(headRef, baseRef, owner + '/' + repo, reverse)
45+
getChangelog(headRef, baseRef, owner + '/' + repo, reverse, fetch)
4546
} else {
4647
setFailed(
47-
'Branch names must contain only numbers, strings, underscores, periods, and dashes.'
48+
'Branch names must contain only numbers, strings, underscores, periods, forward slashes, and dashes.'
4849
)
4950
}
5051
} catch (error) {
5152
setFailed(error.message)
5253
}
5354
}
5455

55-
async function getChangelog(headRef, baseRef, repoName, reverse) {
56+
async function getChangelog(headRef, baseRef, repoName, reverse, fetch) {
5657
try {
5758
let output = ''
5859
let err = ''
@@ -71,7 +72,7 @@ async function getChangelog(headRef, baseRef, repoName, reverse) {
7172

7273
await _exec(
7374
`${src}/changelog.sh`,
74-
[headRef, baseRef, repoName, reverse],
75+
[headRef, baseRef, repoName, reverse, fetch],
7576
options
7677
)
7778

0 commit comments

Comments
 (0)