Skip to content

Commit

Permalink
Add support for Action Job Summaries (#421)
Browse files Browse the repository at this point in the history
* Add support for Action Job Summaries
  • Loading branch information
rfennell authored May 19, 2022
1 parent bf07221 commit fad2e5c
Show file tree
Hide file tree
Showing 527 changed files with 8,371 additions and 78,241 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:
templateFile: '${{ github.workspace }}/__tests__/template.md'
outputfile: '${{ github.workspace }}/__tests__/releasenotes.md'
extensionsfile: '${{ github.workspace }}/__tests__/customextensions.js'
writeToJobSummary: true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This Action uses the GitHub API and a [Handlebars](https://handlebarsjs.com/) ba
templateFile: '${{ github.workspace }}//template.md'
outputfile: '${{ github.workspace }}//releasenotes.md'
extensionsFile: '${{ github.workspace }}//customextensions.js'
writeToJobSummary: true
```
## Parameters
Expand All @@ -23,6 +24,7 @@ As well as the `GITHUB_TOKEN` the action also takes the following parameters
* templateFile: The path to the Handlebar template file. (Required)
* outputFile: The path for the file that will be created. (Required)
* extensionsFile: The path to the an optional module of custom Handlebars functions. (Optional)
* writeToJobSummary: If true the output will be written to the [Action Job Summary](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/) as well as generating a file.

## Template File
The template allows you to create your own document layout using [Handlebars](https://handlebarsjs.com/) syntax. A template written in this format is as follows
Expand Down
4 changes: 3 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Create Release Notes', () => {
core.getInput.mockReturnValueOnce('templateFile')
core.getInput.mockReturnValueOnce('outFile')
core.getInput.mockReturnValueOnce('extensions')
core.getBooleanInput.mockReturnValueOnce(false)
})

test('Can create release notes', async () => {
Expand All @@ -37,7 +38,8 @@ describe('Create Release Notes', () => {
123,
'templateFile',
'outFile',
'extensions'
'extensions',
false
)
})

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
required: false
description: 'The path to the an optional module of custom Handlebars functions'
default: ''
writeToJobSummary:
required: false
description: 'If true the output will be written to the Job Summary'
default: 'false'
runs:
using: 'node12'
main: 'lib/main.js'
Expand Down
15 changes: 13 additions & 2 deletions lib/generate-releasenotes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down Expand Up @@ -31,12 +35,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.generate = void 0;
const core = __importStar(require("@actions/core"));
const fs = __importStar(require("fs"));
function generate(octokit, owner, repo, run_id, templateFile, outputFile, extensionsFile) {
function generate(octokit, owner, repo, run_id, templateFile, outputFile, extensionsFile, writeToJobSummary) {
return __awaiter(this, void 0, void 0, function* () {
try {
core.info(`Getting the details of the workflow run ${run_id} from repo ${owner}/${repo}`);
core.info(`Template File: ${templateFile}`);
core.info(`Output File: ${outputFile}`);
core.info(`WriteToJobSummary: ${writeToJobSummary}`);
core.info(`Owner: ${owner}`);
core.info(`Repo: ${repo}`);
if (fs.existsSync(templateFile)) {
Expand All @@ -51,6 +56,12 @@ function generate(octokit, owner, repo, run_id, templateFile, outputFile, extens
core.debug(JSON.stringify(output));
core.debug(`---THE OUTPUT OBJECT END---`);
fs.writeFileSync(outputFile, output);
if (writeToJobSummary) {
core.info(`Adding output to the Job Summary`);
yield core.summary
.addRaw(output)
.write();
}
}
else {
core.setFailed(`Cannot find template file ${templateFile}`);
Expand Down
8 changes: 6 additions & 2 deletions lib/localrun.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down Expand Up @@ -56,7 +60,7 @@ function run() {
console.log(` --outputfile: ${outputfile}`);
console.log(` --extensionsFile: ${extensionsFile}`);
const octokit = github.getOctokit(pat);
yield releaseNotesModule.generate(octokit, owner, repo, runid, templatefile, outputfile, extensionsFile);
yield releaseNotesModule.generate(octokit, owner, repo, runid, templatefile, outputfile, extensionsFile, false);
}
}
catch (err) {
Expand Down
9 changes: 7 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down Expand Up @@ -47,10 +51,11 @@ function run() {
const templateFile = core.getInput('templateFile');
const outputFile = core.getInput('outputFile');
const extensionsFile = core.getInput('extensionsFile');
const writeToJobSummary = core.getBooleanInput('writeToJobSummary');
// overrides to allow local testing
const repo = repository.name;
const owner = repository.owner.login;
yield releaseNotesModule.generate(octokit, owner, repo, GITHUB_RUN_ID, templateFile, outputFile, extensionsFile);
yield releaseNotesModule.generate(octokit, owner, repo, GITHUB_RUN_ID, templateFile, outputFile, extensionsFile, writeToJobSummary);
resolve(0);
}));
return promise;
Expand Down
144 changes: 74 additions & 70 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions node_modules/@actions/core/lib/core.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions node_modules/@actions/core/lib/core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fad2e5c

Please sign in to comment.