|
7 | 7 | push: |
8 | 8 | branches: [ "main" ] |
9 | 9 | 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]+ |
13 | 13 | pull_request: |
14 | 14 | branches: [ "main" ] |
15 | 15 |
|
16 | 16 | env: |
17 | 17 | GO_VERSION: "1.22.5" |
18 | 18 |
|
19 | 19 | 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 | + |
20 | 46 | build-vnpu: |
21 | 47 | runs-on: ubuntu-22.04-arm |
22 | 48 | container: |
23 | 49 | image: ghcr.io/dsfans2014/ascend-device-plugin/ascend-lib:0.2 |
24 | 50 | 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/* |
47 | 73 |
|
48 | 74 | build: |
49 | 75 | env: |
50 | 76 | IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'projecthami/ascend-device-plugin' }} |
51 | 77 | runs-on: ubuntu-latest |
52 | | - needs: ["build-vnpu"] |
| 78 | + needs: [ "build-vnpu", "test" ] |
53 | 79 | 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 |
62 | 88 |
|
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/ |
68 | 94 |
|
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 }} |
75 | 101 |
|
76 | | - - name: Set up QEMU |
77 | | - uses: docker/setup-qemu-action@v3 |
| 102 | + - name: Set up QEMU |
| 103 | + uses: docker/setup-qemu-action@v3 |
78 | 104 |
|
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 |
81 | 107 |
|
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 |
92 | 118 |
|
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 }} |
0 commit comments