Skip to content

Commit 66dbb00

Browse files
committed
Add test and lint workflow
Signed-off-by: Alexey Fomenko <alexey.fomenko@intel.com>
1 parent 43e8dd7 commit 66dbb00

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

.github/scripts/coverage_check.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
RESULT=$(make "$1" | awk '/total:/ {print ($3+0)}')
5+
6+
if (( $(echo "$RESULT > $2" | bc -l) )); then
7+
echo "$1 $RESULT% is above threshold $2%"
8+
exit 0
9+
else
10+
echo "$1 $RESULT% is below threshold $2%. Add more tests!"
11+
exit 1
12+
fi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Run lint and tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
pull-requests: read
11+
12+
jobs:
13+
test-containerized:
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Build test image
19+
run: make test-image
20+
- name: Run lint in container
21+
run: make lint-containerized
22+
- name: Run tests in container
23+
run: TEST_TARGET=coverage-check make test-containerized

Dockerfile.gaudi-test

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,28 @@ COPY --from=go --chown=${UID}:${GID} /usr/local/go /home/ubuntu/go
2121
# add xpu-smi shared library for GPU tests and other dependencies
2222
RUN \
2323
apt-get update && \
24-
apt-get install -y make gcc wget software-properties-common python3-launchpadlib git && \
24+
apt-get install -y make gcc wget software-properties-common python3-launchpadlib git yamllint shellcheck bc && \
2525
add-apt-repository -y ppa:kobuk-team/intel-graphics && \
2626
apt-get update && \
2727
apt-get install -y libze-intel-gpu1 libze1 intel-metrics-discovery intel-opencl-icd clinfo intel-gsc && \
2828
wget -qO /tmp/xpu-smi.deb https://github.com/intel/xpumanager/releases/download/V1.3.1/xpu-smi_1.3.1_20250724.061629.60921e5e_u24.04_amd64.deb && \
2929
apt-get install -y /tmp/xpu-smi.deb && \
3030
rm /tmp/xpu-smi.deb && \
31-
unset http_proxy https_proxy no_proxy && \
32-
echo 'export PATH=/home/ubuntu/go/bin:$PATH' >> /home/ubuntu/.bashrc
31+
echo 'export PATH=/home/ubuntu/go/bin:$PATH' >> /home/ubuntu/.bashrc && \
32+
wget -q https://github.com/golangci/golangci-lint/releases/download/v2.7.2/golangci-lint-2.7.2-linux-amd64.tar.gz && \
33+
tar zxf golangci-lint-2.7.2-linux-amd64.tar.gz --strip-components=1 golangci-lint-2.7.2-linux-amd64/golangci-lint && \
34+
mv golangci-lint /usr/local/bin/golangci-lint && \
35+
rm golangci-lint-2.7.2-linux-amd64.tar.gz && \
36+
unset http_proxy https_proxy no_proxy
3337

3438
RUN \
3539
mkdir /github && \
3640
chmod 777 /github && \
3741
mkdir /home/ubuntu/src && \
3842
chown -R ${UID}:${GID} /home/ubuntu
3943

44+
ENV GOLANGCI_LINT_CACHE=/home/ubuntu/.lint-cache
45+
ENV GOROOT=/home/ubuntu/go
4046
ENV GOCACHE=/home/ubuntu/.cache/go-build
4147
ENV GOMODCACHE=/home/ubuntu/.cache/go-mod
4248
ENV PATH=/home/ubuntu/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Makefile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,25 @@ licenses: clean-licenses
173173

174174

175175
# linting targets for Go and other code
176-
.PHONY: lint format cilint vet shellcheck yamllint
176+
.PHONY: lint format cilint vet shellcheck yamllint lint-containerized
177177

178-
lint: vendor format cilint vet klogformat shellcheck yamllint
178+
lint-containerized:
179+
$(DOCKER) run \
180+
-e http_proxy=$(http_proxy) \
181+
-e https_proxy=$(https_proxy) \
182+
-e no_proxy=$(no_proxy) \
183+
--user $(shell id -u):$(shell id -g) \
184+
-v "$(shell pwd)":/home/ubuntu/src:rw \
185+
"$(TEST_IMAGE)" \
186+
bash -c "cd src && make lint"
187+
188+
lint: vendor cilint vet klogformat shellcheck yamllint
179189

180190
format:
181191
gofmt -w -s -l ./
182192

183193
cilint:
184-
golangci-lint --max-same-issues 0 --max-issues-per-linter 0 run --timeout 2m0s ./...
194+
golangci-lint --max-same-issues 0 --max-issues-per-linter 0 run --timeout 4m0s ./...
185195

186196
vet:
187197
go vet $(PKG)/...
@@ -261,7 +271,7 @@ TEST_TARGET ?= test
261271

262272
test-containerized:
263273
$(DOCKER) run \
264-
-it -e container=yes \
274+
-e container=yes \
265275
-e http_proxy=$(http_proxy) \
266276
-e https_proxy=$(https_proxy) \
267277
-e no_proxy=$(no_proxy) \
@@ -297,3 +307,9 @@ cdispecsgen-coverage.out: $(shell find cmd/cdi-specs-generator pkg/gpu pkg/gaudi
297307
.PHONY: %-coverage
298308
%-coverage: %-coverage.out
299309
go tool cover -func=$@.out
310+
311+
.PHONY: coverage-check
312+
coverage-check: coverage.out
313+
.github/scripts/coverage_check.sh gpu-coverage 70
314+
.github/scripts/coverage_check.sh gaudi-coverage 70
315+
.github/scripts/coverage_check.sh qat-coverage 70

0 commit comments

Comments
 (0)