Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job summary #60

Merged
merged 2 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion 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,12 +96,14 @@ 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`);
}

core.setOutput('count', prunedList.length);
core.setOutput('prunedVersionIds', prunedList);
core.setOutput('prunedVersionIds', prunedList.map((version) => version.id));
core.setOutput('dryRun', dryRun);
} catch (error) {
core.setFailed(error.message);
Expand Down
2 changes: 1 addition & 1 deletion src/pruning.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const prune = (pruneVersion) => async (pruningList) => {
for (const version of pruningList) {
core.info(`Pruning version #${version.id} named '${version.name}'...`);
await pruneVersion(version);
pruned.push(version.id);
pruned.push(version);
}

core.endGroup();
Expand Down
4 changes: 2 additions & 2 deletions src/pruning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('prune', () => {

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

expect(pruned).toEqual([100001, 100000]);
expect(pruned).toEqual(pruningList);
expect(pruneVersion).toHaveBeenCalledTimes(2);
expect(pruneVersion).nthCalledWith(1, pruningList[0]);
expect(pruneVersion).nthCalledWith(2, pruningList[1]);
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('prune', () => {

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

expect(pruned).toEqual([100000]);
expect(pruned).toEqual([pruningList[0]]);
expect(pruneVersion).toHaveBeenCalledTimes(2);
expect(pruneVersion).nthCalledWith(1, pruningList[0]);
expect(pruneVersion).nthCalledWith(2, pruningList[1]);
Expand Down