-
Notifications
You must be signed in to change notification settings - Fork 54
106 lines (92 loc) · 3.88 KB
/
clean-up-artifacts.yml
File metadata and controls
106 lines (92 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: cleanup-artifacts
on:
push:
paths-ignore:
- '**/README.md'
pull_request:
types:
- closed
paths-ignore:
- '**/README.md'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: write
env:
TARGET: "vs"
ARCH: arm64
NO_FORCE: 1
VS_VER: 17
GA_CI_SECRET: ${{ secrets.CI_SECRET }}
GH_TOKEN: ${{ secrets.CI_SECRET }}
USE_ARTIFACT: true
jobs:
pre-check:
runs-on: ubuntu-latest
steps:
- name: Log old artifacts for potential deletion
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding')
uses: actions/github-script@v7.0.1
env:
GH_TOKEN: ${{ secrets.CI_SECRET }}
REPO: ${{ github.repository }}
GA_CI_SECRET: ${{ secrets.CI_SECRET }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
with:
script: |
console.log(`Token: ${process.env.GH_TOKEN ? "Present" : "Missing"}`);
console.log(`GA_CI_SECRET: ${process.env.GA_CI_SECRET ? "Present" : "Missing"}`);
const artifacts = await github.rest.actions.listArtifactsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
console.log(artifacts);
const keepLatestArtifacts = artifacts.data.artifacts
.filter(artifact => !artifact.expired)
.reduce((acc, artifact) => {
const nameParts = artifact.name.split('-');
const release = nameParts[1];
const platform = nameParts[2]; // e.g., ios, macos, catos, xros, tvos
const arch = nameParts[3]; // e.g., arm64, x86_64, etc.
const bundle = nameParts[4]; // e.g., 1, 2, 3
const type = `${release}-${platform}-${arch}-${bundle}`;
if (!acc[type] || acc[type].created_at < artifact.created_at) {
acc[type] = artifact;
}
return acc;
}, {});
for (const artifact of artifacts.data.artifacts) {
const nameParts = artifact.name.split('-');
const release = nameParts[1];
const platform = nameParts[2];
const arch = nameParts[3];
const bundle = nameParts[4];
const type = `${release}-${platform}-${arch}-${bundle}`;
if (!artifact.expired && keepLatestArtifacts[type].id !== artifact.id) {
console.log(`DISABLED - WOULD delete older artifact: ${artifact.name} (${artifact.created_at} | ${artifact.size_in_bytes} bytes)`);
// Uncomment the next lines to actually delete old artifacts
/*
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});
*/
console.log(`Deleted older artifact: ${artifact.name} (${artifact.created_at} | ${artifact.size_in_bytes} bytes)`);
} else if (/^v\d+/i.test(release)) {
console.log(`DISABLED - WOULD: Deleting artifact with "v*" in release: ${artifact.name} (${artifact.created_at} | ${artifact.size_in_bytes} bytes)`);
// Uncomment to enable artifact deletion
/*
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});
*/
console.log(`Deleted artifact with "v*": ${artifact.name}`);
} else {
console.log(`Keeping artifact: ${artifact.name} (${artifact.created_at} | ${artifact.size_in_bytes} bytes)`);
}
}