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 d8b8d40
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ 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.');
} 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.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 +96,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 d8b8d40

Please sign in to comment.