-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (95 loc) · 3.34 KB
/
build-container-image.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
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
name: Build container image
on:
workflow_call:
inputs:
tag:
description: 'Tag to build container image for'
type: string
required: true
workflow_dispatch:
inputs:
tag:
description: 'Tag to build container image for'
type: string
required: true
permissions:
contents: read
jobs:
image:
name: Build container image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up QEMU
uses: docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: uniget-bot
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install uniget
uses: uniget-org/uniget-action@2801de6989bb0c244342f750b29e6451498ba742 # v1
with:
prefix: helper
tools: jq regclient
- name: Fetch release asset
run: |
INPUT_VERSION="${{ inputs.tag }}"
VERSION="${INPUT_VERSION#v}"
echo "### Downloading from release ${VERSION}"
for ARCH in x86_64 aarch64; do
case "${ARCH}" in
x86_64)
ALT_ARCH=amd64
;;
aarch64)
ALT_ARCH=arm64
;;
*)
echo "### Unsupported architecture ${ARCH}"
exit 1
;;
esac
echo "### Downloading for architecture ${ARCH} (${ALT_ARCH})"
mkdir -p "dist/default_linux_${ALT_ARCH}"
url="https://github.com/uniget-org/cli/releases/download/v${VERSION}/uniget_Linux_${ARCH}.tar.gz"
echo "### Downloading from ${url}"
curl --silent --show-error --location --fail "${url}" \
| tar --extract --gzip --directory "dist/default_linux_${ALT_ARCH}" uniget
done
- name: Build container image
run: |
INPUT_VERSION="${{ inputs.tag }}"
VERSION="${INPUT_VERSION#v}"
echo "### Building container image for version ${VERSION}"
docker buildx build . \
--target systemd-uniget \
--platform linux/amd64,linux/arm64 \
--build-arg version="${VERSION}" \
--tag "ghcr.io/uniget-org/cli:${VERSION}" \
--push
LATEST_VERSION="$(
./helper/usr/local/bin/regctl tag list ghcr.io/uniget-org/cli \
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -Vr \
| head -n 1
)"
if test -z "${LATEST_VERSION}"; then
echo "### No tags found"
exit
fi
echo "### Tagging ${LATEST_VERSION} as latest"
if ! ./helper/usr/local/bin/regctl manifest get ghcr.io/uniget-org/cli:${LATEST_VERSION}; then
echo " Tag ${LATEST_VERSION} does not exist"
exit
fi
./helper/usr/local/bin/regctl image copy \
"ghcr.io/uniget-org/cli:${VERSION}" \
"ghcr.io/uniget-org/cli:${LATEST_VERSION}"