Skip to content

Commit ed12cdb

Browse files
author
houyuxi
committed
ci: add test jobs
Signed-off-by: houyuxi <yuxi.hou@transwarp.io>
1 parent f14c9d2 commit ed12cdb

2 files changed

Lines changed: 100 additions & 71 deletions

File tree

.github/workflows/ci.yml

Lines changed: 96 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,97 +7,123 @@ on:
77
push:
88
branches: [ "main" ]
99
tags:
10-
- v[0-9]+.[0-9]+.[0-9]+.[0-9]+
11-
- v[0-9]+.[0-9]+.[0-9]+
12-
- v[0-9]+.[0-9]+
10+
- v[0-9]+.[0-9]+.[0-9]+.[0-9]+
11+
- v[0-9]+.[0-9]+.[0-9]+
12+
- v[0-9]+.[0-9]+
1313
pull_request:
1414
branches: [ "main" ]
1515

1616
env:
1717
GO_VERSION: "1.22.5"
1818

1919
jobs:
20+
test:
21+
name: Unit test
22+
runs-on: ubuntu-22.04
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
submodules: recursive
28+
- name: Install Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version: ${{ env.GO_VERSION }}
32+
- name: Go tidy
33+
run: make tidy
34+
- name: Run tests
35+
run: make test
36+
- name: Upload coverage to Codecov
37+
if: ${{ github.repository == 'Project-HAMi/ascend-device-plugin' }}
38+
uses: codecov/codecov-action@v4
39+
with:
40+
token: ${{ secrets.CODECOV_TOKEN }}
41+
files: ./_output/coverage/coverage.out
42+
flags: unittests
43+
fail_ci_if_error: false
44+
verbose: true
45+
2046
build-vnpu:
2147
runs-on: ubuntu-22.04-arm
2248
container:
2349
image: ghcr.io/dsfans2014/ascend-device-plugin/ascend-lib:0.2
2450
steps:
25-
- uses: actions/checkout@v4
26-
with:
27-
submodules: recursive
28-
- name: Install Rust
29-
uses: dtolnay/rust-toolchain@stable
30-
- name: Cache cargo
31-
uses: Swatinem/rust-cache@v2
32-
- name: Build
33-
run: cargo build --release
34-
working-directory: ./libvnpu
35-
- name: Prepare artifacts for upload
36-
run: |
37-
mkdir -p ./artifacts
38-
cp libvnpu/target/release/limiter ./artifacts/
39-
cp libvnpu/target/release/libvnpu.so ./artifacts/
40-
echo "/hami-vnpu-core/libvnpu.so" > ./artifacts/ld.so.preload
41-
- name: upload artifacts
42-
uses: actions/upload-artifact@v4
43-
with:
44-
name: build-artifacts
45-
if-no-files-found: error
46-
path: ./artifacts/*
51+
- uses: actions/checkout@v4
52+
with:
53+
submodules: recursive
54+
- name: Install Rust
55+
uses: dtolnay/rust-toolchain@stable
56+
- name: Cache cargo
57+
uses: Swatinem/rust-cache@v2
58+
- name: Build
59+
run: cargo build --release
60+
working-directory: ./libvnpu
61+
- name: Prepare artifacts for upload
62+
run: |
63+
mkdir -p ./artifacts
64+
cp libvnpu/target/release/limiter ./artifacts/
65+
cp libvnpu/target/release/libvnpu.so ./artifacts/
66+
echo "/hami-vnpu-core/libvnpu.so" > ./artifacts/ld.so.preload
67+
- name: upload artifacts
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: build-artifacts
71+
if-no-files-found: error
72+
path: ./artifacts/*
4773

4874
build:
4975
env:
5076
IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'projecthami/ascend-device-plugin' }}
5177
runs-on: ubuntu-latest
52-
needs: ["build-vnpu"]
78+
needs: [ "build-vnpu", "test" ]
5379
steps:
54-
- uses: actions/checkout@v4
55-
with:
56-
ref: ${{ github.event.pull_request.head.sha }}
57-
submodules: true
58-
59-
- name: Get branch names.
60-
id: branch-names
61-
uses: tj-actions/branch-names@v8
80+
- uses: actions/checkout@v4
81+
with:
82+
ref: ${{ github.event.pull_request.head.sha }}
83+
submodules: true
84+
85+
- name: Get branch names.
86+
id: branch-names
87+
uses: tj-actions/branch-names@v8
6288

63-
- name: Download Artifacts
64-
uses: actions/download-artifact@v4
65-
with:
66-
name: build-artifacts
67-
path: ./lib/hami-vnpu-core/
89+
- name: Download Artifacts
90+
uses: actions/download-artifact@v4
91+
with:
92+
name: build-artifacts
93+
path: ./lib/hami-vnpu-core/
6894

69-
- name: Docker Login
70-
if: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
71-
uses: docker/login-action@v3.6.0
72-
with:
73-
username: ${{ secrets.DOCKERHUB_TOKEN }}
74-
password: ${{ secrets.DOCKERHUB_PASSWD }}
95+
- name: Docker Login
96+
if: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
97+
uses: docker/login-action@v3.6.0
98+
with:
99+
username: ${{ secrets.DOCKERHUB_TOKEN }}
100+
password: ${{ secrets.DOCKERHUB_PASSWD }}
75101

76-
- name: Set up QEMU
77-
uses: docker/setup-qemu-action@v3
102+
- name: Set up QEMU
103+
uses: docker/setup-qemu-action@v3
78104

79-
- name: Set up Docker Buildx
80-
uses: docker/setup-buildx-action@v3
105+
- name: Set up Docker Buildx
106+
uses: docker/setup-buildx-action@v3
81107

82-
- name: Extract tag name
83-
id: tag
84-
run: |
85-
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
86-
TAG_NAME="${GITHUB_REF#refs/tags/}"
87-
echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT
88-
echo "Extracted version: ${VERSION}"
89-
else
90-
echo "VERSION=latest" >> $GITHUB_OUTPUT
91-
fi
108+
- name: Extract tag name
109+
id: tag
110+
run: |
111+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
112+
TAG_NAME="${GITHUB_REF#refs/tags/}"
113+
echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT
114+
echo "Extracted version: ${VERSION}"
115+
else
116+
echo "VERSION=latest" >> $GITHUB_OUTPUT
117+
fi
92118
93-
- name: Build and push
94-
uses: docker/build-push-action@v6
95-
with:
96-
context: .
97-
platforms: linux/amd64,linux/arm64
98-
push: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
99-
build-args: |
100-
BASE_IMAGE=ubuntu:20.04
101-
GO_VERSION=${{ env.GO_VERSION }}
102-
VERSION=${{ steps.branch-names.outputs.current_branch || steps.branch-names.outputs.tag }}-${{ github.sha }}
103-
tags: ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.VERSION }}
119+
- name: Build and push
120+
uses: docker/build-push-action@v6
121+
with:
122+
context: .
123+
platforms: linux/amd64,linux/arm64
124+
push: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
125+
build-args: |
126+
BASE_IMAGE=ubuntu:20.04
127+
GO_VERSION=${{ env.GO_VERSION }}
128+
VERSION=${{ steps.branch-names.outputs.current_branch || steps.branch-names.outputs.tag }}-${{ github.sha }}
129+
tags: ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.VERSION }}

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ all: ascend-device-plugin
88
tidy:
99
$(GO) mod tidy
1010

11+
test:
12+
$(GO) test -v -coverprofile=_output/coverage/coverage.out ./...
13+
1114
docker:
1215
docker build \
1316
--build-arg BASE_IMAGE=ubuntu:20.04 \
@@ -24,4 +27,4 @@ ascend-device-plugin:
2427
clean:
2528
rm -rf ./ascend-device-plugin
2629

27-
.PHONY: all clean
30+
.PHONY: all tidy test lint clean

0 commit comments

Comments
 (0)