Skip to content

Commit 5dfba80

Browse files
authored
Fix CI for tagged releases (#11)
* Handle multiple tags on release - When tagging a release both the tag and the `latest` will be in `needs.build.outputs.image`. - Iterate over them and test both. * Upadte actions/download-artifact to v6 * Don't push to GHCR on PRs
1 parent 936475d commit 5dfba80

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

.github/workflows/build.yml

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ jobs:
2525
id: meta
2626
uses: docker/metadata-action@v5
2727
with:
28-
# Use GitHub Container Registry (ghcr) so the image can be pushed from the workflow
29-
images: ghcr.io/OpenModelica/crossbuild
28+
images: ghcr.io/openmodelica/crossbuild
3029

3130
- name: Log in to GitHub Container Registry
3231
uses: docker/login-action@v3
@@ -43,7 +42,23 @@ jobs:
4342
file: ./Dockerfile
4443
tags: ${{ steps.meta.outputs.tags }}
4544
annotations: ${{ steps.meta.outputs.annotations }}
46-
push: true
45+
# Only push when this is NOT a pull_request (avoid GHCR write for PRs)
46+
push: ${{ github.event_name != 'pull_request' }}
47+
48+
- name: Save image as tar for pull_request runs
49+
if: github.event_name == 'pull_request'
50+
run: |
51+
# pick first tag from metadata (comma separated)
52+
img="${{ steps.meta.outputs.tags }}"
53+
img="${img%%,*}"
54+
docker save -o crossbuild-image.tar "$img"
55+
56+
- name: Upload image artifact for pull_request runs
57+
if: github.event_name == 'pull_request'
58+
uses: actions/upload-artifact@v5
59+
with:
60+
name: crossbuild-image
61+
path: crossbuild-image.tar
4762

4863
outputs:
4964
image: ${{ steps.meta.outputs.tags }}
@@ -90,9 +105,23 @@ jobs:
90105
password: ${{ secrets.GITHUB_TOKEN }}
91106

92107
- name: Pull image pushed by build job
108+
if: github.event_name != 'pull_request'
93109
shell: bash
94110
run: |
95-
docker pull "${{ needs.build.outputs.image }}"
111+
for img in ${{ needs.build.outputs.image }}; do
112+
docker pull "$img"
113+
done
114+
115+
- name: Download and load image artifact for pull_request runs
116+
if: github.event_name == 'pull_request'
117+
uses: actions/download-artifact@v6
118+
with:
119+
name: crossbuild-image
120+
path: ./image
121+
122+
- name: Load image for pull_request runs
123+
if: github.event_name == 'pull_request'
124+
run: docker load -i ./image/crossbuild-image.tar
96125

97126
- name: Test cross-compilation for matrix toolchain
98127
shell: bash
@@ -101,18 +130,21 @@ jobs:
101130
FMI_PLATFORM_TUPLE: ${{ matrix.fmi_platform_tuple }}
102131
LIB_EXTENSION: ${{ matrix.lib_extension }}
103132
run: |
104-
docker run --rm \
105-
-v "${{ github.workspace }}":/work \
106-
-w /work \
107-
"${{ needs.build.outputs.image }}" \
108-
bash -lc "\
109-
cmake -S test/resources/FMU_Interaction1/sources \
110-
-B test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} \
111-
-DFMI_INTERFACE_HEADER_FILES_DIRECTORY=/work/test/resources/fmi \
112-
-DCMAKE_TOOLCHAIN_FILE=/opt/cmake/toolchain/${TOOLCHAIN}.cmake && \
113-
cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target install && \
114-
test -f test/resources/FMU_Interaction1/binaries/${FMI_PLATFORM_TUPLE}/Interaction1.${LIB_EXTENSION} && \
115-
cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target create_fmu"
133+
IMAGES="${{ needs.build.outputs.image }}"
134+
for img in $IMAGES; do
135+
docker run --rm \
136+
-v "${{ github.workspace }}":/work \
137+
-w /work \
138+
"$img" \
139+
bash -lc "\
140+
cmake -S test/resources/FMU_Interaction1/sources \
141+
-B test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} \
142+
-DFMI_INTERFACE_HEADER_FILES_DIRECTORY=/work/test/resources/fmi \
143+
-DCMAKE_TOOLCHAIN_FILE=/opt/cmake/toolchain/${TOOLCHAIN}.cmake && \
144+
cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target install && \
145+
test -f test/resources/FMU_Interaction1/binaries/${FMI_PLATFORM_TUPLE}/Interaction1.${LIB_EXTENSION} && \
146+
cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target create_fmu"
147+
done
116148
117149
- name: Upload Interaction1.fmu
118150
uses: actions/upload-artifact@v5
@@ -137,7 +169,7 @@ jobs:
137169
timeout-minutes: 30
138170
steps:
139171
- name: Download Interaction1.fmu
140-
uses: actions/download-artifact@v5
172+
uses: actions/download-artifact@v6
141173
with:
142174
name: ${{ matrix.fmu_artifact }}
143175

0 commit comments

Comments
 (0)