@plainconceptsplatform/workflows 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/workflow-catalog.d.ts +1 -1
  2. package/dist/workflow-catalog.js +0 -2
  3. package/loops/actions/add-issue-labels/action.yml +50 -50
  4. package/loops/actions/agent-output.cjs +17 -17
  5. package/loops/actions/apply-agent-bundle/action.yml +24 -24
  6. package/loops/actions/apply-agent-comments/action.yml +42 -42
  7. package/loops/actions/apply-agent-labels/action.yml +55 -55
  8. package/loops/actions/cleanup-artifacts/action.yml +91 -91
  9. package/loops/actions/close-agent-issues/action.yml +43 -43
  10. package/loops/actions/create-issue-comment/action.yml +29 -29
  11. package/loops/actions/download-agent-output/action.yml +53 -53
  12. package/loops/actions/link-pr-to-issue/action.yml +40 -40
  13. package/loops/actions/list-open-issues/action.yml +33 -33
  14. package/loops/actions/load-issue-context/action.yml +45 -45
  15. package/loops/actions/merge-agent-pr/action.yml +49 -49
  16. package/loops/actions/remove-issue-labels/action.yml +37 -37
  17. package/loops/actions/update-agent-issues/action.yml +58 -58
  18. package/loops/actions/validate-refine-output/validate-refine-output.sh +28 -4
  19. package/loops/actions/validate-review-output/action.yml +35 -35
  20. package/loops/actions/validate-review-output/validate-review-output.sh +4 -1
  21. package/loops/actions/validate-triage-output/action.yml +36 -36
  22. package/loops/actions/validate-triage-output/validate-triage-output.sh +5 -2
  23. package/loops/actions/verify-composite-actions/action.yml +9 -9
  24. package/loops/actions/verify-refine-output/action.yml +9 -9
  25. package/loops/actions/verify-refine-output/verify-refine-output.sh +14 -0
  26. package/loops/actions/verify-route-matrix/action.yml +9 -9
  27. package/loops/actions/verify-route-matrix/verify-route-matrix.sh +32 -46
  28. package/loops/templates/agentics/agentics-maintenance.yml +121 -121
  29. package/loops/templates/issues/bug_report.yml +109 -109
  30. package/loops/templates/issues/feature_request.yml +75 -75
  31. package/loops/workflows/agent-refine.md +43 -119
  32. package/loops/workflows/shared/platform-defaults.md +53 -53
  33. package/package.json +1 -1
  34. package/loops/actions/report-workflow-errors/action.yml +0 -538
  35. package/loops/actions/report-workflow-errors/report-policy.cjs +0 -194
  36. package/loops/templates/agentics/agentics-error-report.yml +0 -101
@@ -19,7 +19,7 @@ export interface MandatoryFile {
19
19
  }
20
20
  export declare const mandatoryFiles: readonly MandatoryFile[];
21
21
  export declare const generatedConsumerTargets: readonly [".github/workflows/agent-*.lock.yml", ".github/aw/actions-lock.json"];
22
- export declare const templateNames: readonly ["agentics-app-errors", "agentics-checks", "agentics-error-report", "agentics-maintenance", "app-ci-dotnet-next", "app-ci-node-monorepo", "bug-report", "dependabot-merge", "feature-request", "github-release", "opencode.ci.json", "platform-template", "quality-gates"];
22
+ export declare const templateNames: readonly ["agentics-app-errors", "agentics-checks", "agentics-maintenance", "app-ci-dotnet-next", "app-ci-node-monorepo", "bug-report", "dependabot-merge", "feature-request", "github-release", "opencode.ci.json", "platform-template", "quality-gates"];
23
23
  export type TemplateName = (typeof templateNames)[number];
