forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (102 loc) · 4.05 KB
/
build-ci-container.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Build CI Container
permissions:
contents: read
on:
push:
branches:
- main
paths:
- .github/workflows/build-ci-container.yml
- '.github/workflows/containers/github-action-ci/**'
pull_request:
branches:
- main
paths:
- .github/workflows/build-ci-container.yml
- '.github/workflows/containers/github-action-ci/**'
jobs:
# TODO(boomanaiden154): Switch this back to a single stage build when we can
# run this on the self-hosted runners and don't have to do it this way to
# avoid timeouts.
build-ci-container-stage1:
if: github.repository_owner == 'llvm'
runs-on: ubuntu-latest
steps:
- name: Checkout LLVM
uses: actions/checkout@v4
with:
sparse-checkout: .github/workflows/containers/github-action-ci/
- name: Change podman Root Direcotry
run: |
mkdir -p ~/.config/containers
sudo mkdir -p /mnt/podman
sudo chown `whoami`:`whoami` /mnt/podman
cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf
podman info
- name: Build container stage1
working-directory: ./.github/workflows/containers/github-action-ci/
run: |
podman build -t stage1-toolchain --target stage1-toolchain -f stage1.Dockerfile .
- name: Save container image
run: |
podman save stage1-toolchain > stage1-toolchain.tar
- name: Upload container image
uses: actions/upload-artifact@v4
with:
name: stage1-toolchain
path: stage1-toolchain.tar
retention-days: 1
build-ci-container-stage2:
if: github.repository_owner == 'llvm'
runs-on: ubuntu-latest
needs: build-ci-container-stage1
permissions:
packages: write
steps:
- name: Write Variables
id: vars
run: |
tag=`date +%s`
container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/ci-ubuntu-22.04"
echo "container-name=$container_name" >> $GITHUB_OUTPUT
echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT
- name: Checkout LLVM
uses: actions/checkout@v4
with:
sparse-checkout: .github/workflows/containers/github-action-ci/
- name: Change podman Root Direcotry
run: |
mkdir -p ~/.config/containers
sudo mkdir -p /mnt/podman
sudo chown `whoami`:`whoami` /mnt/podman
cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf
podman info
# Download the container image into /mnt/podman rather than
# $GITHUB_WORKSPACE to avoid space limitations on the default drive
# and use the permissions setup for /mnt/podman.
- name: Download stage1-toolchain
uses: actions/download-artifact@v4
with:
name: stage1-toolchain
path: /mnt/podman
- name: Load stage1-toolchain
run: |
podman load -i /mnt/podman/stage1-toolchain.tar
- name: Build Container
working-directory: ./.github/workflows/containers/github-action-ci/
run: |
podman build -t ${{ steps.vars.outputs.container-name-tag }} -f stage2.Dockerfile .
podman tag ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}:latest
- name: Test Container
run: |
for image in ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}; do
podman run --rm -it $image /usr/bin/bash -x -c 'printf '\''#include <iostream>\nint main(int argc, char **argv) { std::cout << "Hello\\n"; }'\'' | clang++ -x c++ - && ./a.out | grep Hello'
done
- name: Push Container
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io
podman push ${{ steps.vars.outputs.container-name-tag }}
podman push ${{ steps.vars.outputs.container-name }}:latest