-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
61 lines (51 loc) · 1.94 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: 'Wait for GHCR Container Image'
description: 'Wait for an image to be available in GitHub Container Registry'
inputs:
github-token:
description: 'GitHub token for authentication'
required: true
image-name:
description: 'The image to wait on (e.g., "org/image-name:tag")'
required: true
timeout:
description: 'Maximum time to wait in minutes'
required: false
default: '15'
sleep-time:
description: 'Time to wait between attempts in seconds'
required: false
default: '30'
cache-image:
description: 'Whether to keep the image cached locally after verification'
required: false
default: 'false'
runs:
using: "composite"
steps:
- name: Login to GitHub Container Registry
shell: bash
run: echo "${{ inputs.github-token }}" | docker login ghcr.io -u ${{ inputs.github-username }} --password-stdin
- name: Wait for Image
shell: bash
run: |
echo "Waiting for image ghcr.io/${{ inputs.image-name }} to be available..."
start_time=$(date +%s)
timeout_seconds=$(( ${{ inputs.timeout }} * 60 ))
while true; do
# Use docker manifest inspect instead of pull for availability check
if docker manifest inspect ghcr.io/${{ inputs.image-name }} >/dev/null 2>&1; then
echo "Image is now available!"
if [ "${{ inputs.cache-image }}" = "true" ]; then
docker pull ghcr.io/${{ inputs.image-name }}
fi
exit 0
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ $elapsed_time -ge $timeout_seconds ]; then
echo "Timeout reached after ${{ inputs.timeout }} minutes"
exit 1
fi
echo "Image not yet available, waiting ${{ inputs.sleep-time }} seconds..."
sleep ${{ inputs.sleep-time }}
done