@@ -4,7 +4,7 @@ name: GHCR Images
44on :
55 push :
66 branches : [ main ] # publish on main updates
7- tags : [ 'v*' ] # (optional) also publish on repo tags
7+ tags : [ 'v*' ] # (optional) also publish on repo tags
88 pull_request : # PRs: build only (no push)
99
1010concurrency :
1818 # Expose the step outputs to downstream jobs
1919 outputs :
2020 matrix : ${{ steps.scan.outputs.matrix }}
21- image : ${{ steps.scan.outputs.image }}
21+ image : ${{ steps.scan.outputs.image }}
2222 steps :
2323 - name : Checkout repository
2424 uses : actions/checkout@v4
2828 # - image : "ghcr.io/<owner>/gemc"
2929 - id : scan
3030 name : Build matrix
31- run : ci/discover-docker-matrix.zsh
31+ run : ci/discover-docker-matrix.sh
3232
3333 build :
3434 name : Build ${{ matrix.tag }} on ${{ matrix.os }}
8888 labels : ${{ steps.meta.outputs.labels }}
8989 cache-from : type=gha
9090 cache-to : type=gha,mode=max
91+
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' }}
95+ uses : docker/build-push-action@v6
96+ with :
97+ context : .
98+ 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 }}
103+ labels : ${{ steps.meta.outputs.labels }}
104+ cache-from : type=gha
105+ cache-to : type=gha,mode=max
106+
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
120+
121+ # Extract logs from the built image (local on PRs, pull on main/tags)
122+ - name : Extract /root/src/logs from image
123+ if : ${{ always() }}
124+ env :
125+ IMG : ${{ needs.discover.outputs.image }}:gemc-${{ matrix.tag }}-${{ matrix.os }}
126+ run : |
127+ set -euo pipefail
128+ mkdir -p ci-logs
129+
130+ # If image isn't local (e.g., main build), try pulling it
131+ 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
134+ fi
135+
136+ if docker image inspect "$IMG" >/dev/null 2>&1; then
137+ cid="$(docker create "$IMG" true || true)"
138+ if [ -n "${cid:-}" ]; then
139+ docker cp "$cid":/root/src/logs/. ci-logs/ 2>/dev/null || true
140+ docker rm -v "$cid" >/dev/null 2>&1 || true
141+ fi
142+ else
143+ echo "Image unavailable (likely build failed before image existed)."
144+ fi
145+
146+ ls -l ci-logs || true
147+
148+ - name : Upload build logs artifact
149+ if : ${{ always() }}
150+ uses : actions/upload-artifact@v4
151+ with :
152+ name : logs-${{ matrix.tag }}-${{ matrix.os }}
153+ path : |
154+ ci-logs/setup.log
155+ ci-logs/build.log
156+ ci-logs/test.log
157+ if-no-files-found : ignore
158+ retention-days : 14
0 commit comments