Skip to content

Commit 79e184f

Browse files
committed
update workflows
1 parent 6bebd95 commit 79e184f

5 files changed

Lines changed: 71 additions & 64 deletions

File tree

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

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

190-
- name: 🗑️ Delete 15 Oldest Docker Images
191-
id: variables
190+
- name: 🗑️ Delete Docker Tags AND Images
191+
id: delete_images
192192
shell: bash
193193
env:
194+
IMAGE_NAME: "${{ inputs.image_name }}"
195+
HUB_USERNAME: "${{ inputs.hub_username }}"
196+
HUB_PASSWORD: "${{ inputs.hub_password }}"
194197
MAX_DELETIONS: 15
195198
run: |
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)"
220-
fi
221-
done
222-
echo "Deleted manifests: $DELETED_MANIFESTS"
199+
./.github/entrypoint/remote.sh

.github/actions/2-multiplication/2-feed/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ runs:
133133
[Service]
134134
Type=oneshot
135135
RemainAfterExit=true
136-
ExecStart=/sbin/iptables -A INPUT -p tcp --match multiport --dports 80,5432,6379 -j ACCEPT
136+
ExecStart=/sbin/iptables -A INPUT -p tcp --match multiport --dports 80,5432,6379,8080 -j ACCEPT
137137
138138
- path: /etc/systemd/system/runner1.service
139139
permissions: "0644"

.github/entrypoint/artifact.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ jekyll_build() {
123123

124124
fi
125125

126-
# Fetch SHA, encode new content, and update in one step
127-
gh api --method PUT /repos/${TARGET_REPOSITORY}/contents/.github/workflows/main.yml \
128-
-f sha="$(gh api /repos/${TARGET_REPOSITORY}/contents/.github/workflows/main.yml --jq '.sha')" \
129-
-f message="Update file" -f content="$(base64 -w0 .github/workflows/main.yml)" > /dev/null
130-
131126
}
132127

133128
# Define the next repository function using jq

