@@ -70,67 +70,62 @@ jobs:
7070 with :
7171 images : ${{ needs.discover.outputs.image }}
7272 tags : |
73- type=raw,value=gemc- ${{ matrix.tag }}-${{ matrix.os }}
74- type=raw,value=gemc- latest-${{ matrix.os }},enable=${{ matrix.latest }}
73+ type=raw,value=${{ matrix.tag }}-${{ matrix.os }}
74+ type=raw,value=latest-${{ matrix.os }},enable=${{ matrix.latest }}
7575 labels : |
7676 org.opencontainers.image.source=${{ github.repository }}
7777 org.opencontainers.image.description=GEMC image (${{ matrix.tag }} on ${{ matrix.os }})
7878
79- # Build on PRs; Build+Push on main/tags; publish multi-arch manifest to GHCR
80- - name : Build (PR) or Build+Push (main/tags)
81- uses : docker/build-push-action@v6
82- with :
83- context : .
84- file : ${{ matrix.file }}
85- platforms : linux/amd64,linux/arm64 # ← multi-arch; change to linux/amd64 if you prefer single-arch
86- push : ${{ github.event_name != 'pull_request' }}
87- tags : ${{ steps.meta.outputs.tags }}
88- labels : ${{ steps.meta.outputs.labels }}
89- cache-from : type=gha
90- cache-to : type=gha,mode=max
79+ # Decide platforms per Dockerfile by inspecting its base image
80+ - name : Decide platforms from Dockerfile base
81+ id : plats
82+ shell : bash
83+ run : |
84+ set -euo pipefail
85+ BASE="$(awk 'toupper($1)=="FROM"{print $2; exit}' "${{ matrix.file }}")"
86+ echo "Base image: $BASE"
87+ if docker buildx imagetools inspect "$BASE" | grep -qE 'manifest\.list|image\.index'; then
88+ PLATS="linux/amd64,linux/arm64"
89+ else
90+ PLATS="linux/amd64"
91+ fi
92+ echo "platforms=$PLATS" >> "$GITHUB_OUTPUT"
9193
92- # Build for PRs: single-arch, load into local Docker so we can copy logs out
93- - name : Build (PR) [load locally]
94- if : ${{ github.event_name == 'pull_request' }}
94+ # Single build step for PRs AND main/tags
95+ - name : Build (PR loads; main/tags push)
9596 uses : docker/build-push-action@v6
9697 with :
9798 context : .
9899 file : ${{ matrix.file }}
99- platforms : linux/amd64 # load:true only supports single arch
100- load : true # <-- makes the image available locally
101- push : false
102- tags : ${{ steps.meta.outputs.tags }}
100+ platforms : ${{ github.event_name == 'pull_request' && 'linux/amd64' || steps.plats.outputs.platforms }}
101+ load : ${{ github.event_name == 'pull_request' }} # PR: load locally for log extraction
102+ push : ${{ github.event_name != 'pull_request' }} # main/tags: push to GHCR
103+ tags : ${{ steps.meta.outputs.tags }} # e.g., ghcr.io/gemc/gemc:dev3-ubuntu24
103104 labels : ${{ steps.meta.outputs.labels }}
104105 cache-from : type=gha
105106 cache-to : type=gha,mode=max
106107
107- # Build & push for main/tags: multi-arch & publish to GHCR
108- - name : Build & Push (main/tags)
109- if : ${{ github.event_name != 'pull_request' }}
110- uses : docker/build-push-action@v6
111- with :
112- context : .
113- file : ${{ matrix.file }}
114- platforms : linux/amd64,linux/arm64
115- push : true
116- tags : ${{ steps.meta.outputs.tags }}
117- labels : ${{ steps.meta.outputs.labels }}
118- cache-from : type=gha
119- cache-to : type=gha,mode=max
120108
121- # Extract logs from the built image (local on PRs, pull on main/tags)
109+
110+ # Extract logs from the built image (use new tag names)
122111 - name : Extract /root/src/logs from image
123112 if : ${{ always() }}
124113 env :
125- IMG : ${{ needs.discover.outputs.image }}:gemc-${{ matrix.tag }}-${{ matrix.os }}
114+ IMG_PRIMARY : ${{ needs.discover.outputs.image }}:${{ matrix.tag }}-${{ matrix.os }}
115+ IMG_LATEST : ${{ needs.discover.outputs.image }}:latest-${{ matrix.os }}
126116 run : |
127117 set -euo pipefail
128118 mkdir -p ci-logs
129119
130- # If image isn't local (e.g., main build), try pulling it
120+ # Prefer the primary tag; fall back to latest-<os> if needed
121+ IMG="$IMG_PRIMARY"
131122 if ! docker image inspect "$IMG" >/dev/null 2>&1; then
132- echo "Image not local; attempting docker pull (PRs will skip)…"
133- docker pull "$IMG" || true
123+ # Not local? try pull (main/tags). If still missing, try the latest alias.
124+ docker pull "$IMG" >/dev/null 2>&1 || true
125+ if ! docker image inspect "$IMG" >/dev/null 2>&1; then
126+ IMG="$IMG_LATEST"
127+ docker pull "$IMG" >/dev/null 2>&1 || true
128+ fi
134129 fi
135130
136131 if docker image inspect "$IMG" >/dev/null 2>&1; then
@@ -145,6 +140,7 @@ jobs:
145140
146141 ls -l ci-logs || true
147142
143+
148144 - name : Upload build logs artifact
149145 if : ${{ always() }}
150146 uses : actions/upload-artifact@v4
0 commit comments