- replace ENV variable output with normal output (requires re-passing)

- update README
This commit is contained in:
Mike Penz
2023-06-04 10:20:31 +00:00
committed by GitHub
parent 91da901770
commit 5dd6b400c7
8 changed files with 54 additions and 82 deletions
+6 -1
View File
@@ -24,6 +24,10 @@ jobs:
- name: Install NPM - name: Install NPM
run: | run: |
cd pr-collector
npm run all
cd ..
npm install npm install
- name: Run NPM - name: Run NPM
@@ -127,7 +131,6 @@ jobs:
fromTag: "v8.1.0" fromTag: "v8.1.0"
toTag: "v8.1.6" toTag: "v8.1.6"
token: ${{ secrets.PERSONAL_TOKEN }} token: ${{ secrets.PERSONAL_TOKEN }}
exportCollected: true
exportOnly: true exportOnly: true
- name: "External Repo Configuration" - name: "External Repo Configuration"
@@ -137,6 +140,7 @@ jobs:
configuration: "configs/configuration_complex.json" configuration: "configs/configuration_complex.json"
owner: "mikepenz" owner: "mikepenz"
repo: "MaterialDrawer" repo: "MaterialDrawer"
cache: ${{ steps.external_changelog_collect.outputs.cache }}
- name: "External Repo Configuration Second" - name: "External Repo Configuration Second"
id: external_changelog_second id: external_changelog_second
@@ -155,6 +159,7 @@ jobs:
} }
owner: "mikepenz" owner: "mikepenz"
repo: "MaterialDrawer" repo: "MaterialDrawer"
cache: ${{ steps.external_changelog_collect.outputs.cache }}
- name: Echo External Repo Configuration Changelog - name: Echo External Repo Configuration Changelog
env: env:
+2
View File
@@ -91,6 +91,7 @@ A full set list of possible output values for this action.
| `outputs.changes` | Total count of changes in this release (lines). | | `outputs.changes` | Total count of changes in this release (lines). |
| `outputs.commits` | Count of commits which have been added in this release. | | `outputs.commits` | Count of commits which have been added in this release. |
| `outputs.categorized` | The categorized pull requests used to build the changelog as serialized JSON. | | `outputs.categorized` | The categorized pull requests used to build the changelog as serialized JSON. |
| `outputs.cache` | The cache for the current fetched data. Can be provided to another action step. |
## Full Sample 🖥️ ## Full Sample 🖥️
@@ -330,6 +331,7 @@ For advanced use cases additional settings can be provided to the action
| `fetchReleaseInformation` | Will enable fetching additional release information from tags. Default: false | | `fetchReleaseInformation` | Will enable fetching additional release information from tags. Default: false |
| `fetchReviews` | Will enable fetching the reviews on of the PR. Default: false | | `fetchReviews` | Will enable fetching the reviews on of the PR. Default: false |
| `commitMode` | Special configuration for projects which work without PRs. Uses commit messages as changelog. This mode looses access to information only available for PRs. Default: false | | `commitMode` | Special configuration for projects which work without PRs. Uses commit messages as changelog. This mode looses access to information only available for PRs. Default: false |
| `cache` | Cached data from a previous run. Will skip fetching PR information |
> **Warning**: `${{ secrets.GITHUB_TOKEN }}` only grants rights to the current repository, for other repositories please use a PAT (Personal Access Token). > **Warning**: `${{ secrets.GITHUB_TOKEN }}` only grants rights to the current repository, for other repositories please use a PAT (Personal Access Token).
+4 -3
View File
@@ -40,9 +40,6 @@ inputs:
commitMode: commitMode:
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.' 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.'
default: "false" default: "false"
exportCollected:
description: 'Enables the export of all collected PR information to an environment variable'
default: "false"
exportOnly: exportOnly:
description: 'If enabled, the action will only collect the data and terminate afterwards. Data can then be consumed by steps afterwards' description: 'If enabled, the action will only collect the data and terminate afterwards. Data can then be consumed by steps afterwards'
default: "false" default: "false"
@@ -53,6 +50,8 @@ inputs:
default: ${{ github.token }} default: ${{ github.token }}
baseUrl: baseUrl:
description: 'Defines the base url for GitHub Enterprise authentication, uses `https://api.github.com` by default' description: 'Defines the base url for GitHub Enterprise authentication, uses `https://api.github.com` by default'
cache:
description: 'Provide the cache of a previous run. Allows to re-use collected information multiple times to generate different release notes.'
outputs: outputs:
changelog: changelog:
description: The built release changelog built from the merged pull requests description: The built release changelog built from the merged pull requests
@@ -74,6 +73,8 @@ outputs:
description: Count of uncategorized pull requests description: Count of uncategorized pull requests
open_prs: open_prs:
description: Count of open pull requests. Only fetched if `includeOpen` is enabled. description: Count of open pull requests. Only fetched if `includeOpen` is enabled.
cache:
description: 'Cache containing this runs data. Allows to re-use collected information multiple times to generate different release notes.'
runs: runs:
using: 'node16' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'
Generated Vendored
+20 -38
View File
@@ -141,9 +141,8 @@ function run() {
const fetchReleaseInformation = core.getInput('fetchReleaseInformation') === 'true'; const fetchReleaseInformation = core.getInput('fetchReleaseInformation') === 'true';
const fetchReviews = core.getInput('fetchReviews') === 'true'; const fetchReviews = core.getInput('fetchReviews') === 'true';
const commitMode = core.getInput('commitMode') === 'true'; const commitMode = core.getInput('commitMode') === 'true';
const exportCollected = core.getInput('exportCollected') === 'true';
const exportOnly = core.getInput('exportOnly') === 'true'; const exportOnly = core.getInput('exportOnly') === 'true';
const result = yield new releaseNotesBuilder_1.ReleaseNotesBuilder(baseUrl, token, repositoryPath, owner, repo, fromTag, toTag, includeOpen, failOnError, ignorePreReleases, fetchReviewers, fetchReleaseInformation, fetchReviews, commitMode, exportCollected, exportOnly, configuration).build(); const result = yield new releaseNotesBuilder_1.ReleaseNotesBuilder(baseUrl, token, repositoryPath, owner, repo, fromTag, toTag, includeOpen, failOnError, ignorePreReleases, fetchReviewers, fetchReleaseInformation, fetchReviews, commitMode, exportOnly, configuration).build();
core.setOutput('changelog', result); core.setOutput('changelog', result);
// write the result in changelog to file if possible // write the result in changelog to file if possible
const outputFile = core.getInput('outputFile'); const outputFile = core.getInput('outputFile');
@@ -279,7 +278,7 @@ const transform_1 = __nccwpck_require__(1644);
const github_pr_collector_1 = __nccwpck_require__(3196); const github_pr_collector_1 = __nccwpck_require__(3196);
const utils_2 = __nccwpck_require__(853); const utils_2 = __nccwpck_require__(853);
class ReleaseNotesBuilder { class ReleaseNotesBuilder {
constructor(baseUrl, token, repositoryPath, owner, repo, fromTag, toTag, includeOpen = false, failOnError, ignorePreReleases, fetchReviewers = false, fetchReleaseInformation = false, fetchReviews = false, commitMode = false, exportCollected = false, exportOnly = false, configuration) { constructor(baseUrl, token, repositoryPath, owner, repo, fromTag, toTag, includeOpen = false, failOnError, ignorePreReleases, fetchReviewers = false, fetchReleaseInformation = false, fetchReviews = false, commitMode = false, exportOnly = false, configuration) {
this.baseUrl = baseUrl; this.baseUrl = baseUrl;
this.token = token; this.token = token;
this.repositoryPath = repositoryPath; this.repositoryPath = repositoryPath;
@@ -294,13 +293,12 @@ class ReleaseNotesBuilder {
this.fetchReleaseInformation = fetchReleaseInformation; this.fetchReleaseInformation = fetchReleaseInformation;
this.fetchReviews = fetchReviews; this.fetchReviews = fetchReviews;
this.commitMode = commitMode; this.commitMode = commitMode;
this.exportCollected = exportCollected;
this.exportOnly = exportOnly; this.exportOnly = exportOnly;
this.configuration = configuration; this.configuration = configuration;
} }
build() { build() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let releaseNotesData = (0, utils_1.checkExportedData)(); const releaseNotesData = (0, utils_1.checkExportedData)();
if (releaseNotesData == null) { if (releaseNotesData == null) {
if (!this.owner) { if (!this.owner) {
(0, utils_2.failOrError)(`💥 Missing or couldn't resolve 'owner'`, this.failOnError); (0, utils_2.failOrError)(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
@@ -349,27 +347,22 @@ class ReleaseNotesBuilder {
core.setOutput('deletions', diffInfo.deletions); core.setOutput('deletions', diffInfo.deletions);
core.setOutput('changes', diffInfo.changes); core.setOutput('changes', diffInfo.changes);
core.setOutput('commits', diffInfo.commits); core.setOutput('commits', diffInfo.commits);
if (this.exportCollected) { const cache = {
core.info('📦 Exporting collected data');
core.exportVariable(`RCBA_EXPORT_diffInfo`, JSON.stringify(diffInfo));
//fs.writeFileSync(path.resolve('diffInfo.json'), JSON.stringify(diffInfo))
core.exportVariable(`RCBA_EXPORT_mergedPullRequests`, JSON.stringify(mergedPullRequests));
//fs.writeFileSync(path.resolve('mergedPullRequests.json'), JSON.stringify(mergedPullRequests))
core.exportVariable(`RCBA_EXPORT_options`, JSON.stringify(options));
//fs.writeFileSync(path.resolve('options.json'), JSON.stringify(options))
if (this.exportOnly) {
core.endGroup();
return null;
}
}
releaseNotesData = {
mergedPullRequests, mergedPullRequests,
diffInfo, diffInfo,
options options
}; };
core.setOutput(`cache`, JSON.stringify(cache));
//fs.writeFileSync(path.resolve('cache.json'), JSON.stringify(cache))
if (this.exportOnly) {
core.info(`️ Enabled 'exportOnly' will not generate changelog`);
core.endGroup();
return null;
}
return (0, transform_1.buildChangelog)(diffInfo, mergedPullRequests, options);
} }
else { else {
core.info(`️ Retrieved previously exported collected data`); core.info(`️ Retrieved previously cache data`);
// merge input with options (in case some data was updated) // merge input with options (in case some data was updated)
const diffInfo = releaseNotesData.diffInfo; const diffInfo = releaseNotesData.diffInfo;
const mergedPullRequests = releaseNotesData.mergedPullRequests; const mergedPullRequests = releaseNotesData.mergedPullRequests;
@@ -397,17 +390,7 @@ class ReleaseNotesBuilder {
commitMode: this.commitMode || orgOptions.commitMode, commitMode: this.commitMode || orgOptions.commitMode,
configuration: this.configuration || orgOptions.configuration configuration: this.configuration || orgOptions.configuration
}; };
releaseNotesData = { return (0, transform_1.buildChangelog)(diffInfo, mergedPullRequests, options);
diffInfo,
mergedPullRequests,
options
};
}
if (releaseNotesData != null) {
return (0, transform_1.buildChangelog)(releaseNotesData.diffInfo, releaseNotesData.mergedPullRequests, releaseNotesData.options);
}
else {
return null;
} }
}); });
} }
@@ -951,12 +934,11 @@ exports.retrieveRepositoryPath = retrieveRepositoryPath;
* If available, return a [ReleaseNotesData]. * If available, return a [ReleaseNotesData].
*/ */
function checkExportedData() { function checkExportedData() {
const rawDiffInfo = process.env[`RCBA_EXPORT_diffInfo`]; const rawCache = core.getInput(`cache`);
const rawMergedPullRequests = process.env[`RCBA_EXPORT_mergedPullRequests`]; if (rawCache) {
const rawOptions = process.env[`RCBA_EXPORT_options`]; const cache = JSON.parse(rawCache);
if (rawDiffInfo && rawMergedPullRequests && rawOptions) { const diffInfo = cache.diffInfo;
const diffInfo = JSON.parse(rawDiffInfo); const mergedPullRequests = cache.mergedPullRequests;
const mergedPullRequests = JSON.parse(rawMergedPullRequests);
for (const pr of mergedPullRequests) { for (const pr of mergedPullRequests) {
pr.createdAt = (0, moment_1.default)(pr.createdAt); pr.createdAt = (0, moment_1.default)(pr.createdAt);
if (pr.mergedAt) { if (pr.mergedAt) {
@@ -970,7 +952,7 @@ function checkExportedData() {
} }
} }
} }
const options = JSON.parse(rawOptions); const options = cache.options;
return { return {
diffInfo, diffInfo,
mergedPullRequests, mergedPullRequests,
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
-2
View File
@@ -54,7 +54,6 @@ async function run(): Promise<void> {
const fetchReleaseInformation = core.getInput('fetchReleaseInformation') === 'true' const fetchReleaseInformation = core.getInput('fetchReleaseInformation') === 'true'
const fetchReviews = core.getInput('fetchReviews') === 'true' const fetchReviews = core.getInput('fetchReviews') === 'true'
const commitMode = core.getInput('commitMode') === 'true' const commitMode = core.getInput('commitMode') === 'true'
const exportCollected = core.getInput('exportCollected') === 'true'
const exportOnly = core.getInput('exportOnly') === 'true' const exportOnly = core.getInput('exportOnly') === 'true'
const result = await new ReleaseNotesBuilder( const result = await new ReleaseNotesBuilder(
@@ -72,7 +71,6 @@ async function run(): Promise<void> {
fetchReleaseInformation, fetchReleaseInformation,
fetchReviews, fetchReviews,
commitMode, commitMode,
exportCollected,
exportOnly, exportOnly,
configuration configuration
).build() ).build()
+15 -30
View File
@@ -27,6 +27,7 @@ export interface Data {
mergedPullRequests: PullRequestInfo[] mergedPullRequests: PullRequestInfo[]
options: ReleaseNotesOptions options: ReleaseNotesOptions
} }
export class ReleaseNotesBuilder { export class ReleaseNotesBuilder {
constructor( constructor(
private baseUrl: string | null, private baseUrl: string | null,
@@ -43,13 +44,12 @@ export class ReleaseNotesBuilder {
private fetchReleaseInformation: boolean = false, private fetchReleaseInformation: boolean = false,
private fetchReviews: boolean = false, private fetchReviews: boolean = false,
private commitMode: boolean = false, private commitMode: boolean = false,
private exportCollected: boolean = false,
private exportOnly: boolean = false, private exportOnly: boolean = false,
private configuration: Configuration private configuration: Configuration
) {} ) {}
async build(): Promise<string | null> { async build(): Promise<string | null> {
let releaseNotesData = checkExportedData() const releaseNotesData = checkExportedData()
if (releaseNotesData == null) { if (releaseNotesData == null) {
if (!this.owner) { if (!this.owner) {
failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError) failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError)
@@ -121,28 +121,23 @@ export class ReleaseNotesBuilder {
core.setOutput('changes', diffInfo.changes) core.setOutput('changes', diffInfo.changes)
core.setOutput('commits', diffInfo.commits) core.setOutput('commits', diffInfo.commits)
if (this.exportCollected) { const cache = {
core.info('📦 Exporting collected data')
core.exportVariable(`RCBA_EXPORT_diffInfo`, JSON.stringify(diffInfo))
//fs.writeFileSync(path.resolve('diffInfo.json'), JSON.stringify(diffInfo))
core.exportVariable(`RCBA_EXPORT_mergedPullRequests`, JSON.stringify(mergedPullRequests))
//fs.writeFileSync(path.resolve('mergedPullRequests.json'), JSON.stringify(mergedPullRequests))
core.exportVariable(`RCBA_EXPORT_options`, JSON.stringify(options))
//fs.writeFileSync(path.resolve('options.json'), JSON.stringify(options))
if (this.exportOnly) {
core.endGroup()
return null
}
}
releaseNotesData = {
mergedPullRequests, mergedPullRequests,
diffInfo, diffInfo,
options options
} }
core.setOutput(`cache`, JSON.stringify(cache))
//fs.writeFileSync(path.resolve('cache.json'), JSON.stringify(cache))
if (this.exportOnly) {
core.info(`️ Enabled 'exportOnly' will not generate changelog`)
core.endGroup()
return null
}
return buildChangelog(diffInfo, mergedPullRequests, options)
} else { } else {
core.info(`️ Retrieved previously exported collected data`) core.info(`️ Retrieved previously cache data`)
// merge input with options (in case some data was updated) // merge input with options (in case some data was updated)
const diffInfo = releaseNotesData.diffInfo const diffInfo = releaseNotesData.diffInfo
@@ -173,17 +168,7 @@ export class ReleaseNotesBuilder {
commitMode: this.commitMode || orgOptions.commitMode, commitMode: this.commitMode || orgOptions.commitMode,
configuration: this.configuration || orgOptions.configuration configuration: this.configuration || orgOptions.configuration
} }
return buildChangelog(diffInfo, mergedPullRequests, options)
releaseNotesData = {
diffInfo,
mergedPullRequests,
options
}
}
if (releaseNotesData != null) {
return buildChangelog(releaseNotesData.diffInfo, releaseNotesData.mergedPullRequests, releaseNotesData.options)
} else {
return null
} }
} }
} }
+6 -7
View File
@@ -28,13 +28,12 @@ export function retrieveRepositoryPath(providedPath: string): string {
* If available, return a [ReleaseNotesData]. * If available, return a [ReleaseNotesData].
*/ */
export function checkExportedData(): Data | null { export function checkExportedData(): Data | null {
const rawDiffInfo = process.env[`RCBA_EXPORT_diffInfo`] const rawCache = core.getInput(`cache`)
const rawMergedPullRequests = process.env[`RCBA_EXPORT_mergedPullRequests`]
const rawOptions = process.env[`RCBA_EXPORT_options`]
if (rawDiffInfo && rawMergedPullRequests && rawOptions) { if (rawCache) {
const diffInfo: DiffInfo = JSON.parse(rawDiffInfo) const cache: Data = JSON.parse(rawCache)
const mergedPullRequests: PullRequestInfo[] = JSON.parse(rawMergedPullRequests) const diffInfo: DiffInfo = cache.diffInfo
const mergedPullRequests: PullRequestInfo[] = cache.mergedPullRequests
for (const pr of mergedPullRequests) { for (const pr of mergedPullRequests) {
pr.createdAt = moment(pr.createdAt) pr.createdAt = moment(pr.createdAt)
@@ -51,7 +50,7 @@ export function checkExportedData(): Data | null {
} }
} }
const options: ReleaseNotesOptions = JSON.parse(rawOptions) const options: ReleaseNotesOptions = cache.options
return { return {
diffInfo, diffInfo,
mergedPullRequests, mergedPullRequests,