Apothecary fixes (#433) #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: cleanup artifact caches keep latest | |
on: | |
push: | |
paths-ignore: | |
- '**/README.md' | |
pull_request: | |
paths-ignore: | |
- '**/README.md' | |
# on: | |
# pull_request: | |
# types: | |
# - closed | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
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: | |
cleanup-artifacts: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
bundle: [1,2] | |
defaults: | |
run: | |
shell: msys2 {0} | |
steps: | |
- name: Log old artifacts for potential deletion | |
if: github.repository == 'openframeworks/apothecary' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/bleeding') | |
uses: actions/[email protected] | |
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 // Get up to 100 artifacts | |
}); | |
console.log(artifacts); | |
const keepLatestArtifacts = artifacts.data.artifacts | |
.filter(artifact => !artifact.expired) | |
.reduce((acc, artifact) => { | |
const nameParts = artifact.name.split('-'); | |
const platform = nameParts[1]; // e.g., ios, macos, catos, xros, tvos | |
const arch = nameParts[2]; // e.g., arm64, x86_64, etc. | |
const bundle = nameParts[3]; // e.g., 1, 2, 3 | |
const type = `${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 platform = nameParts[1]; | |
const arch = nameParts[2]; | |
const bundle = nameParts[3]; | |
const type = `${platform}-${arch}-${bundle}`; | |
if (!artifact.expired && keepLatestArtifacts[type].id !== artifact.id) { | |
console.log(`Would delete older artifact: ${artifact.name}`); | |
// | |
/** | |
await github.rest.actions.deleteArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: artifact.id | |
}); | |
*/ | |
console.log(`Deleted older artifact: ${artifact.name}`); | |
} else { | |
console.log(`Keeping artifact: ${artifact.name}`); | |
} | |
} |