Skip to content

Commit 63cfc66

Browse files
committed
fixed ci/discover-docker-matrix.sh for ci actions
1 parent ef82c0b commit 63cfc66

2 files changed

Lines changed: 41 additions & 52 deletions

File tree

.github/workflows/docker.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
pull_request: # PRs: build only (no push)
99

1010
concurrency:
11-
group: ghcr-${{ github.ref }} # cancel older runs on same ref
11+
group: ghcr-${{ github.ref }} # cancel older runs on the same ref
1212
cancel-in-progress: true
1313

1414
jobs:
@@ -23,7 +23,7 @@ jobs:
2323
- name: Checkout repository
2424
uses: actions/checkout@v4
2525

26-
# Run the zsh discovery script which writes to $GITHUB_OUTPUT:
26+
# Run the sh discovery script which writes to $GITHUB_OUTPUT:
2727
# - matrix: JSON {"include":[{file,tag,os,latest},...]}
2828
# - image : "ghcr.io/<owner>/gemc"
2929
- id: scan
@@ -39,7 +39,7 @@ jobs:
3939
packages: write # needed to push to GHCR
4040
strategy:
4141
fail-fast: false
42-
# Use the JSON produced by the discover job
42+
# Use the JSON produced by ci/discover-docker-matrix.sh
4343
matrix: ${{ fromJSON(needs.discover.outputs.matrix) }}
4444
steps:
4545
- name: Checkout repository

ci/discover-docker-matrix.sh

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,62 @@
11
#!/usr/bin/env sh
2-
32
# Discover dockerfiles: dockerfiles/Dockerfile-gemc-<tag>-<os>
4-
# Outputs (for GitHub Actions):
5-
# matrix: {"include":[{"file":..., "tag":..., "os":..., "latest":true|false}, ...]}
6-
# image : ghcr.io/<owner>/gemc
3+
# Outputs for GitHub Actions:
4+
# - matrix: {"include":[{"file":..., "tag":..., "os":..., "latest":true|false}, ...]}
5+
# - image : ghcr.io/<owner>/gemc
76
# Works on macOS (BSD utils), Linux, and GHA.
8-
# Example:
9-
# GITHUB_REPOSITORY_OWNER="gemc" ./ci/discover-docker-matrix.sh
107

118
set -eu
129

1310
DIR="${1:-dockerfiles}"
1411

15-
# Lowercase owner without bash-4 features
16-
OWNER="${GITHUB_REPOSITORY_OWNER:-unknown}"
12+
# Determine owner (prefer GITHUB_REPOSITORY_OWNER; fallback to GITHUB_REPOSITORY)
13+
OWNER="${GITHUB_REPOSITORY_OWNER:-}"
14+
if [ -z "$OWNER" ] && [ -n "${GITHUB_REPOSITORY:-}" ]; then
15+
OWNER="${GITHUB_REPOSITORY%%/*}"
16+
fi
17+
[ -z "$OWNER" ] && OWNER="unknown"
1718
OWNER_LOWER=$(printf '%s' "$OWNER" | tr '[:upper:]' '[:lower:]')
1819
IMAGE="ghcr.io/$OWNER_LOWER/gemc"
1920

