Skip to content

Commit 1369502

Browse files
committed
feat: enable publishing latest release
1 parent f811fda commit 1369502

File tree

7 files changed

+171
-38
lines changed

7 files changed

+171
-38
lines changed

.github/workflows/draft-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ on: [workflow_dispatch, push]
44

55
jobs:
66
call-workflow:
7-
uses: tomasbjerre/.github/.github/workflows/draft-release.yaml@master
7+
uses: tomasbjerre/.github/.github/workflows/draft-release.yaml@master
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Publish release on tag push
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
push:
7+
tags:
8+
- '*'
9+
10+
jobs:
11+
call-workflow:
12+
uses: tomasbjerre/.github/.github/workflows/publish-release-on-tag-push.yaml@master

README.md

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ that can draft release in GitHub generated from template using
1515

1616
[<img src="git-changelog-github-release-draft.png" width="500" />](git-changelog-github-release-draft.png)
1717

18-
19-
## Usage
18+
## Draft releases
2019

2120
- Create a file, perhaps `.github/workflows/draft-release.yaml`, with content:
2221

@@ -43,11 +42,15 @@ jobs:
4342
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needs write permission in Github menu '/settings/actions'
4443
```
4544
46-
Running example [in this repo](.github/workflows/draft-release.yaml) and it references [re-usable workflow](https://github.com/tomasbjerre/.github/blob/master/.github/workflows/draft-release.yaml).
45+
Running example [in this repo](.github/workflows/draft-release.yaml) and it
46+
references
47+
[re-usable workflow](https://github.com/tomasbjerre/.github/blob/master/.github/workflows/draft-release.yaml).
4748
48-
## Triggering release when publishing draft
49+
### Triggering release when publishing draft
4950
50-
You may want to have GitHub trigger a workflow when drafted release is published. Perhaps to build it and upload a release. Perhaps something like this:
51+
You may want to have GitHub trigger a workflow when drafted release is
52+
published. Perhaps to build it and upload a release. Perhaps something like
53+
this:
5154
5255
```yaml
5356
name: Release
@@ -67,5 +70,45 @@ jobs:
6770
NEW_VERSION=$(echo "${GITHUB_REF}" | cut -d "/" -f3)
6871
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
6972
- name: Publish
70-
run: echo Whatever command to release version ${{ steps.new_version.outputs.new_version }}
73+
run:
74+
echo Whatever command to release version ${{
75+
steps.new_version.outputs.new_version }}
76+
```
77+
78+
## Publish releases when tags pushed
79+
80+
If you already have some other way of releasing, you may want to just publish
81+
those releases.
82+
83+
This will render the release content with the difference between the last 2
84+
tags.
85+
86+
```yaml
87+
name: Publish release on tag push
88+
89+
on:
90+
workflow_dispatch:
91+
workflow_call:
92+
push:
93+
tags:
94+
- '*'
95+
96+
jobs:
97+
build:
98+
runs-on: 'ubuntu-latest'
99+
permissions:
100+
contents: write
101+
steps:
102+
- uses: actions/checkout@v4
103+
with:
104+
fetch-tags: 'true'
105+
fetch-depth: '0'
106+
- name: Setup java
107+
uses: actions/setup-java@v2
108+
with:
109+
distribution: 'zulu'
110+
java-version: 17
111+
- uses: tomasbjerre/git-changelog-github-release@main
112+
with:
113+
draft: false
71114
```

action.yml

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ inputs:
1212
required: true
1313
description: 'If it should be a draft in GitHub or an actual release'
1414
default: 'true'
15-
template:
15+
templateDraft:
1616
description: |
17-
Rendered and used as description. See https://github.com/tomasbjerre/git-changelog-lib for documentation.
17+
Used when draft is true.
18+
Unreleased changes rendered and used as description.
19+
See https://github.com/tomasbjerre/git-changelog-lib for documentation.
1820
required: false
1921
default: |
2022
{{#tags}}
@@ -68,6 +70,62 @@ inputs:
6870
{{/ifContainsType}}
6971
{{/ifEquals}}
7072
{{/tags}}
73+
templateLatestRelease:
74+
description: |
75+
Used when draft is false
76+
Difference between 2 latest tags rendered and used as description.
77+
See https://github.com/tomasbjerre/git-changelog-lib for documentation.
78+
required: false
79+
default: |
80+
{{#with tags.[0]}}
81+
{{#ifContainsBreaking commits}}
82+
# 💣 Breaking changes
83+
84+
{{#commits}}
85+
{{#ifCommitBreaking .}}
86+
- {{#eachCommitScope .}} **{{.}}** {{/eachCommitScope}} {{{commitDescription .}}} ([{{subString hash 0 5}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}}) {{#eachCommitRefs .}}{{#ifMatches . "^#[0-9]+"}} [{{.}}](https://github.com/{{ownerName}}/{{repoName}}/issues/{{subString . 1}}) {{/ifMatches}}{{/eachCommitRefs}} {{#eachCommitFixes .}}{{#ifMatches . "^#[0-9]+"}} [{{.}}](https://github.com/{{ownerName}}/{{repoName}}/issues/{{subString . 1}}) {{/ifMatches}}{{/eachCommitFixes}}
87+
{{/ifCommitBreaking}}
88+
{{/commits}}
89+
90+
{{/ifContainsBreaking}}
91+
{{#ifContainsType commits type='feat'}}
92+
# 🚀 Features
93+
94+
{{#commits}}
95+
{{#ifCommitType . type='feat'}}
96+
- {{#eachCommitScope .}} **{{.}}** {{/eachCommitScope}} {{{commitDescription .}}} ([{{subString hash 0 5}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}}) {{#eachCommitRefs .}}{{#ifMatches . "^#[0-9]+"}} [{{.}}](https://github.com/{{ownerName}}/{{repoName}}/issues/{{subString . 1}}) {{/ifMatches}}{{/eachCommitRefs}} {{#eachCommitFixes .}}{{#ifMatches . "^#[0-9]+"}} [{{.}}](https://github.com/{{ownerName}}/{{repoName}}/issues/{{subString . 1}}) {{/ifMatches}}{{/eachCommitFixes}}
97+
{{/ifCommitType}}
98+
{{/commits}}
99+
100+
{{/ifContainsType}}
101+
{{#ifContainsType commits type='fix'}}
102+
# 🐛 Bug Fixes
103+
104+
{{#commits}}
105+
{{#ifCommitType . type='fix'}}
106+
- {{#eachCommitScope .}} **{{.}}** {{/eachCommitScope}} {{{commitDescription .}}} ([{{subString hash 0 5}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}}) {{#eachCommitRefs .}}{{#ifMatches . "^#[0-9]+"}} [{{.}}](https://github.com/{{ownerName}}/{{repoName}}/issues/{{subString . 1}}) {{/ifMatches}}{{/eachCommitRefs}} {{#eachCommitFixes .}}{{#ifMatches . "^#[0-9]+"}} [{{.}}](https://github.com/{{ownerName}}/{{repoName}}/issues/{{subString . 1}}) {{/ifMatches}}{{/eachCommitFixes}}
107+
{{/ifCommitType}}
108+
{{/commits}}
109+
110+
{{/ifContainsType}}
111+
{{#ifContainsType commits type='^($|(?!fix|feat|breaking))'}}
112+
# 🧰 Other changes
113+
114+
{{#commits}}
115+
{{#ifCommitType . type='^$'}}
116+
**{{{messageTitle}}}**
117+
118+
{{#messageBodyItems}}
119+
* {{.}}
120+
{{/messageBodyItems}}
121+
122+
[{{subString hash 0 5}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}} *{{commitTime}}*
123+
124+
{{/ifCommitType}}
125+
{{/commits}}
126+
127+
{{/ifContainsType}}
128+
{{/with}}
71129
outputs:
72130
id:
73131
description: Of created release

dist/index.js

Lines changed: 22 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function gitChangelogCommandLine(userArgs: string[]) {
1212
console.log(`stderr: ${stderr}`)
1313
console.log(`status: ${status}`)
1414
if (!status) {
15-
return stdout
15+
return stdout.trim()
1616
}
1717
throw Error(
1818
`Error (${status}) from git-changelog-command-line:\n\n${userArgs}\n\n${stderr}\n\n`
@@ -35,31 +35,37 @@ export async function run(): Promise<void> {
3535
*/
3636
const draft = core.getInput('draft', { required: false }) === 'true'
3737

38-
const template = core.getInput('template')
38+
const template = draft
39+
? core.getInput('templateDraft')
40+
: core.getInput('templateLatestRelease')
3941
console.log(`Using template:\n\n${template}\n\n`)
4042

4143
/**
4244
* Gather details on release
4345
*/
4446
const highestVersion = gitChangelogCommandLine(['--print-highest-version'])
45-
console.log(`highestVersion: ${highestVersion}`)
47+
console.log(`highestVersion: '${highestVersion}'`)
4648

4749
const highestVersionTag = gitChangelogCommandLine([
4850
'--print-highest-version-tag'
4951
])
50-
console.log(`highestVersionTag: ${highestVersionTag}`)
52+
console.log(`highestVersionTag: '${highestVersionTag}'`)
5153

5254
let currentVersion = gitChangelogCommandLine([
5355
'--patch-version-pattern',
5456
'^fix.*',
5557
'--print-current-version'
5658
])
57-
console.log(`Rendered currentVersion:\n\n${currentVersion}\n\n`)
59+
console.log(`Rendered currentVersion: '${currentVersion}'`)
5860

5961
if (highestVersionTag) {
6062
if (currentVersion === highestVersion) {
61-
console.log(`No changes made that can be released`)
62-
return
63+
if (draft) {
64+
console.log(
65+
`No changes made that can be released, skipping since draft is ${draft}`
66+
)
67+
return
68+
}
6369
} else {
6470
console.log(
6571
`Changes detected and a new ${currentVersion} release can be made`
@@ -72,12 +78,18 @@ export async function run(): Promise<void> {
7278
currentVersion = '0.0.1'
7379
}
7480

75-
const description = gitChangelogCommandLine([
76-
'-std',
77-
'--template-content',
78-
template
79-
])
80-
console.log(`Rendered description:\n\n${description}\n\n`)
81+
let description = draft
82+
? gitChangelogCommandLine(['-std', '--template-content', template])
83+
: gitChangelogCommandLine([
84+
'-std',
85+
'--to-revision',
86+
currentVersion,
87+
'--template-content',
88+
template
89+
])
90+
console.log(
91+
`Rendered '${currentVersion}' description:\n\n${description}\n\n`
92+
)
8193

8294
/**
8395
* Remove any previous draft
@@ -109,7 +121,7 @@ export async function run(): Promise<void> {
109121
owner,
110122
repo,
111123
tag_name: currentVersion,
112-
name: currentVersion,
124+
name: `v${currentVersion}`,
113125
body: description,
114126
draft,
115127
prerelease: false,

0 commit comments

Comments
 (0)