Skip to content

Commit db59edb

Browse files
authored
ci: fix shellcheck errors and improve consistency (#2165)
1 parent 3f2ed37 commit db59edb

File tree

5 files changed

+123
-120
lines changed

5 files changed

+123
-120
lines changed

scripts/ci/compute-fingerprint.sh renamed to .github/scripts/docker-compute-fingerprints.sh

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
set -euo pipefail
33

44
write_output() {
5-
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
6-
echo "$1" >> "${GITHUB_OUTPUT}"
7-
else
8-
echo "$1"
9-
fi
5+
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
6+
echo "$1" >>"${GITHUB_OUTPUT}"
7+
else
8+
echo "$1"
9+
fi
1010
}
1111

1212
get_php_version() {
13-
local version="$1"
14-
skopeo inspect "docker://docker.io/library/php:${version}" \
15-
--override-os linux \
16-
--override-arch amd64 |
17-
jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")'
13+
local version="$1"
14+
skopeo inspect "docker://docker.io/library/php:${version}" \
15+
--override-os linux \
16+
--override-arch amd64 |
17+
jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")'
1818
}
1919

2020
PHP_82_LATEST="$(get_php_version 8.2)"
@@ -30,55 +30,55 @@ write_output "php84_version=${PHP_84_LATEST//./-}"
3030
write_output "php85_version=${PHP_85_LATEST//./-}"
3131

3232
if [[ "${GITHUB_EVENT_NAME:-}" == "schedule" ]]; then
33-
FRANKENPHP_LATEST_TAG="$(gh release view --repo php/frankenphp --json tagName --jq '.tagName')"
34-
git checkout "${FRANKENPHP_LATEST_TAG}"
33+
FRANKENPHP_LATEST_TAG="$(gh release view --repo php/frankenphp --json tagName --jq '.tagName')"
34+
git checkout "${FRANKENPHP_LATEST_TAG}"
3535
fi
3636

3737
METADATA="$(PHP_VERSION="${PHP_VERSION}" docker buildx bake --print | jq -c)"
3838

3939
BASE_IMAGES=()
4040
while IFS= read -r image; do
41-
BASE_IMAGES+=("${image}")
41+
BASE_IMAGES+=("${image}")
4242
done < <(jq -r '
43-
.target[]?.contexts? | to_entries[]?
44-
| select(.value | startswith("docker-image://"))
45-
| .value
46-
| sub("^docker-image://"; "")
47-
' <<< "${METADATA}" | sort -u)
43+
.target[]?.contexts? | to_entries[]?
44+
| select(.value | startswith("docker-image://"))
45+
| .value
46+
| sub("^docker-image://"; "")
47+
' <<<"${METADATA}" | sort -u)
4848

4949
BASE_IMAGE_DIGESTS=()
5050
for image in "${BASE_IMAGES[@]}"; do
51-
if [[ "${image}" == */* ]]; then
52-
ref="docker://docker.io/${image}"
53-
else
54-
ref="docker://docker.io/library/${image}"
55-
fi
56-
digest="$(skopeo inspect "${ref}" \
57-
--override-os linux \
58-
--override-arch amd64 \
59-
--format '{{.Digest}}')"
60-
BASE_IMAGE_DIGESTS+=("${image}@${digest}")
51+
if [[ "${image}" == */* ]]; then
52+
ref="docker://docker.io/${image}"
53+
else
54+
ref="docker://docker.io/library/${image}"
55+
fi
56+
digest="$(skopeo inspect "${ref}" \
57+
--override-os linux \
58+
--override-arch amd64 \
59+
--format '{{.Digest}}')"
60+
BASE_IMAGE_DIGESTS+=("${image}@${digest}")
6161
done
6262

6363
BASE_FINGERPRINT="$(printf '%s\n' "${BASE_IMAGE_DIGESTS[@]}" | sort | sha256sum | awk '{print $1}')"
6464
write_output "base_fingerprint=${BASE_FINGERPRINT}"
6565

6666
if [[ "${GITHUB_EVENT_NAME:-}" != "schedule" ]]; then
67-
write_output "skip=false"
68-
exit 0
67+
write_output "skip=false"
68+
exit 0
6969
fi
7070

7171
FRANKENPHP_LATEST_TAG_NO_PREFIX="${FRANKENPHP_LATEST_TAG#v}"
7272
EXISTING_FINGERPRINT=$(
73-
skopeo inspect "docker://docker.io/dunglas/frankenphp:${FRANKENPHP_LATEST_TAG_NO_PREFIX}" \
74-
--override-os linux \
75-
--override-arch amd64 |
76-
jq -r '.Labels["dev.frankenphp.base.fingerprint"] // empty'
73+
skopeo inspect "docker://docker.io/dunglas/frankenphp:${FRANKENPHP_LATEST_TAG_NO_PREFIX}" \
74+
--override-os linux \
75+
--override-arch amd64 |
76+
jq -r '.Labels["dev.frankenphp.base.fingerprint"] // empty'
7777
)
7878

7979
if [[ -n "${EXISTING_FINGERPRINT}" ]] && [[ "${EXISTING_FINGERPRINT}" == "${BASE_FINGERPRINT}" ]]; then
80-
write_output "skip=true"
81-
exit 0
80+
write_output "skip=true"
81+
exit 0
8282
fi
8383

8484
write_output "ref=${FRANKENPHP_LATEST_TAG}"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PHP_VERSION="${PHP_VERSION:-}"
5+
GO_VERSION="${GO_VERSION:-}"
6+
USE_LATEST_PHP="${USE_LATEST_PHP:-0}"
7+
8+
if [[ -z "${GO_VERSION}" ]]; then
9+
GO_VERSION="$(awk -F'"' '/variable "GO_VERSION"/ {f=1} f && /default/ {print $2; exit}' docker-bake.hcl)"
10+
GO_VERSION="${GO_VERSION:-1.25}"
11+
fi
12+
13+
if [[ -z "${PHP_VERSION}" ]]; then
14+
PHP_VERSION="$(awk -F'"' '/variable "PHP_VERSION"/ {f=1} f && /default/ {print $2; exit}' docker-bake.hcl)"
15+
PHP_VERSION="${PHP_VERSION:-8.2,8.3,8.4,8.5}"
16+
fi
17+
18+
if [[ "${USE_LATEST_PHP}" == "1" ]]; then
19+
PHP_82_LATEST=$(skopeo inspect docker://docker.io/library/php:8.2 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
20+
PHP_83_LATEST=$(skopeo inspect docker://docker.io/library/php:8.3 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
21+
PHP_84_LATEST=$(skopeo inspect docker://docker.io/library/php:8.4 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
22+
PHP_85_LATEST=$(skopeo inspect docker://docker.io/library/php:8.5 --override-os linux --override-arch amd64 | jq -r '.Env[] | select(test("^PHP_VERSION=")) | sub("^PHP_VERSION="; "")')
23+
PHP_VERSION="${PHP_82_LATEST},${PHP_83_LATEST},${PHP_84_LATEST},${PHP_85_LATEST}"
24+
fi
25+
26+
OS_LIST=()
27+
while IFS= read -r os; do
28+
OS_LIST+=("${os}")
29+
done < <(
30+
python3 - <<'PY'
31+
import re
32+
33+
with open("docker-bake.hcl", "r", encoding="utf-8") as f:
34+
data = f.read()
35+
36+
# Find the first "os = [ ... ]" block and extract quoted values
37+
m = re.search(r'os\s*=\s*\[(.*?)\]', data, re.S)
38+
if not m:
39+
raise SystemExit(1)
40+
41+
vals = re.findall(r'"([^"]+)"', m.group(1))
42+
for v in vals:
43+
print(v)
44+
PY
45+
)
46+
47+
IFS=',' read -r -a PHP_VERSIONS <<<"${PHP_VERSION}"
48+
49+
BASE_IMAGES=()
50+
for os in "${OS_LIST[@]}"; do
51+
BASE_IMAGES+=("golang:${GO_VERSION}-${os}")
52+
for pv in "${PHP_VERSIONS[@]}"; do
53+
BASE_IMAGES+=("php:${pv}-zts-${os}")
54+
done
55+
done
56+
57+
mapfile -t BASE_IMAGES < <(printf '%s\n' "${BASE_IMAGES[@]}" | sort -u)
58+
59+
BASE_IMAGE_DIGESTS=()
60+
for image in "${BASE_IMAGES[@]}"; do
61+
if [[ "${image}" == */* ]]; then
62+
ref="docker://docker.io/${image}"
63+
else
64+
ref="docker://docker.io/library/${image}"
65+
fi
66+
digest="$(skopeo inspect "${ref}" --override-os linux --override-arch amd64 --format '{{.Digest}}')"
67+
BASE_IMAGE_DIGESTS+=("${image}@${digest}")
68+
done
69+
70+
hash_cmd="sha256sum"
71+
if ! command -v "${hash_cmd}" >/dev/null 2>&1; then
72+
hash_cmd="shasum -a 256"
73+
fi
74+
75+
fingerprint="$(printf '%s\n' "${BASE_IMAGE_DIGESTS[@]}" | sort | ${hash_cmd} | awk '{print $1}')"
76+
77+
echo "PHP_VERSION=${PHP_VERSION}"
78+
echo "GO_VERSION=${GO_VERSION}"
79+
echo "OS_LIST=${OS_LIST[*]}"
80+
echo "Base images:"
81+
printf ' %s\n' "${BASE_IMAGES[@]}"
82+
echo "Fingerprint: ${fingerprint}"

.github/workflows/docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
id: check
6363
env:
6464
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65-
run: ./scripts/ci/compute-fingerprint.sh
65+
run: ./.github/scripts/docker-compute-fingerprints.sh
6666
- name: Create variants matrix
6767
if: ${{ !fromJson(steps.check.outputs.skip) }}
6868
id: matrix

frankenphp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,15 @@ static void frankenphp_snapshot_ini(void) {
226226
if (EG(modified_ini_directives) == NULL) {
227227
/* Allocate empty table to mark as snapshotted */
228228
ALLOC_HASHTABLE(worker_ini_snapshot);
229-
zend_hash_init(worker_ini_snapshot, 0, NULL, frankenphp_ini_snapshot_dtor, 0);
229+
zend_hash_init(worker_ini_snapshot, 0, NULL, frankenphp_ini_snapshot_dtor,
230+
0);
230231
return;
231232
}
232233

233234
uint32_t num_modified = zend_hash_num_elements(EG(modified_ini_directives));
234235
ALLOC_HASHTABLE(worker_ini_snapshot);
235-
zend_hash_init(worker_ini_snapshot, num_modified, NULL, frankenphp_ini_snapshot_dtor, 0);
236+
zend_hash_init(worker_ini_snapshot, num_modified, NULL,
237+
frankenphp_ini_snapshot_dtor, 0);
236238

237239
zend_ini_entry *ini_entry;
238240
ZEND_HASH_FOREACH_PTR(EG(modified_ini_directives), ini_entry) {

scripts/ci/verify_image_tags.sh

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)