20-
# Collect matches (handle spaces via NUL separators)
2121
TMP_TSV="$(mktemp)"
22-
FOUND=0
23-
# macOS/BSD find supports -print0; if not, fall back without it
24-
if find "$DIR" -type f -name 'Dockerfile-gemc-*' -print0 >/dev/null 2>&1; then
25-
find "$DIR" -type f -name 'Dockerfile-gemc-*' -print0 \
26-
| while IFS= read -r -d '' F; do
27-
FOUND=$((FOUND+1)) # this won't persist outside subshell; we’ll recount later
28-
BASE=$(basename "$F") # Dockerfile-gemc-dev3-ubuntu24
29-
REST=${BASE#Dockerfile-} # gemc-dev3-ubuntu24
30-
case "$REST" in
31-
gemc-*-*) : ;;
32-
*) continue ;;
33-
esac
34-
REST2=${REST#gemc-} # dev3-ubuntu24
35-
TAG=${REST2%%-*} # dev3
36-
OS=${REST2#*-} # ubuntu24 (may contain dashes)
37-
# trailing number as weight (dev3 -> 3; dev -> 0)
38-
DIGITS=$(printf '%s\n' "$TAG" | sed -n 's/.*\([0-9][0-9]*\)$/\1/p')
39-
[ -z "$DIGITS" ] && DIGITS=0
40-
printf '%s\t%s\t%s\t%s\n' "$F" "$TAG" "$OS" "$DIGITS" >> "$TMP_TSV"
41-
done
42-
else
43-
# Fallback (no -print0)
44-
find "$DIR" -type f -name 'Dockerfile-gemc-*' \
45-
| while IFS= read -r F; do
46-
BASE=$(basename "$F")
47-
REST=${BASE#Dockerfile-}
48-
case "$REST" in
49-
gemc-*-*) : ;;
50-
*) continue ;;
51-
esac
52-
REST2=${REST#gemc-}
53-
TAG=${REST2%%-*}
54-
OS=${REST2#*-}
55-
DIGITS=$(printf '%s\n' "$TAG" | sed -n 's/.*\([0-9][0-9]*\)$/\1/p')
56-
[ -z "$DIGITS" ] && DIGITS=0
57-
printf '%s\t%s\t%s\t%s\n' "$F" "$TAG" "$OS" "$DIGITS" >> "$TMP_TSV"
58-
done
22+
23+
# Glob-based enumeration (portable; avoids read -d / -print0)
24+
set -- "$DIR"/Dockerfile-gemc-*
25+
if [ "$1" = "$DIR/Dockerfile-gemc-*" ]; then
26+
echo "No matching dockerfiles found under '$DIR' (expected Dockerfile-gemc-<tag>-<os>)." >&2
27+
echo "[local] matrix={\"include\":[]}"
28+
echo "[local] image=$IMAGE"
29+
exit 1
5930
fi
6031

32+
for F in "$@"; do
33+
[ -f "$F" ] || continue
34+
BASE=${F##*/} # Dockerfile-gemc-dev3-ubuntu24
35+
REST=${BASE#Dockerfile-} # gemc-dev3-ubuntu24
36+
case "$REST" in
37+
gemc-*-*) ;;
38+
*) continue ;;
39+
esac
40+
REST2=${REST#gemc-} # dev3-ubuntu24
41+
TAG=${REST2%%-*} # dev3
42+
OS=${REST2#*-} # ubuntu24 (may contain dashes)
43+
44+
# trailing digits in TAG as weight (dev3 -> 3; dev -> 0)
45+
DIGITS=$(printf '%s\n' "$TAG" | sed -n 's/.*\([0-9][0-9]*\)$/\1/p')
46+
[ -z "$DIGITS" ] && DIGITS=0
47+
48+
printf '%s\t%s\t%s\t%s\n' "$F" "$TAG" "$OS" "$DIGITS" >> "$TMP_TSV"
49+
done
50+
6151
# If nothing was written, bail out clearly
6252
if [ ! -s "$TMP_TSV" ]; then
63-
echo "No matching dockerfiles found under '$DIR' (expected Dockerfile-gemc-<tag>-<os>)." >&2
64-
echo "Examples: Dockerfile-gemc-dev3-ubuntu24, Dockerfile-gemc-dev3-fedora40" >&2
53+
echo "No usable dockerfiles after parsing." >&2
6554
echo "[local] matrix={\"include\":[]}"
6655
echo "[local] image=$IMAGE"
6756
exit 1
6857
fi
6958

70-
# Build JSON with BSD/POSIX awk (no non-portable features)
59+
# Build JSON with POSIX/BSD awk
7160
JSON=$(
7261
awk -F '\t' '
7362
BEGIN { n=0 }

0 commit comments

Comments
 (0)