Skip to content

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

Draft
mbien wants to merge 1 commit intoapache:masterfrom
mbien:ci-replace-delete-artifact-action
Draft

Replace delete-artifact action with REST api calls using gh CLI#9286
mbien wants to merge 1 commit intoapache:masterfrom
mbien:ci-replace-delete-artifact-action

Conversation

@mbien
Copy link
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 5 times, most recently from dd841ec to 11c77bb Compare March 18, 2026 22:46
@mbien mbien force-pushed the ci-replace-delete-artifact-action branch 10 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
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.

1 participant