From 64f55b7f31b8a1e8b1b820a58e9312d3a83a4694 Mon Sep 17 00:00:00 2001 From: YinCQL <71113782+YinCQL@users.noreply.github.com> Date: Fri, 31 May 2024 21:51:00 +0800 Subject: [PATCH] Add Cleanup old artifacts --- .github/workflows/dotnet.yml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 0e2abbb1..afb6326a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -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, + }); + } + }