Skip to content

Commit

Permalink
ci: add artifact cleanup workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Feb 2, 2025
1 parent cc37065 commit b0f410e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
22 changes: 21 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,24 @@ jobs:
secrets: inherit
with:
artifact: issuer-api
tag: "waltid/issuer-api:${{ needs.version.outputs.release_version }}"
tag: "waltid/issuer-api:${{ needs.version.outputs.release_version }}"
artifact-names:
runs-on: ubuntu-latest
needs: [ docker-matrix ]
outputs:
artifacts: ${{ steps.artifact-names.outputs.names }}
steps:
- name: Extract names from JSON
id: artifact-names
run: |
# Define the JSON input
json_data=${{ needs.docker-matrix.outputs.json }}
# Use jq to extract names into a list
names=$(echo $json_data | jq -r 'map(.name) | @csv' | tr -d '"')
# Set the output as an environment variable
echo "names=$names" >> $GITHUB_OUTPUT
cleanup:
uses: walt-id/waltid-identity/.github/workflows/cleanup.yml@feat/docker-build-share
needs: [ artifact-names ]
with:
artifacts: ${{ needs.artifact-names.outputs.artifacts }}
38 changes: 38 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Delete Artifacts

on:
workflow_call:
inputs:
artifacts:
required: true
type: string

jobs:
delete:
runs-on: ubuntu-latest
strategy:
matrix:
artifact: [${{ inputs.artifacts }}]
steps:
- name: Delete artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
artifact_name="${{ matrix.artifact }}"
echo "Deleting artifact: $artifact_name"
# Get the artifact ID for the known artifact name
ARTIFACT_ID=$(curl -s \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts" | \
jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .id")
# Delete the artifact if found
if [ -n "$ARTIFACT_ID" ]; then
curl -X DELETE \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID"
echo "Artifact '$artifact_name' deleted."
else
echo "No artifact named '$artifact_name' found to delete."
fi

0 comments on commit b0f410e

Please sign in to comment.