.github/entrypoint/init.sh

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@ 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-
3317
export RERUN_RUNNER=$(curl -s -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" \
3418
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/variables/RERUN_RUNNER" | jq -r '.value')
3519
export TARGET_REPOSITORY=$(curl -s -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" \
@@ -70,13 +54,28 @@ if [[ -z ${PASS} ]] || [[ "${PASS}" == "true" ]]; then
7054
echo -e "\n$hr\nCONFIG\n$hr"
7155
mv -f /home/runner/work/_actions/eq19/eq19/v2/.github/templates/jekyll_config.yml $RUNNER_TEMP/_config.yml
7256
export PATH=/home/runner/work/_actions/eq19/eq19/v2/.github/entrypoint:$PATH && artifact.sh
73-
57+
58+
# Loop through all repos and cancel runs except current one
59+
#ALL_REPOS=""
60+
#ORGS=$(gh api user/orgs --jq '.[].login')
61+
#CURRENT_REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
62+
#ALL_REPOS+=$(gh repo list --limit 1000 --json nameWithOwner -q '.[].nameWithOwner')
63+
#for org in $ORGS; do ALL_REPOS+=$(gh repo list $org --limit 1000 --json nameWithOwner -q '.[].nameWithOwner'); done
64+
#for REPO in $ALL_REPOS; do
65+
#if [ "$REPO" != "$CURRENT_REPO" ]; then
66+
#RUNS=$(gh api "repos/$REPO/actions/runs?status=in_progress" --jq '.workflow_runs[].id')
67+
#RUNS+=" $(gh api "repos/$REPO/actions/runs?status=queued" --jq '.workflow_runs[].id')"
68+
#for RUN_ID in $RUNS; do gh api -X POST "repos/$REPO/actions/runs/$RUN_ID/force-cancel"; done
69+
#fi
70+
#done
71+
7472
PARAMS_JSON=$(curl -s -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" \
7573
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/variables/PARAMS_JSON" | jq -r '.value')
7674
echo "${PARAMS_JSON}" | jq '.' > $1/user_data/strategies/fibbo.json
7775
if jq empty < $1/user_data/strategies/fibbo.json; then
7876
echo -e "\n$hr\nPARAMETERS\n$hr"
7977
cat $1/user_data/strategies/fibbo.json
78+
gh variable set PARAMS_JSON --repo ${TARGET_REPOSITORY} --body "${PARAMS_JSON}"
8079
else
8180
echo "Invalid JSON"
8281
fi
@@ -112,6 +111,11 @@ if [[ "${JOBS_ID}" == "1" ]]; then
112111
cd $1 && javac -d user_data/ft_client/test_client javaCode/Main.java
113112
cd $GITHUB_WORKSPACE && rm -rf user_data && mv -f $1/user_data . && ls -al .
114113

114+
# Fetch SHA, encode new content, and update in one step
115+
gh api --method PUT /repos/${TARGET_REPOSITORY}/contents/.github/workflows/main.yml \
116+
-f sha="$(gh api /repos/${TARGET_REPOSITORY}/contents/.github/workflows/main.yml --jq '.sha')" \
117+
-f message="Update file" -f content="$(base64 -w0 .github/workflows/main.yml)" > /dev/null
118+
115119
fi
116120

117121
elif [[ "${JOBS_ID}" == "2" ]]; then

.github/entrypoint/remote.sh

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

3-
deploy_remote() {
4-
echo -e "Deploying to $1 on branch gh-pages"
5-
REMOTE_REPO="https://${ACTOR}:${TOKEN}@github.com/$1.git"
3+
# 1. Authenticate
4+
token=$(curl -s -H "Content-Type: application/json" -X POST \
5+
-d "{\"username\": \"$HUB_USERNAME\", \"password\": \"$HUB_PASSWORD\"}" \
6+
https://hub.docker.com/v2/users/login/ | jq -r .token)
7+
[ -z "$token" ] && { echo "❌ Auth failed"; exit 1; }
68

7-
git config --global user.name "${ACTOR}"
8-
git config --global user.email "${ACTOR}@users.noreply.github.com"
9+
# 2. Get manifests with tags
10+
response=$(curl -s -H "Authorization: JWT $token" \
11+
"https://hub.docker.com/v2/repositories/$IMAGE_NAME/tags/?page_size=$MAX_DELETIONS&ordering=last_updated")
912

10-
git clone -b gh-pages --single-branch ${REMOTE_REPO} &>/dev/null
11-
cd "$(basename "${REMOTE_REPO}" .git)" && rm -rf *
13+
# 3. Process deletions
14+
deleted=0
15+
echo "$response" | jq -c '.results[]' | while read -r item; do
16+
tag=$(echo "$item" | jq -r '.name')
17+
digest=$(echo "$item" | jq -r '.images[0].digest')
18+
19+
echo "Processing ${digest:7:12}..."
20+
21+
# Delete tag first (if not latest)
22+
if [ "$tag" != "null" ] && [ "$tag" != "latest" ]; then
23+
echo " 🏷️ Deleting tag: $tag"
24+
curl -s -o /dev/null -X DELETE \
25+
-H "Authorization: JWT $token" \
26+
"https://hub.docker.com/v2/namespaces/${IMAGE_NAME%/*}/repositories/${IMAGE_NAME#*/}/tags/$tag"
27+
fi
28+
29+
# Delete the actual image manifest
30+
echo " 🖼️ Deleting image manifest..."
31+
status=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
32+
-H "Authorization: JWT $token" \
33+
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
34+
"https://hub.docker.com/v2/repositories/$IMAGE_NAME/manifests/$digest")
35+
36+
if [ "$status" -eq 202 ]; then
37+
((deleted++))
38+
echo " ✅ Deleted successfully"
39+
else
40+
echo " ❌ Failed to delete image (HTTP $status)"
41+
fi
42+
43+
sleep 2
44+
[ $deleted -ge $MAX_DELETIONS ] && break
45+
done
1246

13-
mv -v ${GITHUB_WORKSPACE}/_site/* . && touch .nojekyll && git add .
14-
git commit -m "jekyll build from cction ${GITHUB_SHA}"
15-
git push -u origin gh-pages
16-
}
47+
echo "Result: Deleted $deleted images (tags AND manifests)"

0 commit comments

Comments
 (0)