1010 paths :
1111 - .github/workflows/build-ci-container.yml
1212 - ' .github/workflows/containers/github-action-ci/**'
13+ - ' .github/workflows/build-container/**'
14+ - ' .github/workflows/push-container/**'
1315 pull_request :
1416 paths :
1517 - .github/workflows/build-ci-container.yml
1618 - ' .github/workflows/containers/github-action-ci/**'
19+ - ' .github/workflows/build-container/**'
20+ - ' .github/workflows/push-container/**'
1721
1822jobs :
1923 build-ci-container :
24+ name : Build Container ${{ matrix.container-name }} ${{ (contains(matrix.runs-on, 'arm') && 'ARM64') || 'X64' }}
2025 if : github.repository_owner == 'llvm'
2126 runs-on : ${{ matrix.runs-on }}
2227 strategy :
2328 matrix :
24- include :
25- # The arch names should match the names used on dockerhub.
26- # See https://github.com/docker-library/official-images#architectures-other-than-amd64
27- - arch : amd64
28- runs-on : depot-ubuntu-24.04-16
29- - arch : arm64v8
30- runs-on : depot-ubuntu-24.04-arm-16
29+ runs-on :
30+ - depot-ubuntu-24.04-16
31+ - depot-ubuntu-24.04-arm-16
32+ container-name :
33+ - ' '
34+ - agent
35+ test-command :
36+ - cd $HOME && printf '#include <iostream>\nint main(int argc, char **argv) { std::cout << "Hello\\n"; }' | clang++ -x c++ - && ./a.out | grep Hello
3137 steps :
3238 - name : Checkout LLVM
3339 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3440 with :
35- sparse-checkout : .github/workflows/containers/github-action-ci/
36- # podman is not installed by default on the ARM64 images.
37- - name : Install Podman
38- if : runner.arch == 'ARM64'
39- run : |
40- sudo apt-get install podman
41- - name : Write Variables
42- id : vars
43- run : |
44- tag=$(git rev-parse --short=12 HEAD)
45- container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/${{ matrix.arch }}/ci-ubuntu-24.04"
46- echo "container-name=$container_name" >> $GITHUB_OUTPUT
47- echo "container-name-agent=$container_name-agent" >> $GITHUB_OUTPUT
48- echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT
49- echo "container-name-agent-tag=$container_name-agent:$tag" >> $GITHUB_OUTPUT
50- echo "container-filename=$(echo $container_name:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
51- echo "container-agent-filename=$(echo $container_name-agent:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
52- - name : Build container
53- working-directory : ./.github/workflows/containers/github-action-ci/
54- run : |
55- podman build --target ci-container -t ${{ steps.vars.outputs.container-name-tag }} .
56- podman build --target ci-container-agent -t ${{ steps.vars.outputs.container-name-agent-tag }} .
41+ sparse-checkout : |
42+ .github/workflows/containers/github-action-ci/
43+ .github/workflows/build-container
5744
58- # Save the container so we have it in case the push fails. This also
59- # allows us to separate the push step into a different job so we can
60- # maintain minimal permissions while building the container.
61- - name : Save container image
62- run : |
63- podman save ${{ steps.vars.outputs.container-name-tag }} > ${{ steps.vars.outputs.container-filename }}
64- podman save ${{ steps.vars.outputs.container-name-agent-tag }} > ${{ steps.vars.outputs.container-agent-filename }}
65-
66- - name : Upload container image
67- uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
45+ - name : Build Container
46+ uses : ./.github/workflows/build-container
6847 with :
69- name : container-${{ matrix.arch }}
70- path : " *.tar"
71- retention-days : 14
72-
73- - name : Test Container
74- run : |
75- for image in ${{ steps.vars.outputs.container-name-tag }}; do
76- # Use --pull=never to ensure we are testing the just built image.
77- podman run --pull=never --rm -it $image /usr/bin/bash -x -c 'cd $HOME && printf '\''#include <iostream>\nint main(int argc, char **argv) { std::cout << "Hello\\n"; }'\'' | clang++ -x c++ - && ./a.out | grep Hello'
78- done
48+ container-name : ci-ubuntu-24.04${{ matrix.container-name && format('-{0}', matrix.container-name)}}
49+ context : .github/workflows/containers/github-action-ci/
50+ dockerfile : .github/workflows/containers/github-action-ci/Dockerfile
51+ target : ci-container${{ matrix.container-name && format('-{0}', matrix.container-name) }}
52+ test-command : ${{ matrix.test-command }}
7953
8054 push-ci-container :
8155 if : github.event_name == 'push'
@@ -87,31 +61,12 @@ jobs:
8761 env :
8862 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
8963 steps :
90- - name : Download container
91- uses : actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
92-
93- - name : Push Container
94- run : |
95- function push_container {
96- image_name=$1
97- latest_name=$(echo $image_name | sed 's/:[a-f0-9]\+$/:latest/g')
98- podman tag $image_name $latest_name
99- echo "Pushing $image_name ..."
100- podman push $image_name
101- echo "Pushing $latest_name ..."
102- podman push $latest_name
103- }
104-
105- podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io
106- for f in $(find . -iname '*.tar'); do
107- image_name=$(podman load -q -i $f | sed 's/Loaded image: //g')
108- push_container $image_name
64+ - name : Checkout LLVM
65+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
66+ with :
67+ sparse-checkout : |
68+ .github/workflows/push-container
10969
110- if echo $image_name | grep '/amd64/'; then
111- # For amd64, create an alias with the arch component removed.
112- # This matches the convention used on dockerhub.
113- default_image_name=$(echo $(dirname $(dirname $image_name))/$(basename $image_name))
114- podman tag $image_name $default_image_name
115- push_container $default_image_name
116- fi
117- done
70+ - uses : ./.github/workflows/push-container
71+ with :
72+ token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments