Skip to content

Commit a91b26a

Browse files
committed
update workflows
1 parent 05ee3d2 commit a91b26a

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

.github/actions/1-addition/1-maps/action.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,36 @@ runs:
187187
configFile: ${{ inputs.action_path }}/.devcontainer.json
188188
push: ${{ env.RERUN_RUNNER == 'true' && 'always' || 'never' }}
189189

190-
- name: 💎 Variables
190+
- name: 🗑️ Delete 15 Oldest Docker Images
191191
id: variables
192192
shell: bash
193+
env:
194+
MAX_DELETIONS: 15
193195
run: |
194-
BASE_NAME=$(basename ${{ inputs.image_name }})
195-
IFS=', '; array=($(curl -L -s 'https://registry.hub.docker.com/v2/repositories/${{ inputs.image_name }}/tags?page_size=1024' | jq -rc '."results"[]["name"]' | yq eval -P | sed "s/ /, /g"))
196-
for ((i=0; i < ${#array[@]}; i++)); do
197-
if [ "${array[$i]}" != "latest" ]; then
198-
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${{ inputs.hub_username }}\", \"password\": \"${{ inputs.hub_password }}\"}" https://hub.docker.com/v2/users/login/ | jq -r .token)
199-
curl -s -i -X DELETE -H "Accept: application/json" -H "Authorization: JWT $HUB_TOKEN" https://hub.docker.com/v2/namespaces/${{ inputs.hub_username }}/repositories/$BASE_NAME/tags/${array[$i]}
200-
echo "deleted: ${{ inputs.image_name }}:${array[$i]}"
196+
echo "Fetching manifests to delete..."
197+
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST \
198+
-d "{\"username\": \"${{ inputs.hub_username }}\", \"password\": \"${{ inputs.hub_password }}\"}" \
199+
https://hub.docker.com/v2/users/login/ | jq -r .token)
200+
[ -z "$HUB_TOKEN" ] && { echo "❌ Authentication failed"; exit 1; }
201+
202+
MANIFESTS=$(curl -s -H "Authorization: JWT $HUB_TOKEN" \
203+
"https://hub.docker.com/v2/repositories/${{ inputs.image_name }}/tags/?page_size=${{ env.MAX_DELETIONS }}&ordering=last_updated" \
204+
| jq -r '.results[] | select(.images != null) | .images[].digest' \
205+
| sort | uniq | head -n ${{ env.MAX_DELETIONS }})
206+
207+
DELETED_MANIFESTS=0
208+
for SHA in $MANIFESTS; do
209+
echo "Deleting manifest ${SHA:0:12}..."
210+
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
211+
-H "Authorization: JWT $HUB_TOKEN" \
212+
"https://hub.docker.com/v2/repositories/${{ inputs.image_name }}/manifests/$SHA")
213+
214+
if [ "$RESPONSE" -eq 202 ]; then
215+
((DELETED_MANIFESTS++))
216+
echo "✅ Deleted manifest"
217+
sleep 1
218+
else
219+
echo "❌ Failed to delete (HTTP $RESPONSE)"
201220
fi
202221
done
222+
echo "Deleted manifests: $DELETED_MANIFESTS"

.github/entrypoint/init.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ git config --global --add safe.directory "${GITHUB_WORKSPACE}"
1414
git config --global credential.helper store
1515
echo "https://${GITHUB_ACTOR}:${GH_TOKEN}@github.com" > ~/.git-credentials
1616

17+
# Get current repo name in owner/repo format
18+
CURRENT_REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
19+
20+
# Get list of all repositories (user and org)
21+
ALL_REPOS=$(gh repo list --limit 1000 --json nameWithOwner -q '.[].nameWithOwner')
22+
23+
# Loop through all repos and cancel runs except current one
24+
for repo in $ALL_REPOS; do
25+
if [ "$repo" != "$CURRENT_REPO" ]; then
26+
echo "Canceling runs in $repo"
27+
gh api -X POST "/repos/$repo/actions/runs/cancel" || echo "Failed to cancel runs in $repo"
28+
else
29+
echo "Skipping current repo: $repo"
30+
fi
31+
done
32+
1733
export RERUN_RUNNER=$(curl -s -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" \
1834
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/variables/RERUN_RUNNER" | jq -r '.value')
1935
export TARGET_REPOSITORY=$(curl -s -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" \

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: COmpendium of RElations – Modulo 6
33

44
on:
5-
push:
5+
#push:
66
workflow_run:
77
types: [completed]
88
workflows: ["pages-build-deployment"]

0 commit comments

Comments
 (0)