Skip to content

Commit 9e4bf09

Browse files
committed
Add script to backfill old tags
1 parent 302b4fc commit 9e4bf09

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

ci/backfill-tags.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Handle Ctrl+C
5+
trap 'echo -e "\nInterrupted. Exiting..."; exit 130' INT TERM
6+
7+
# Docker images to check for each semver tag
8+
DOCKER_IMAGES=(
9+
activemq
10+
alpaca
11+
blazegraph
12+
cantaloupe
13+
crayfish
14+
crayfits
15+
drupal
16+
fcrepo6
17+
fits
18+
handle
19+
homarus
20+
houdini
21+
hypercube
22+
imagemagick
23+
java
24+
mariadb
25+
milliner
26+
nginx
27+
postgresql
28+
riprap
29+
solr
30+
tomcat
31+
)
32+
33+
DOCKER_REPOSITORY="${DOCKER_REPOSITORY:-islandora}"
34+
WORKFLOW_FILE="${WORKFLOW_FILE:-push.yml}"
35+
WORKFLOW_REF="${WORKFLOW_REF:-main}"
36+
LOG_FILE="${LOG_FILE:-backfill-tags.log}"
37+
DRY_RUN=true
38+
SINGLE_TAG=""
39+
40+
# Parse arguments
41+
while [[ $# -gt 0 ]]; do
42+
case $1 in
43+
--yolo)
44+
DRY_RUN=false
45+
shift
46+
;;
47+
--tag)
48+
SINGLE_TAG="$2"
49+
shift 2
50+
;;
51+
*)
52+
shift
53+
;;
54+
esac
55+
done
56+
57+
# Get all semver tags from the repo (3.x and above), sorted
58+
get_semver_tags() {
59+
git tag --list | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | while read -r tag; do
60+
# Extract major version (strip leading 'v' if present)
61+
local version="${tag#v}"
62+
local major="${version%%.*}"
63+
if [[ "$major" -ge 3 ]]; then
64+
echo "$tag"
65+
fi
66+
done
67+
}
68+
69+
# Check if a Docker image exists
70+
image_exists() {
71+
local image="$1"
72+
local tag="$2"
73+
local full_image="${DOCKER_REPOSITORY}/${image}:${tag}"
74+
75+
# Use docker manifest inspect to check if image exists (doesn't pull the image)
76+
if docker manifest inspect "$full_image" &>/dev/null; then
77+
return 0
78+
else
79+
return 1
80+
fi
81+
}
82+
83+
# Log a workflow run
84+
log_workflow() {
85+
local tag="$1"
86+
local run_id="$2"
87+
local url="$3"
88+
local timestamp
89+
timestamp=$(date -Iseconds)
90+
91+
echo "${timestamp} | ${tag} | ${run_id} | ${url}" >> "$LOG_FILE"
92+
echo " Logged to $LOG_FILE: $url"
93+
}
94+
95+
# Run the workflow for a given tag
96+
run_workflow() {
97+
local tag="$1"
98+
99+
echo "Running workflow for tag: $tag"
100+
101+
if [[ "$DRY_RUN" == "true" ]]; then
102+
echo "[DRY-RUN] Would run: gh workflow run $WORKFLOW_FILE --ref $WORKFLOW_REF -f tag=$tag -f strip-apk-pinning=true"
103+
return 0
104+
fi
105+
106+
# Run the workflow and wait for completion
107+
gh workflow run "$WORKFLOW_FILE" \
108+
--ref "$WORKFLOW_REF" \
109+
-f "tag=$tag" \
110+
-f "strip-apk-pinning=true"
111+
112+
# Give GitHub a moment to register the run
113+
sleep 5
114+
115+
# Get the run ID and URL of the workflow we just triggered
116+
local run_info run_id run_url
117+
run_info=$(gh run list --workflow="$WORKFLOW_FILE" --limit=1 --json databaseId,url --jq '.[0] | "\(.databaseId) \(.url)"')
118+
run_id=$(echo "$run_info" | cut -d' ' -f1)
119+
run_url=$(echo "$run_info" | cut -d' ' -f2)
120+
121+
# Log the tag and workflow URL
122+
log_workflow "$tag" "$run_id" "$run_url"
123+
124+
echo "Waiting for workflow run $run_id to complete..."
125+
gh run watch "$run_id" --exit-status
126+
127+
echo "Workflow completed for tag: $tag"
128+
}
129+
130+
# Main logic
131+
main() {
132+
if [[ "$DRY_RUN" == "true" ]]; then
133+
echo "=== DRY-RUN MODE (pass --yolo to execute) ==="
134+
echo ""
135+
fi
136+
137+
local tags
138+
if [[ -n "$SINGLE_TAG" ]]; then
139+
tags="$SINGLE_TAG"
140+
echo "Processing single tag: $tags"
141+
else
142+
tags=$(get_semver_tags)
143+
144+
if [[ -z "$tags" ]]; then
145+
echo "No semver tags >= 3.0.0 found in repository"
146+
exit 0
147+
fi
148+
149+
echo "Found semver tags (>= 3.0.0):"
150+
echo "$tags"
151+
fi
152+
echo ""
153+
154+
while IFS= read -r tag; do
155+
echo "Checking tag: $tag"
156+
157+
local missing_images=()
158+
159+
for image in "${DOCKER_IMAGES[@]}"; do
160+
if ! image_exists "$image" "$tag"; then
161+
missing_images+=("$image")
162+
fi
163+
done
164+
165+
if [[ ${#missing_images[@]} -gt 0 ]]; then
166+
echo " Missing images for $tag: ${missing_images[*]}"
167+
run_workflow "$tag"
168+
else
169+
echo " All images exist for $tag, skipping"
170+
fi
171+
172+
echo ""
173+
done <<< "$tags"
174+
175+
echo "Done!"
176+
}
177+
178+
main

0 commit comments

Comments
 (0)