From ac348dbe95fa5ac7930e57a2e48d1617659938a7 Mon Sep 17 00:00:00 2001 From: mikeplotean Date: Sun, 2 Feb 2025 18:23:27 +0200 Subject: [PATCH] ci: add artifact cleanup workflow --- .github/workflows/build.yml | 22 +++++++++++++++++++- .github/workflows/cleanup.yml | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cleanup.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 589ed0191..109b3e80d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,4 +34,24 @@ jobs: secrets: inherit with: artifact: issuer-api - tag: "waltid/issuer-api:${{ needs.version.outputs.release_version }}" \ No newline at end of file + 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 }} \ No newline at end of file diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml new file mode 100644 index 000000000..9401fe7fe --- /dev/null +++ b/.github/workflows/cleanup.yml @@ -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 \ No newline at end of file