Skip to content

Commit d18ab16

Browse files
authored
Merge pull request #1182 from mikepenz/feature/export_cache
Enable cache via `exportCache` configuration option
2 parents 5c949cd + f0cbee5 commit d18ab16

File tree

9 files changed

+63
-34
lines changed

9 files changed

+63
-34
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ jobs:
131131
fromTag: "v8.1.0"
132132
toTag: "v8.1.6"
133133
token: ${{ secrets.PERSONAL_TOKEN }}
134+
exportCache: true
134135
exportOnly: true
135136

136137
- name: "External Repo Configuration"

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,20 +588,22 @@ it('Test custom changelog builder', async () => {
588588
'release-changelog-builder-action-playground', // repo
589589
'1.5.0', // fromTag
590590
'2.0.0', // toTag
591-
true, // includeOpen
591+
false, // includeOpen
592592
false, // failOnError
593593
false, // ignorePrePrelease
594-
true, // enable to fetch reviewers
594+
false, // enable to fetch via commits
595+
false, // enable to fetch reviewers
595596
false, // enable to fetch release information
596597
false, // enable to fetch reviews
597-
false, // commitMode
598+
false, // enable commitMode
599+
false, // enable exportCache
598600
false, // enable exportOnly
599601
configuration // configuration
600602
)
601603

602604
const changeLog = await releaseNotesBuilder.build()
603605
console.log(changeLog)
604-
expect(changeLog).toStrictEqual(``)
606+
expect(changeLog).toStrictEqual(`define-expected-output`)
605607
})
606608
```
607609

__tests__/releaseNotesBuilder.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ it('Should match generated changelog (unspecified fromTag)', async () => {
2121
false, // enable to fetch tag release information
2222
false, // enable to fetch reviews
2323
false, // enable commitMode
24+
false, // enable exportCache
2425
false, // enable exportOnly
2526
configuration
2627
)
@@ -53,6 +54,7 @@ it('Should match generated changelog (unspecified tags)', async () => {
5354
false, // enable to fetch tag release information
5455
false, // enable to fetch reviews
5556
false, // enable commitMode
57+
false, // enable exportCache
5658
false, // enable exportOnly
5759
configuration
5860
)
@@ -80,6 +82,7 @@ it('Should use empty placeholder', async () => {
8082
false, // enable to fetch tag release information
8183
false, // enable to fetch reviews
8284
false, // enable commitMode
85+
false, // enable exportCache
8386
false, // enable exportOnly
8487
configuration
8588
)
@@ -107,6 +110,7 @@ it('Should fill empty placeholders', async () => {
107110
false, // enable to fetch tag release information
108111
false, // enable to fetch reviews
109112
false, // enable commitMode
113+
false, // enable exportCache
110114
false, // enable exportOnly
111115
configuration
112116
)
@@ -136,6 +140,7 @@ it('Should fill `template` placeholders', async () => {
136140
false, // enable to fetch tag release information
137141
false, // enable to fetch reviews
138142
false, // enable commitMode
143+
false, // enable exportCache
139144
false, // enable exportOnly
140145
configuration
141146
)
@@ -166,6 +171,7 @@ it('Should fill `template` placeholders, ignore', async () => {
166171
false, // enable to fetch tag release information
167172
false, // enable to fetch reviews
168173
false, // enable commitMode
174+
false, // enable exportCache
169175
false, // enable exportOnly
170176
configuration
171177
)
@@ -195,6 +201,7 @@ it('Uncategorized category', async () => {
195201
false, // enable to fetch tag release information
196202
false, // enable to fetch reviews
197203
false, // enable commitMode
204+
false, // enable exportCache
198205
false, // enable exportOnly
199206
configuration
200207
)
@@ -224,6 +231,7 @@ it('Verify commit based changelog', async () => {
224231
false, // enable to fetch tag release information
225232
false, // enable to fetch reviews
226233
true, // enable commitMode
234+
false, // enable exportCache
227235
false, // enable exportOnly
228236
configuration
229237
)
@@ -253,6 +261,7 @@ it('Verify commit based changelog, with emoji categorisation', async () => {
253261
false, // enable to fetch tag release information
254262
false, // enable to fetch reviews
255263
true, // enable commitMode
264+
false, // enable exportCache
256265
false, // enable exportOnly
257266
configuration
258267
)
@@ -282,6 +291,7 @@ it('Verify default inclusion of open PRs', async () => {
282291
false, // enable to fetch tag release information
283292
false, // enable to fetch reviews
284293
false, // enable commitMode
294+
false, // enable exportCache
285295
false, // enable exportOnly
286296
configuration // configuration
287297
)
@@ -311,6 +321,7 @@ it('Verify custom categorisation of open PRs', async () => {
311321
false, // enable to fetch tag release information
312322
false, // enable to fetch reviews
313323
false, // enable commitMode
324+
false, // enable exportCache
314325
false, // enable exportOnly
315326
configuration // configuration
316327
)
@@ -340,6 +351,7 @@ it('Verify reviewers who approved are fetched and also release information', asy
340351
true, // enable to fetch tag release information
341352
false, // enable to fetch reviews
342353
false, // enable commitMode
354+
false, // enable exportCache
343355
false, // enable exportOnly
344356
configuration // configuration
345357
)
@@ -370,6 +382,7 @@ it('Fetch release information', async () => {
370382
true, // enable to fetch tag release information
371383
false, // enable to fetch reviews
372384
false, // enable commitMode
385+
false, // enable exportCache
373386
false, // enable exportOnly
374387
configuration // configuration
375388
)
@@ -398,6 +411,7 @@ it('Fetch release information for non existing tag / release', async () => {
398411
true, // enable to fetch tag release information
399412
false, // enable to fetch reviews
400413
false, // enable commitMode
414+
false, // enable exportCache
401415
false, // enable exportOnly
402416
configuration // configuration
403417
)

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ inputs:
4343
commitMode:
4444
description: 'Enables a `light` commit based mode. This mode generates changelogs based on the commits. Please note that this is not officially supported, and lacks a lot of features only possible with PRs.'
4545
default: "false"
46+
exportCache:
47+
description: 'If enabled, the action will export the collected data to the cache. This is disabled by default. Can be passed to a follow up run via `cache`.'
48+
default: "false"
4649
exportOnly:
47-
description: 'If enabled, the action will only collect the data and terminate afterwards. Data can then be consumed by steps afterwards'
50+
description: 'If enabled, the action will only collect the data and terminate afterwards. Data can then be consumed by steps afterwards. This requires `exportCache` to be enabled'
4851
default: "false"
4952
outputFile:
5053
description: 'If defined, the changelog will get written to this file. (relative to the checkout dir)'
@@ -54,7 +57,7 @@ inputs:
5457
baseUrl:
5558
description: 'Defines the base url for GitHub Enterprise authentication, uses `https://api.github.com` by default'
5659
cache:
57-
description: 'Provide the cache of a previous run. Allows to re-use collected information multiple times to generate different release notes.'
60+
description: 'Provide the cache of a previous run. Allows to re-use collected information multiple times to generate different release notes. Requires `exportCache` to be enabled for the previous run.'
5861
outputs:
5962
changelog:
6063
description: The built release changelog built from the merged pull requests

