Skip to content

Commit eed95bd

Browse files
gomorizsoltactions-user
authored andcommitted
Update distified version
1 parent 9fa79d7 commit eed95bd

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

dist/index.js

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -506,16 +506,28 @@ const yn = __webpack_require__(300);
506506

507507
const devEnv = process.env.NODE_ENV === "dev";
508508

509+
const inputKeys = {
510+
AGE: devEnv ? "AGE" : "age",
511+
SKIP_TAGS: devEnv ? "SKIP_TAGS" : "skip-tags",
512+
SKIP_RECENT: devEnv ? "SKIP_RECENT" : "skip-recent",
513+
};
514+
509515
if (devEnv) {
510516
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
511517
__webpack_require__(245).config();
512518
}
513519

520+
function readInput(key, isRequired = false) {
521+
if (devEnv) {
522+
return process.env[key];
523+
}
524+
525+
return core.getInput(key, { required: isRequired });
526+
}
527+
514528
function getConfigs() {
515529
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
516-
const [age, units] = devEnv
517-
? process.env.AGE.split(" ")
518-
: core.getInput("age", { required: true }).split(" ");
530+
const [age, units] = readInput(inputKeys.AGE, true).split(" ");
519531
const maxAge = moment().subtract(age, units);
520532

521533
console.log(
@@ -527,6 +539,16 @@ function getConfigs() {
527539
")"
528540
);
529541

542+
const skipRecent = readInput(inputKeys.SKIP_RECENT);
543+
544+
if (skipRecent) {
545+
const parsedRecent = Number(skipRecent);
546+
547+
if (Number.isNaN(parsedRecent)) {
548+
throw new Error("skip-recent option must be type of number.");
549+
}
550+
}
551+
530552
return {
531553
repo: {
532554
owner,
@@ -536,9 +558,8 @@ function getConfigs() {
536558
perPage: 100,
537559
},
538560
maxAge: moment().subtract(age, units),
539-
skipTags: devEnv
540-
? yn(process.env.SKIP_TAGS)
541-
: yn(core.getInput("skip-tags")),
561+
skipTags: yn(readInput(inputKeys.SKIP_TAGS)),
562+
skipRecent: Number(skipRecent),
542563
retriesEnabled: true,
543564
};
544565
}
@@ -601,6 +622,8 @@ async function run() {
601622
}
602623
);
603624

625+
let skippedArtifactsCounter = 0;
626+
604627
return octokit
605628
.paginate(workflowRunsRequest, ({ data }, done) => {
606629
const stopPagination = data.find(workflowRun => {
@@ -618,10 +641,10 @@ async function run() {
618641
.then(workflowRuns => {
619642
const artifactPromises = workflowRuns
620643
.filter(workflowRun => {
621-
const skipWorkflow =
644+
const skipTaggedWorkflow =
622645
configs.skipTags && taggedCommits.includes(workflowRun.head_sha);
623646

624-
if (skipWorkflow) {
647+
if (skipTaggedWorkflow) {
625648
console.log(`Skipping tagged run ${workflowRun.head_sha}`);
626649

627650
return false;
@@ -641,6 +664,20 @@ async function run() {
641664
return octokit.paginate(workflowRunArtifactsRequest).then(artifacts =>
642665
artifacts
643666
.filter(artifact => {
667+
const skipRecentArtifact =
668+
configs.skipRecent &&
669+
configs.skipRecent > skippedArtifactsCounter;
670+
671+
if (skipRecentArtifact) {
672+
console.log(
673+
`Skipping recent artifact (id: ${artifact.id}, name: ${artifact.name}).`
674+
);
675+
676+
skippedArtifactsCounter += 1;
677+
678+
return false;
679+
}
680+
644681
const createdAt = moment(artifact.created_at);
645682

646683
return createdAt.isBefore(configs.maxAge);
@@ -649,7 +686,7 @@ async function run() {
649686
if (devEnv) {
650687
return new Promise(resolve => {
651688
console.log(
652-
`Recognized development environment, preventing ${artifact.id} from being removed.`
689+
`Recognized development environment, preventing artifact (id: ${artifact.id}, name: ${artifact.name}) from being removed.`
653690
);
654691

655692
resolve();
@@ -663,7 +700,7 @@ async function run() {
663700
})
664701
.then(() => {
665702
console.log(
666-
`Successfully removed artifact with id ${artifact.id}.`
703+
`Successfully removed artifact (id: ${artifact.id}, name: ${artifact.name}).`
667704
);
668705
});
669706
})

0 commit comments

Comments
 (0)