24
24
  export interface CatalogTemplate {
25
25
  readonly name: TemplateName;
@@ -52,7 +52,6 @@ export const generatedConsumerTargets = [
52
52
  export const templateNames = [
53
53
  "agentics-app-errors",
54
54
  "agentics-checks",
55
- "agentics-error-report",
56
55
  "agentics-maintenance",
57
56
  "app-ci-dotnet-next",
58
57
  "app-ci-node-monorepo",
@@ -67,7 +66,6 @@ export const templateNames = [
67
66
  export const catalogTemplates = [
68
67
  { name: "agentics-app-errors", file: "agentics-app-errors.yml", description: "Daily application error report: asks Application Insights what the deployed app threw, groups it, and files one issue per distinct problem HERE, labelled bug + refine so the belt picks it up. Deterministic, no model; the report never leaves this repository, and a leak scanner withholds anything carrying an identifier." },
69
68
  { name: "agentics-checks", file: "agentics-checks.yml", description: "Agentics checks: verifies generated agent lockfiles, actionlint, and compile on PRs touching workflow files." },
70
- { name: "agentics-error-report", file: "agentics-error-report.yml", description: "Daily error report: classifies the last day of failures in the workflows this package ships and files them upstream so the package gets fixed. Deterministic, no model; sends only package-owned names, conclusions and counts, and refuses to file anything a leak scanner flags." },
71
69
  { name: "agentics-maintenance", file: "agentics-maintenance.yml", description: "Agentic maintenance: scheduled daily maintenance workflow for keeping workflows and actions up to date." },
72
70
  { name: "app-ci-dotnet-next", file: "app-ci-dotnet-next.yml", description: "App CI pipeline for a .NET + Next.js monorepo: build, test, and lint on PRs and schedule." },
73
71
  { name: "app-ci-node-monorepo", file: "app-ci-node-monorepo.yml", description: "App CI pipeline for a Node monorepo: build, test, and lint on PRs and schedule." },
@@ -1,50 +1,50 @@
1
- # Managed by @plainconceptsplatform/workflows. Source: loops/actions/add-issue-labels/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
- name: Add issue labels
3
- description: Add one or more labels to an issue or pull request.
4
- inputs:
5
- token:
6
- description: GitHub token used by github-script.
7
- required: true
8
- issue-number:
9
- description: Issue or pull request number.
10
- required: true
11
- labels:
12
- description: Labels to add, one per line. A comma-separated list is accepted as well.
13
- required: true
14
- runs:
15
- using: composite
16
- steps:
17
- - name: Add labels
18
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
19
- env:
20
- ISSUE_NUMBER: ${{ inputs.issue-number }}
21
- LABELS: ${{ inputs.labels }}
22
- with:
23
- github-token: ${{ inputs.token }}
24
- script: |
25
- const labels = process.env.LABELS.split(/\r?\n|,/).map((label) => label.trim()).filter(Boolean);
26
- if (labels.length === 0) {
27
- core.notice('No labels to add.');
28
- return;
29
- }
30
-
31
- // Create what does not exist yet, so shipping a new label in the package does not
32
- // require a person to go and make it in every repository first. Its sibling
33
- // remove-issue-labels has swallowed 404 for a long time; this one had no guard at all,
34
- // so a label the package introduced would fail the step in every consumer until
35
- // somebody created it by hand. 422 is "already exists", which is the happy path on
36
- // every run after the first.
37
- for (const name of labels) {
38
- try {
39
- await github.rest.issues.createLabel({ ...context.repo, name, color: 'ededed' });
40
- core.notice(`Created the ${name} label.`);
41
- } catch (error) {
42
- if (error.status !== 422) throw error;
43
- }
44
- }
45
-
46
- await github.rest.issues.addLabels({
47
- ...context.repo,
48
- issue_number: Number(process.env.ISSUE_NUMBER),
49
- labels,
50
- });
1
+ # Managed by @plainconceptsplatform/workflows. Source: loops/actions/add-issue-labels/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
+ name: Add issue labels
3
+ description: Add one or more labels to an issue or pull request.
4
+ inputs:
5
+ token:
6
+ description: GitHub token used by github-script.
7
+ required: true
8
+ issue-number:
9
+ description: Issue or pull request number.
10
+ required: true
11
+ labels:
12
+ description: Labels to add, one per line. A comma-separated list is accepted as well.
13
+ required: true
14
+ runs:
15
+ using: composite
16
+ steps:
17
+ - name: Add labels
18
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
19
+ env:
20
+ ISSUE_NUMBER: ${{ inputs.issue-number }}
21
+ LABELS: ${{ inputs.labels }}
22
+ with:
23
+ github-token: ${{ inputs.token }}
24
+ script: |
25
+ const labels = process.env.LABELS.split(/\r?\n|,/).map((label) => label.trim()).filter(Boolean);
26
+ if (labels.length === 0) {
27
+ core.notice('No labels to add.');
28
+ return;
29
+ }
30
+
31
+ // Create what does not exist yet, so shipping a new label in the package does not
32
+ // require a person to go and make it in every repository first. Its sibling
33
+ // remove-issue-labels has swallowed 404 for a long time; this one had no guard at all,
34
+ // so a label the package introduced would fail the step in every consumer until
35
+ // somebody created it by hand. 422 is "already exists", which is the happy path on
36
+ // every run after the first.
37
+ for (const name of labels) {
38
+ try {
39
+ await github.rest.issues.createLabel({ ...context.repo, name, color: 'ededed' });
40
+ core.notice(`Created the ${name} label.`);
41
+ } catch (error) {
42
+ if (error.status !== 422) throw error;
43
+ }
44
+ }
45
+
46
+ await github.rest.issues.addLabels({
47
+ ...context.repo,
48
+ issue_number: Number(process.env.ISSUE_NUMBER),
49
+ labels,
50
+ });
@@ -1,17 +1,17 @@
1
- // Managed by @plainconceptsplatform/workflows. Source: loops/actions/agent-output.cjs. Update with `workflows update --force`; consumer edits may be overwritten.
2
- const fs = require('node:fs');
3
-
4
- // Every apply-agent-* action reads the same artifact the same way: a missing file means the
5
- // agent produced nothing, which is a normal outcome rather than a failure.
6
- function readAgentItems(outputFile, type) {
7
- if (!outputFile || !fs.existsSync(outputFile)) {
8
- return [];
9
- }
10
-
11
- const parsed = JSON.parse(fs.readFileSync(outputFile, 'utf8'));
12
- const items = Array.isArray(parsed.items) ? parsed.items : [];
13
-
14
- return type ? items.filter((item) => item.type === type) : items;
15
- }
16
-
17
- module.exports = { readAgentItems };
1
+ // Managed by @plainconceptsplatform/workflows. Source: loops/actions/agent-output.cjs. Update with `workflows update --force`; consumer edits may be overwritten.
2
+ const fs = require('node:fs');
3
+
4
+ // Every apply-agent-* action reads the same artifact the same way: a missing file means the
5
+ // agent produced nothing, which is a normal outcome rather than a failure.
6
+ function readAgentItems(outputFile, type) {
7
+ if (!outputFile || !fs.existsSync(outputFile)) {
8
+ return [];
9
+ }
10
+
11
+ const parsed = JSON.parse(fs.readFileSync(outputFile, 'utf8'));
12
+ const items = Array.isArray(parsed.items) ? parsed.items : [];
13
+
14
+ return type ? items.filter((item) => item.type === type) : items;
15
+ }
16
+
17
+ module.exports = { readAgentItems };
@@ -1,24 +1,24 @@
1
- # Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-bundle/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
- name: Apply agent bundle
3
- description: Fast-forward an intended branch to the single commit exported by a verified git bundle.
4
- inputs:
5
- bundle-file:
6
- description: Path to the git bundle from the agent artifact.
7
- required: true
8
- target-branch:
9
- description: Branch that must fast-forward to the bundle commit.
10
- required: true
11
- base-branch:
12
- description: Existing branch used only when target-branch does not exist.
13
- required: false
14
- default: ''
15
- runs:
16
- using: composite
17
- steps:
18
- - name: Fast-forward branch from bundle
19
- shell: bash
20
- env:
21
- BUNDLE_FILE: ${{ inputs.bundle-file }}
22
- TARGET_BRANCH: ${{ inputs.target-branch }}
23
- BASE_BRANCH: ${{ inputs.base-branch }}
24
- run: bash "$GITHUB_ACTION_PATH/apply-bundle.sh" "$BUNDLE_FILE" "$TARGET_BRANCH" "$BASE_BRANCH"
1
+ # Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-bundle/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
+ name: Apply agent bundle
3
+ description: Fast-forward an intended branch to the single commit exported by a verified git bundle.
4
+ inputs:
5
+ bundle-file:
6
+ description: Path to the git bundle from the agent artifact.
7
+ required: true
8
+ target-branch:
9
+ description: Branch that must fast-forward to the bundle commit.
10
+ required: true
11
+ base-branch:
12
+ description: Existing branch used only when target-branch does not exist.
13
+ required: false
14
+ default: ''
15
+ runs:
16
+ using: composite
17
+ steps:
18
+ - name: Fast-forward branch from bundle
19
+ shell: bash
20
+ env:
21
+ BUNDLE_FILE: ${{ inputs.bundle-file }}
22
+ TARGET_BRANCH: ${{ inputs.target-branch }}
23
+ BASE_BRANCH: ${{ inputs.base-branch }}
24
+ run: bash "$GITHUB_ACTION_PATH/apply-bundle.sh" "$BUNDLE_FILE" "$TARGET_BRANCH" "$BASE_BRANCH"
@@ -1,42 +1,42 @@
1
- # Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-comments/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
- name: Apply agent comments
3
- description: Post every add_comment item from agent_output.json.
4
- inputs:
5
- output-file:
6
- description: Path to agent_output.json.
7
- required: true
8
- token:
9
- description: GitHub token with issues:write and pull-requests:write.
10
- required: true
11
- runs:
12
- using: composite
13
- steps:
14
- - name: Post comments
15
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
16
- env:
17
- AGENT_OUTPUT_LIB: ${{ github.action_path }}/../agent-output.cjs
18
- OUTPUT_FILE: ${{ inputs.output-file }}
19
- with:
20
- github-token: ${{ inputs.token }}
21
- script: |
22
- const { readAgentItems } = require(process.env.AGENT_OUTPUT_LIB);
23
- const items = readAgentItems(process.env.OUTPUT_FILE, 'add_comment');
24
-
25
- let posted = 0;
26
-
27
- for (const item of items) {
28
- if (!item.item_number) {
29
- core.warning(`add_comment item has no item_number, skipping: ${JSON.stringify(item)}`);
30
- continue;
31
- }
32
-
33
- await github.rest.issues.createComment({
34
- ...context.repo,
35
- issue_number: Number(item.item_number),
36
- body: item.body,
37
- });
38
-
39
- posted += 1;
40
- }
41
-
42
- core.info(`Posted ${posted} comment(s).`);
1
+ # Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-comments/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
+ name: Apply agent comments
3
+ description: Post every add_comment item from agent_output.json.
4
+ inputs:
5
+ output-file:
6
+ description: Path to agent_output.json.
7
+ required: true
8
+ token:
9
+ description: GitHub token with issues:write and pull-requests:write.
10
+ required: true
11
+ runs:
12
+ using: composite
13
+ steps:
14
+ - name: Post comments
15
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
16
+ env:
17
+ AGENT_OUTPUT_LIB: ${{ github.action_path }}/../agent-output.cjs
18
+ OUTPUT_FILE: ${{ inputs.output-file }}
19
+ with:
20
+ github-token: ${{ inputs.token }}
21
+ script: |
22
+ const { readAgentItems } = require(process.env.AGENT_OUTPUT_LIB);
23
+ const items = readAgentItems(process.env.OUTPUT_FILE, 'add_comment');
24
+
25
+ let posted = 0;
26
+
27
+ for (const item of items) {
28
+ if (!item.item_number) {
29
+ core.warning(`add_comment item has no item_number, skipping: ${JSON.stringify(item)}`);
30
+ continue;
31
+ }
32
+
33
+ await github.rest.issues.createComment({
34
+ ...context.repo,
35
+ issue_number: Number(item.item_number),
36
+ body: item.body,
37
+ });
38
+
39
+ posted += 1;
40
+ }
41
+
42
+ core.info(`Posted ${posted} comment(s).`);
@@ -1,55 +1,55 @@
1
- # Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-labels/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
- name: Apply agent labels
3
- description: Apply every add_labels and remove_labels item from agent_output.json.
4
- inputs:
5
- output-file:
6
- description: Path to agent_output.json.
7
- required: true
8
- token:
9
- description: GitHub token with issues:write.
10
- required: true
11
- runs:
12
- using: composite
13
- steps:
14
- - name: Apply label changes
15
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
16
- env:
17
- AGENT_OUTPUT_LIB: ${{ github.action_path }}/../agent-output.cjs
18
- OUTPUT_FILE: ${{ inputs.output-file }}
19
- with:
20
- github-token: ${{ inputs.token }}
21
- script: |
22
- const { readAgentItems } = require(process.env.AGENT_OUTPUT_LIB);
23
- const items = readAgentItems(process.env.OUTPUT_FILE)
24
- .filter((item) => item.type === 'add_labels' || item.type === 'remove_labels');
25
-
26
- let added = 0;
27
- let removed = 0;
28
-
29
- for (const item of items) {
30
- const labels = (item.labels ?? []).map((label) => label.name).filter(Boolean);
31
-
32
- if (!item.item_number || labels.length === 0) {
33
- core.warning(`${item.type} item is not actionable, skipping: ${JSON.stringify(item)}`);
34
- continue;
35
- }
36
-
37
- const issue_number = Number(item.item_number);
38
-
39
- if (item.type === 'add_labels') {
40
- await github.rest.issues.addLabels({ ...context.repo, issue_number, labels });
41
- added += labels.length;
42
- continue;
43
- }
44
-
45
- for (const name of labels) {
46
- try {
47
- await github.rest.issues.removeLabel({ ...context.repo, issue_number, name });
48
- removed += 1;
49
- } catch (error) {
50
- if (error.status !== 404) throw error;
51
- }
52
- }
53
- }
54
-
55
- core.info(`Added ${added} label(s), removed ${removed}.`);
1
+ # Managed by @plainconceptsplatform/workflows. Source: loops/actions/apply-agent-labels/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
+ name: Apply agent labels
3
+ description: Apply every add_labels and remove_labels item from agent_output.json.
4
+ inputs:
5
+ output-file:
6
+ description: Path to agent_output.json.
7
+ required: true
8
+ token:
9
+ description: GitHub token with issues:write.
10
+ required: true
11
+ runs:
12
+ using: composite
13
+ steps:
14
+ - name: Apply label changes
15
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
16
+ env:
17
+ AGENT_OUTPUT_LIB: ${{ github.action_path }}/../agent-output.cjs
18
+ OUTPUT_FILE: ${{ inputs.output-file }}
19
+ with:
20
+ github-token: ${{ inputs.token }}
21
+ script: |
22
+ const { readAgentItems } = require(process.env.AGENT_OUTPUT_LIB);
23
+ const items = readAgentItems(process.env.OUTPUT_FILE)
24
+ .filter((item) => item.type === 'add_labels' || item.type === 'remove_labels');
25
+
26
+ let added = 0;
27
+ let removed = 0;
28
+
29
+ for (const item of items) {
30
+ const labels = (item.labels ?? []).map((label) => label.name).filter(Boolean);
31
+
32
+ if (!item.item_number || labels.length === 0) {
33
+ core.warning(`${item.type} item is not actionable, skipping: ${JSON.stringify(item)}`);
34
+ continue;
35
+ }
36
+
37
+ const issue_number = Number(item.item_number);
38
+
39
+ if (item.type === 'add_labels') {
40
+ await github.rest.issues.addLabels({ ...context.repo, issue_number, labels });
41
+ added += labels.length;
42
+ continue;
43
+ }
44
+
45
+ for (const name of labels) {
46
+ try {
47
+ await github.rest.issues.removeLabel({ ...context.repo, issue_number, name });
48
+ removed += 1;
49
+ } catch (error) {
50
+ if (error.status !== 404) throw error;
51
+ }
52
+ }
53
+ }
54
+
55
+ core.info(`Added ${added} label(s), removed ${removed}.`);
@@ -1,91 +1,91 @@
1
- # Managed by @plainconceptsplatform/workflows. Source: loops/actions/cleanup-artifacts/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
- name: Clean up artifacts
3
- description: Delete workflow artifacts older than the configured retention period.
4
- inputs:
5
- token:
6
- description: GitHub token with actions write access.
7
- required: true
8
- artifact-retention-days:
9
- description: Retention period in days. Invalid or empty values use 3.
10
- required: false
11
- default: ''
12
- runs:
13
- using: composite
14
- steps:
15
- - name: Delete expired artifacts
16
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
17
- env:
18
- ARTIFACT_RETENTION_DAYS: ${{ inputs.artifact-retention-days }}
19
- with:
20
- github-token: ${{ inputs.token }}
21
- script: |
22
- const parsedDays = Number.parseInt(process.env.ARTIFACT_RETENTION_DAYS, 10);
23
- const days = Number.isInteger(parsedDays) && parsedDays > 0 ? parsedDays : 3;
24
- const cutoff = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
25
-
26
- core.info(`Retention: ${days} days (cutoff ${cutoff.toISOString()})`);
27
-
28
- const artifacts = await github.paginate(github.rest.actions.listArtifactsForRepo, {
29
- ...context.repo,
30
- per_page: 100,
31
- });
32
-
33
- const expired = artifacts.filter((artifact) => new Date(artifact.created_at) < cutoff);
34
-
35
- let deleted = 0;
36
- const failed = [];
37
-
38
- for (const artifact of expired) {
39
- // GitHub answers a delete with a 5xx now and then. Three tries, because the
40
- // alternative is a red daily run over one artifact that tomorrow's run would
41
- // have removed anyway.
42
- let lastError;
43
- for (let attempt = 1; attempt <= 3; attempt += 1) {
44
- try {
45
- await github.rest.actions.deleteArtifact({
46
- ...context.repo,
47
- artifact_id: artifact.id,
48
- });
49
-
50
- core.info(`Deleted ${artifact.name} (created ${artifact.created_at})`);
51
- deleted += 1;
52
- lastError = undefined;
53
- break;
54
- } catch (error) {
55
- lastError = error;
56
- if (attempt < 3) await new Promise((wait) => setTimeout(wait, attempt * 2000));
57
- }
58
- }
59
-
60
- if (lastError) {
61
- core.warning(
62
- `Could not delete ${artifact.name} (${artifact.id}) after 3 tries: ${lastError.message}`,
63
- );
64
- failed.push({ name: artifact.name, status: lastError.status });
65
- }
66
- }
67
-
68
- await core.summary
69
- .addHeading('Artifact cleanup', 2)
70
- .addList([
71
- `Retention: ${days} days (cutoff ${cutoff.toISOString()})`,
72
- `Deleted: ${deleted}`,
73
- `Failed to delete: ${failed.length}`,
74
- `Within retention: ${artifacts.length - expired.length}`,
75
- ])
76
- .write();
77
-
78
- // Deleting nothing at all while expired artifacts exist is a permission or
79
- // configuration problem, and has to be loud. One stubborn artifact among many is
80
- // the API having a bad minute: tomorrow's run picks it up, and failing here only
81
- // teaches people to ignore a red cleanup. A 4xx is never transient, so it fails
82
- // whatever else succeeded.
83
- const names = failed.map((entry) => entry.name).join(', ');
84
- const structural = failed.some((entry) => entry.status && entry.status < 500);
85
- if (failed.length > 0 && (deleted === 0 || structural)) {
86
- core.setFailed(`${failed.length} artifact(s) could not be deleted: ${names}`);
87
- } else if (failed.length > 0) {
88
- core.warning(
89
- `${failed.length} artifact(s) survived this run and will be retried tomorrow: ${names}`,
90
- );
91
- }
1
+ # Managed by @plainconceptsplatform/workflows. Source: loops/actions/cleanup-artifacts/action.yml. Update with workflows update --force; consumer edits may be overwritten.
2
+ name: Clean up artifacts
3
+ description: Delete workflow artifacts older than the configured retention period.
4
+ inputs:
5
+ token:
6
+ description: GitHub token with actions write access.
7
+ required: true
8
+ artifact-retention-days:
9
+ description: Retention period in days. Invalid or empty values use 3.
10
+ required: false
11
+ default: ''
12
+ runs:
13
+ using: composite
14
+ steps:
15
+ - name: Delete expired artifacts
16
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
17
+ env:
18
+ ARTIFACT_RETENTION_DAYS: ${{ inputs.artifact-retention-days }}
19
+ with:
20
+ github-token: ${{ inputs.token }}
21
+ script: |
22
+ const parsedDays = Number.parseInt(process.env.ARTIFACT_RETENTION_DAYS, 10);
23
+ const days = Number.isInteger(parsedDays) && parsedDays > 0 ? parsedDays : 3;
24
+ const cutoff = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
25
+
26
+ core.info(`Retention: ${days} days (cutoff ${cutoff.toISOString()})`);
27
+
28
+ const artifacts = await github.paginate(github.rest.actions.listArtifactsForRepo, {
29
+ ...context.repo,
30
+ per_page: 100,
31
+ });
32
+
33
+ const expired = artifacts.filter((artifact) => new Date(artifact.created_at) < cutoff);
34
+
35
+ let deleted = 0;
36
+ const failed = [];
37
+
38
+ for (const artifact of expired) {
39
+ // GitHub answers a delete with a 5xx now and then. Three tries, because the
40
+ // alternative is a red daily run over one artifact that tomorrow's run would
41
+ // have removed anyway.
42
+ let lastError;
43
+ for (let attempt = 1; attempt <= 3; attempt += 1) {
44
+ try {
45
+ await github.rest.actions.deleteArtifact({
46
+ ...context.repo,
47
+ artifact_id: artifact.id,
48
+ });
49
+
50
+ core.info(`Deleted ${artifact.name} (created ${artifact.created_at})`);
51
+ deleted += 1;
52
+ lastError = undefined;
53
+ break;
54
+ } catch (error) {
55
+ lastError = error;
56
+ if (attempt < 3) await new Promise((wait) => setTimeout(wait, attempt * 2000));
57
+ }
58
+ }
59
+
60
+ if (lastError) {
61
+ core.warning(
62
+ `Could not delete ${artifact.name} (${artifact.id}) after 3 tries: ${lastError.message}`,
63
+ );
64
+ failed.push({ name: artifact.name, status: lastError.status });
65
+ }
66
+ }
67
+
68
+ await core.summary
69
+ .addHeading('Artifact cleanup', 2)
70
+ .addList([
71
+ `Retention: ${days} days (cutoff ${cutoff.toISOString()})`,
72
+ `Deleted: ${deleted}`,
73
+ `Failed to delete: ${failed.length}`,
74
+ `Within retention: ${artifacts.length - expired.length}`,
75
+ ])
76
+ .write();
77
+
78
+ // Deleting nothing at all while expired artifacts exist is a permission or
79
+ // configuration problem, and has to be loud. One stubborn artifact among many is
80
+ // the API having a bad minute: tomorrow's run picks it up, and failing here only
81
+ // teaches people to ignore a red cleanup. A 4xx is never transient, so it fails
82
+ // whatever else succeeded.
83
+ const names = failed.map((entry) => entry.name).join(', ');
84
+ const structural = failed.some((entry) => entry.status && entry.status < 500);
85
+ if (failed.length > 0 && (deleted === 0 || structural)) {
86
+ core.setFailed(`${failed.length} artifact(s) could not be deleted: ${names}`);
87
+ } else if (failed.length > 0) {
88
+ core.warning(
89
+ `${failed.length} artifact(s) survived this run and will be retried tomorrow: ${names}`,
90
+ );
91
+ }