dist/index.js

Lines changed: 18 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async function run(): Promise<void> {
5555
const fetchReleaseInformation = core.getInput('fetchReleaseInformation') === 'true'
5656
const fetchReviews = core.getInput('fetchReviews') === 'true'
5757
const commitMode = core.getInput('commitMode') === 'true'
58+
const exportCache = core.getInput('exportCache') === 'true'
5859
const exportOnly = core.getInput('exportOnly') === 'true'
5960

6061
const result = await new ReleaseNotesBuilder(
@@ -73,6 +74,7 @@ async function run(): Promise<void> {
7374
fetchReleaseInformation,
7475
fetchReviews,
7576
commitMode,
77+
exportCache,
7678
exportOnly,
7779
configuration
7880
).build()

src/releaseNotesBuilder.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class ReleaseNotesBuilder {
4545
private fetchReleaseInformation: boolean = false,
4646
private fetchReviews: boolean = false,
4747
private commitMode: boolean = false,
48+
private exportCache: boolean = false,
4849
private exportOnly: boolean = false,
4950
private configuration: Configuration
5051
) {}
@@ -107,18 +108,20 @@ export class ReleaseNotesBuilder {
107108
const diffInfo = prData.diffInfo
108109
this.setOutputs(options, diffInfo, mergedPullRequests)
109110

110-
const cache = {
111-
mergedPullRequests,
112-
diffInfo,
113-
options
114-
}
115-
core.setOutput(`cache`, JSON.stringify(cache))
116-
//fs.writeFileSync(path.resolve('cache.json'), JSON.stringify(cache))
117-
118-
if (this.exportOnly) {
119-
core.info(`ℹ️ Enabled 'exportOnly' will not generate changelog`)
120-
core.endGroup()
121-
return null
111+
if (this.exportCache) {
112+
const cache = {
113+
mergedPullRequests,
114+
diffInfo,
115+
options
116+
}
117+
core.setOutput(`cache`, JSON.stringify(cache))
118+
//fs.writeFileSync(path.resolve('cache.json'), JSON.stringify(cache))
119+
120+
if (this.exportOnly) {
121+
core.info(`ℹ️ Enabled 'exportOnly' will not generate changelog`)
122+
core.endGroup()
123+
return null
124+
}
122125
}
123126

124127
return buildChangelog(diffInfo, mergedPullRequests, options)

src/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o
251251
}
252252
}
253253

254-
// note the `exclude label` configuration of categories will not apply to the legacy "UNCATEGORIZED" placeholder
254+
// note the `exclude label` configuration of categories will not apply to the legacy "UNCATEGORIZED" placeholder
255255
uncategorizedPrs.push(body)
256256
} else {
257257
categorizedPrs.push(body)

0 commit comments

Comments
 (0)