Skip to content

Commit 1e2b03a

Browse files
gomorizsoltactions-user
authored andcommitted
Update distified version
1 parent 8e17b98 commit 1e2b03a

File tree

1 file changed

+77
-55
lines changed

1 file changed

+77
-55
lines changed

dist/index.js

Lines changed: 77 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,13 @@ function getConfigs() {
528528
);
529529

530530
return {
531-
repoOptions: {
531+
repo: {
532532
owner,
533533
repo,
534534
},
535+
pagination: {
536+
perPage: 100,
537+
},
535538
maxAge: moment().subtract(age, units),
536539
skipTags: devEnv
537540
? yn(process.env.SKIP_TAGS)
@@ -569,7 +572,8 @@ async function run() {
569572

570573
async function getTaggedCommits() {
571574
const listTagsRequest = octokit.repos.listTags.endpoint.merge({
572-
...configs.repoOptions,
575+
...configs.repo,
576+
per_page: configs.pagination.perPage,
573577
ref: "tags",
574578
});
575579

@@ -591,67 +595,85 @@ async function run() {
591595
}
592596

593597
const workflowRunsRequest = octokit.actions.listRepoWorkflowRuns.endpoint.merge(
594-
configs.repoOptions
598+
{
599+
...configs.repo,
600+
per_page: configs.pagination.perPage,
601+
}
595602
);
596603

597-
return octokit.paginate(workflowRunsRequest).then(workflowRuns => {
598-
const artifactPromises = workflowRuns
599-
.filter(workflowRun => {
600-
const skipWorkflow =
601-
configs.skipTags && taggedCommits.includes(workflowRun.head_sha);
604+
return octokit
605+
.paginate(workflowRunsRequest, ({ data }, done) => {
606+
const stopPagination = data.find(workflowRun => {
607+
const createdAt = moment(workflowRun.created_at);
602608

603-
if (skipWorkflow) {
604-
console.log(`Skipping tagged run ${workflowRun.head_sha}`);
609+
return createdAt.isBefore(moment.utc().subtract(90, "days"));
610+
});
605611

606-
return false;
607-
}
612+
if (stopPagination) {
613+
done();
614+
}
608615

609-
return true;
610-
})
611-
.map(workflowRun => {
612-
const workflowRunArtifactsRequest = octokit.actions.listWorkflowRunArtifacts.endpoint.merge(
613-
{
614-
...configs.repoOptions,
615-
run_id: workflowRun.id,
616+
return data;
617+
})
618+
.then(workflowRuns => {
619+
const artifactPromises = workflowRuns
620+
.filter(workflowRun => {
621+
const skipWorkflow =
622+
configs.skipTags && taggedCommits.includes(workflowRun.head_sha);
623+
624+
if (skipWorkflow) {
625+
console.log(`Skipping tagged run ${workflowRun.head_sha}`);
626+
627+
return false;
616628
}
617-
);
618629

619-
return octokit.paginate(workflowRunArtifactsRequest).then(artifacts =>
620-
artifacts
621-
.filter(artifact => {
622-
const createdAt = moment(artifact.created_at);
623-
624-
return createdAt.isBefore(configs.maxAge);
625-
})
626-
.map(artifact => {
627-
if (devEnv) {
628-
return new Promise(resolve => {
629-
console.log(
630-
`Recognized development environment, preventing ${artifact.id} from being removed.`
631-
);
632-
633-
resolve();
634-
});
635-
}
636-
637-
return octokit.actions
638-
.deleteArtifact({
639-
...configs.repoOptions,
640-
artifact_id: artifact.id,
641-
})
642-
.then(() => {
643-
console.log(
644-
`Successfully removed artifact with id ${artifact.id}.`
645-
);
646-
});
647-
})
648-
);
649-
});
630+
return true;
631+
})
632+
.map(workflowRun => {
633+
const workflowRunArtifactsRequest = octokit.actions.listWorkflowRunArtifacts.endpoint.merge(
634+
{
635+
...configs.repo,
636+
per_page: configs.pagination.perPage,
637+
run_id: workflowRun.id,
638+
}
639+
);
640+
641+
return octokit.paginate(workflowRunArtifactsRequest).then(artifacts =>
642+
artifacts
643+
.filter(artifact => {
644+
const createdAt = moment(artifact.created_at);
645+
646+
return createdAt.isBefore(configs.maxAge);
647+
})
648+
.map(artifact => {
649+
if (devEnv) {
650+
return new Promise(resolve => {
651+
console.log(
652+
`Recognized development environment, preventing ${artifact.id} from being removed.`
653+
);
654+
655+
resolve();
656+
});
657+
}
650658

651-
return Promise.all(artifactPromises).then(artifactDeletePromises =>
652-
Promise.all([].concat(...artifactDeletePromises))
653-
);
654-
});
659+
return octokit.actions
660+
.deleteArtifact({
661+
...configs.repo,
662+
artifact_id: artifact.id,
663+
})
664+
.then(() => {
665+
console.log(
666+
`Successfully removed artifact with id ${artifact.id}.`
667+
);
668+
});
669+
})
670+
);
671+
});
672+
673+
return Promise.all(artifactPromises).then(artifactDeletePromises =>
674+
Promise.all([].concat(...artifactDeletePromises))
675+
);
676+
});
655677
}
656678

657679
run().catch(err => {

0 commit comments

Comments
 (0)