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, + }); + } + }