mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
ci: add a delete artifact action (#2999)
This commit is contained in:
parent
4ca9db156b
commit
febe8f0801
17
.github/actions/artifact_delete/action.yml
vendored
Normal file
17
.github/actions/artifact_delete/action.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
name: Delete artifact
|
||||||
|
description: Delete an artifact by name
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
name:
|
||||||
|
description: 'The name of the artifact.'
|
||||||
|
required: true
|
||||||
|
workflowID:
|
||||||
|
description: 'The ID of the workflow.'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Delete artifact
|
||||||
|
shell: bash
|
||||||
|
run: ./.github/actions/artifact_delete/delete_artifact.sh ${{ inputs.workflowID }} ${{ inputs.name }}
|
43
.github/actions/artifact_delete/delete_artifact.sh
vendored
Executable file
43
.github/actions/artifact_delete/delete_artifact.sh
vendored
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# get_artifact_id retrieves the artifact id of
|
||||||
|
# an artifact that was generated by a workflow.
|
||||||
|
# $1 should be the workflow run id. $2 should be the artifact name.
|
||||||
|
function get_artifact_id {
|
||||||
|
artifact_id="$(gh api \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"/repos/edgelesssys/constellation/actions/runs/$1/artifacts" --jq ".artifacts |= map(select(.name==\"$2\")) | .artifacts[0].id" || exit 1)"
|
||||||
|
echo "$artifact_id"
|
||||||
|
}
|
||||||
|
|
||||||
|
# delete_artifact_by_id deletes an artifact by its artifact id.
|
||||||
|
# $1 should be the id of the artifact.
|
||||||
|
function delete_artifact_by_id {
|
||||||
|
gh api \
|
||||||
|
--method DELETE \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"/repos/edgelesssys/constellation/actions/artifacts/$1" || exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
workflow_id="$1"
|
||||||
|
artifact_name="$2"
|
||||||
|
|
||||||
|
if [[ -z $workflow_id ]]; then
|
||||||
|
echo "[X] No workflow id provided."
|
||||||
|
echo "Usage: delete_artifact.sh <WORKFLOW_ID> <ARTIFACT_NAME>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $artifact_name ]]; then
|
||||||
|
echo "[X] No artifact name provided."
|
||||||
|
echo "Usage: delete_artifact.sh <WORKFLOW_ID> <ARTIFACT_NAME>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[*] retrieving artifact ID"
|
||||||
|
artifact_id="$(get_artifact_id "$workflow_id" "$artifact_name")"
|
||||||
|
|
||||||
|
echo "[*] deleting artifact with ID $artifact_id"
|
||||||
|
delete_artifact_by_id "$artifact_id"
|
Loading…
Reference in New Issue
Block a user