forked from autowarefoundation/autoware
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yaml
118 lines (96 loc) · 4.06 KB
/
action.yaml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: combine-multi-arch-images
description: ""
inputs:
package-name:
description: ""
required: true
runs:
using: composite
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Set image name
id: set-image-name
run: echo "image-name=ghcr.io/${{ github.repository_owner }}/${{ inputs.package-name }}" >> $GITHUB_OUTPUT
shell: bash
- name: Get all tags
id: get-all-tags
run: |
base_url="https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${{ inputs.package-name }}/versions"
echo "base_url: $base_url"
all_tags=()
for page in $(seq 1 10); do
page_url="${base_url}?page=$page"
echo -e "\npage_url: $page_url"
page_tags=$(curl -fsSL "$page_url" -H "Authorization: token ${{ github.token }}" | jq ".[].metadata.container.tags[]" | cut -d '"' -f 2)
echo -e "\n[page_tags]\n$page_tags"
if [ "$page_tags" = "" ]; then
echo "No tags found in the page $page."
break
fi
for tag in $(IFS=$'\n'; echo "$page_tags"); do
all_tags+=("$tag")
done
done
all_tags=$(printf "%s\n" ${all_tags[@]})
echo -e "\n[all_tags]\n$all_tags"
echo "tags=$(printf "%s " $all_tags | sed 's/\s*$//')" >> $GITHUB_OUTPUT
shell: bash
- name: Get base tags
id: get-base-tags
run: |
amd64_tags=$(printf "%s\n" $ALL_TAGS | grep "\-amd64" | sed "s/-amd64$//g")
arm64_tags=$(printf "%s\n" $ALL_TAGS | grep "\-arm64" | sed "s/-arm64$//g")
base_tags=$(printf "%s\n" "$amd64_tags" "$arm64_tags" | sort | uniq)
echo -e "\n[amd64_tags]\n$amd64_tags"
echo -e "\n[arm64_tags]\n$arm64_tags"
echo -e "\n[base_tags]\n$base_tags"
echo "tags=$(printf "%s " $base_tags | sed 's/\s*$//')" >> $GITHUB_OUTPUT
env:
ALL_TAGS: ${{ steps.get-all-tags.outputs.tags }}
shell: bash
- name: Create Docker manifest and delete -amd64 and -arm64 tags
run: |
for base_tag in $BASE_TAGS; do
echo -e "\nbase_tag: $base_tag"
amd64_tag=$(printf "%s\n" $ALL_TAGS | grep "^$base_tag\-amd64" || true)
arm64_tag=$(printf "%s\n" $ALL_TAGS | grep "^$base_tag\-arm64" || true)
echo "amd64_tag: $amd64_tag"
echo "arm64_tag: $arm64_tag"
if [ "$amd64_tag" != "" ]; then
amd64_image="${{ steps.set-image-name.outputs.image-name }}:$amd64_tag"
else
echo "No amd64 tag found for '$base_tag'."
continue
fi
if [ "$arm64_tag" != "" ]; then
arm64_image="${{ steps.set-image-name.outputs.image-name }}:$arm64_tag"
else
echo "No arm64 tag found for '$base_tag'."
continue
fi
echo "amd64_image: $amd64_image"
echo "arm64_image: $arm64_image"
if docker manifest create ${{ steps.set-image-name.outputs.image-name }}:$base_tag \
$amd64_image \
$arm64_image; then
docker manifest push ${{ steps.set-image-name.outputs.image-name }}:$base_tag
# Delete amd64_image and arm64_image
curl -X DELETE \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${{ inputs.package-name }}/versions/$amd64_tag
curl -X DELETE \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${{ inputs.package-name }}/versions/$arm64_tag
fi
done
env:
ALL_TAGS: ${{ steps.get-all-tags.outputs.tags }}
BASE_TAGS: ${{ steps.get-base-tags.outputs.tags }}
shell: bash