Skip to content

Replace delete-artifact action with REST api calls using gh CLI#9286

Merged
mbien merged 1 commit into
apache:masterfrom
mbien:ci-replace-delete-artifact-action
Jun 1, 2026
Merged

Replace delete-artifact action with REST api calls using gh CLI#9286
mbien merged 1 commit into
apache:masterfrom
mbien:ci-replace-delete-artifact-action

Conversation

@mbien
Copy link
Copy Markdown
Member

@mbien mbien commented Mar 18, 2026

tried to come up with a way to remove the third party action.

attempt 1 using github-script looked like:

      - name: Delete Workflow Artifacts
        uses: actions/github-script@v8
        with:
          script: |
            const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: context.runId
            });
            for (const artifact of artifacts.data.artifacts) {
              if (artifact.name === "build.tar.zst") {
                console.log("removing " + artifact.name);
                await github.rest.actions.deleteArtifact({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  artifact_id: artifact.id
                });
              }
            }

attempt 2 using gh CLI:

      - name: Delete Workspace Artifact
        run: |
          ARTIFACT_ID=$(gh api /repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts --jq ".artifacts[] | select(.name == \"${NAME}\") | .id")
          if [ -n "$ARTIFACT_ID" ]; then
            gh api /repos/${GITHUB_REPOSITORY}/actions/artifacts/${ARTIFACT_ID} -X DELETE
          fi
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NAME: build.tar.zst

both would require

    permissions:
      actions: write

unfortunately

I don't know what black magic geekyeggo/delete-artifact uses to delete it without permissions set.

@mbien mbien added the CI continuous integration changes label Mar 18, 2026
@mbien mbien force-pushed the ci-replace-delete-artifact-action branch 15 times, most recently from 65a8417 to 26ed96d Compare March 19, 2026 02:12
@mbien mbien added the ci:no-build [ci] disable CI pipeline label Mar 19, 2026
@mbien mbien force-pushed the ci-replace-delete-artifact-action branch from 26ed96d to b4ea395 Compare March 19, 2026 03:01
@ebarboni
Copy link
Copy Markdown
Contributor

replacement of #9280

@mbien mbien added this to the NB31 milestone Jun 1, 2026
@mbien mbien force-pushed the ci-replace-delete-artifact-action branch from b4ea395 to 2425ddc Compare June 1, 2026 13:12
@mbien mbien marked this pull request as ready for review June 1, 2026 13:12
@mbien mbien requested a review from neilcsmith-net June 1, 2026 13:13
Copy link
Copy Markdown
Member

@neilcsmith-net neilcsmith-net left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Surprised that gh doesn't have a command to handle this - see gh run download and gh rn delete but nothing for managing individual artifacts? Should remember to update this if that changes.

👍

@mbien mbien merged commit 567da19 into apache:master Jun 1, 2026
24 checks passed
@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jun 2, 2026

we may have to revert this because this doesn't seem to work in (certain?) PRs. The actions permission is still set to read.

e.g https://github.com/apache/netbeans/actions/runs/26810081110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:no-build [ci] disable CI pipeline CI continuous integration changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants