Add Cleanup old artifacts

This commit is contained in:
YinCQL
2024-05-31 21:51:00 +08:00
committed by GitHub
parent 877af770bc
commit 64f55b7f31

View File

@@ -3,6 +3,10 @@
name: .NET
permissions:
actions: write
contents: write
on:
push:
branches: [ "master" ]
@@ -12,7 +16,6 @@ on:
paths: [ "**.cs" ]
workflow_dispatch:
jobs:
build:
@@ -20,7 +23,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
@@ -56,5 +59,22 @@ jobs:
name: DanhengServer-linux-arm64
path: Release\linux-arm64
- name: Cleanup old artifacts
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const runId = process.env.GITHUB_RUN_ID;
const artifacts = await github.actions.listArtifactsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
});
for (const artifact of artifacts.data.artifacts) {
if (artifact.workflow_run.id.toString() !== runId) {
await github.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
});
}
}