Skip to content

Commit

Permalink
Add job summary
Browse files Browse the repository at this point in the history
Resolves #52

Build a job summary which lists all versions which were pruned. This acts as an exhaustive summary of the action effects.
  • Loading branch information
vlaurin committed Oct 23, 2022
1 parent 6835473 commit ac0c75d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ const dryRunDelete = (version) => new Promise((resolve) => {
resolve();
});

const writeSummary = async (container, dryRun, pruningVersions, prunedVersions) => {
const allPruned = pruningVersions.length === prunedVersions.length;

let summary = core.summary.addHeading(`Pruning versions for container: ${container}`, 2);

if (dryRun) {
summary = summary.addRaw(':warning: This is a dry run, no container versions were actually deleted.')
.addBreak();
} else {
summary = summary.addRaw(`${allPruned ? ':white_check_mark:' : ':x:'} ${prunedVersions.length} out of ${pruningVersions.length} identified versions were pruned successfully.`);
}

await summary.addHeading('Pruned versions', 3)
.addRaw(`The following ${prunedVersions.length} versions were successfully pruned:`)
.addTable([
[{data: 'ID', header: true}, {data: 'Name', header: true}, {data: 'Created at', header: true}, {data: 'Tags', header: true}],
...prunedVersions.map((version) => ([
`[${String(version.id)}](${version.html_url})`,
version.name,
version.created_at.replace('T', ' '),
version.metadata.container.tags.join(', '),
])),
])
.write();
};

const run = async () => {
try {
const token = core.getInput('token');
Expand Down Expand Up @@ -71,6 +97,8 @@ const run = async () => {

const prunedList = await prune(pruneVersion)(pruningList);

await writeSummary(container, dryRun, pruningList, prunedList);

if (prunedList.length !== pruningList.length) {
core.setFailed(`Failed to prune some versions: ${prunedList.length} out of ${pruningList.length} versions were pruned`);
}
Expand Down

0 comments on commit ac0c75d

Please sign in to comment.