-
Notifications
You must be signed in to change notification settings - Fork 25
205 lines (173 loc) · 5.74 KB
/
verify.yml
File metadata and controls
205 lines (173 loc) · 5.74 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Verify
on:
push:
permissions:
contents: read
packages: write
env:
GHCR_IMAGE: ghcr.io/kastnerrg/cgra4ml-ibex
jobs:
build-and-push-image:
runs-on: ubuntu-22.04
outputs:
image_tag: ${{ steps.meta.outputs.image_tag }}
image_exists: ${{ steps.check.outputs.image_exists }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: meta
name: Compute Docker inputs hash -> image tag
shell: bash
run: |
set -euo pipefail
# Only these files affect the image tag. Add/remove paths as desired.
inputs=(
Dockerfile
Makefile
pyproject.toml
ibex-soc/python-requirements.txt
)
tmp="$(mktemp)"
for f in "${inputs[@]}"; do
if [ -f "$f" ]; then
{
echo ">>>FILE:$f"
cat "$f"
echo
} >> "$tmp"
else
echo "WARN: missing $f (ignored)"
fi
done
hash="$(sha256sum "$tmp" | awk '{print $1}')"
short="${hash:0:16}"
tag="ci-${short}"
echo "Computed hash: $hash"
echo "Using tag: $tag"
echo "image_tag=$tag" >> "$GITHUB_OUTPUT"
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: check
name: Check if image tag already exists in GHCR
shell: bash
run: |
set -euo pipefail
tag="${{ steps.meta.outputs.image_tag }}"
if docker manifest inspect "${GHCR_IMAGE}:${tag}" >/dev/null 2>&1; then
echo "Image exists: ${GHCR_IMAGE}:${tag}"
echo "image_exists=true" >> "$GITHUB_OUTPUT"
else
echo "Image missing: ${GHCR_IMAGE}:${tag}"
echo "image_exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Build Docker image (only if missing)
if: steps.check.outputs.image_exists == 'false'
shell: bash
run: |
set -euo pipefail
tag="${{ steps.meta.outputs.image_tag }}"
# Build using your Makefile; tag directly with the content-hash tag.
make IMAGE="${GHCR_IMAGE}:${tag}" image
# Optional: also tag as "latest" whenever we build a new hash-tag.
docker tag "${GHCR_IMAGE}:${tag}" "${GHCR_IMAGE}:latest"
- name: Push image to GHCR (only if built)
if: steps.check.outputs.image_exists == 'false'
shell: bash
run: |
set -euo pipefail
tag="${{ steps.meta.outputs.image_tag }}"
docker push "${GHCR_IMAGE}:${tag}"
docker push "${GHCR_IMAGE}:latest"
smoke-test:
runs-on: ubuntu-22.04
needs: build-and-push-image
env:
IMAGE_TAG: ${{ needs.build-and-push-image.outputs.image_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Free disk space on runner
run: |
echo "Before cleanup:"; df -h
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true
sudo apt-get clean || true
sudo rm -rf /var/lib/apt/lists/* || true
docker system prune -af || true
echo "After cleanup:"; df -h
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull CI image
run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}"
- name: Smoke test (example.py)
run: |
docker run --rm \
-v "$PWD":/work \
-e PYTHONPATH=/work \
-w /work \
"${GHCR_IMAGE}:${IMAGE_TAG}" \
bash -c '
python -m pip install -e /work --no-deps
mkdir -p run/work
cd run/work
python ../example.py
'
test:
runs-on: ubuntu-22.04
needs: [build-and-push-image, smoke-test]
env:
IMAGE_TAG: ${{ needs.build-and-push-image.outputs.image_tag }}
strategy:
fail-fast: false
matrix:
include:
- name: param_test
cmd: make smoke_test TEST=param_test
- name: pointnet
cmd: make smoke_test TEST=pointnet
# - name: resnet50
# cmd: make smoke_test TEST=resnet50
# - name: resnet18
# cmd: make smoke_test TEST=resnet18
- name: jettagger
cmd: make smoke_test TEST=jettagger
- name: verify-ibex-soc
cmd: |
fusesoc library add sa_ip "$(pwd -P)" || true
make smoke_ibex
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Free disk space on runner
run: |
echo "Before cleanup:"; df -h
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true
sudo apt-get clean || true
sudo rm -rf /var/lib/apt/lists/* || true
docker system prune -af || true
echo "After cleanup:"; df -h
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull CI image
run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}"
- name: Run ${{ matrix.name }}
run: |
docker run --rm \
-e PYTHONPATH=/work \
-v "$PWD":/work \
-w /work \
"${GHCR_IMAGE}:${IMAGE_TAG}" \
bash -c '${{ matrix.cmd }}'