Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 121 additions & 97 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,128 +7,152 @@ on:
push:
branches: [ "main" ]
tags:
- v[0-9]+.[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+
pull_request:
branches: [ "main" ]

env:
GO_VERSION: "1.22.5"
GO_VERSION: "1.24.6"

jobs:
lint:
name: lint
runs-on: ubuntu-22.04
steps:
- name: checkout code
uses: actions/checkout@v6
with:
submodules: recursive
- name: install Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: go tidy
env:
GOTOOLCHAIN: auto
run: |
find mind-cluster/component -maxdepth 1 -type d ! -name "npu-exporter" ! -name "ascend-common" ! -name "component" -exec rm -rf {} \;
go mod download github.com/Project-HAMi/HAMi
go get github.com/Project-HAMi/ascend-device-plugin/internal/server
go get huawei.com/npu-exporter
go get huawei.com/npu-exporter/utils/logger@v0.0.0-00010101000000-000000000000
go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
env:
GOTOOLCHAIN: auto
with:
version: v1.64.5
install-mode: binary
args: --timeout=10m
- name: checkout code
uses: actions/checkout@v6
with:
submodules: recursive
- name: install Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: go tidy
env:
GOTOOLCHAIN: auto
run: |
find mind-cluster/component -maxdepth 1 -type d ! -name "npu-exporter" ! -name "ascend-common" ! -name "component" -exec rm -rf {} \;
go mod download github.com/Project-HAMi/HAMi
go get github.com/Project-HAMi/ascend-device-plugin/internal/server
go get huawei.com/npu-exporter
go get huawei.com/npu-exporter/utils/logger@v0.0.0-00010101000000-000000000000
go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
env:
GOTOOLCHAIN: auto
with:
version: v1.64.5
install-mode: binary
args: --timeout=10m

test:
name: Unit test
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Run tests
run: make test
- name: Upload coverage to Codecov
if: ${{ github.repository == 'Project-HAMi/ascend-device-plugin' }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./_output/coverage/coverage.out
flags: unittests
fail_ci_if_error: false
verbose: true

build-vnpu:
runs-on: ubuntu-22.04-arm
container:
image: ghcr.io/dsfans2014/ascend-device-plugin/ascend-lib:0.2
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release
working-directory: ./libvnpu
- name: Prepare artifacts for upload
run: |
mkdir -p ./artifacts
cp libvnpu/target/release/limiter ./artifacts/
cp libvnpu/target/release/libvnpu.so ./artifacts/
echo "/hami-vnpu-core/libvnpu.so" > ./artifacts/ld.so.preload
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
if-no-files-found: error
path: ./artifacts/*
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release
working-directory: ./libvnpu
- name: Prepare artifacts for upload
run: |
mkdir -p ./artifacts
cp libvnpu/target/release/limiter ./artifacts/
cp libvnpu/target/release/libvnpu.so ./artifacts/
echo "/hami-vnpu-core/libvnpu.so" > ./artifacts/ld.so.preload
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
if-no-files-found: error
path: ./artifacts/*

build:
env:
IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'projecthami/ascend-device-plugin' }}
runs-on: ubuntu-latest
needs: ["build-vnpu"]
needs: [ "build-vnpu", "test" ]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
submodules: true
- name: Get branch names.
id: branch-names
uses: tj-actions/branch-names@v8
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
submodules: true

- name: Get branch names.
id: branch-names
uses: tj-actions/branch-names@v8

- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: ./lib/hami-vnpu-core/
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: ./lib/hami-vnpu-core/

- name: Docker Login
if: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
uses: docker/login-action@v3.6.0
with:
username: ${{ secrets.DOCKERHUB_TOKEN }}
password: ${{ secrets.DOCKERHUB_PASSWD }}
- name: Docker Login
if: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
uses: docker/login-action@v3.6.0
with:
username: ${{ secrets.DOCKERHUB_TOKEN }}
password: ${{ secrets.DOCKERHUB_PASSWD }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract tag name
id: tag
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAG_NAME="${GITHUB_REF#refs/tags/}"
echo "VERSION=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "Extracted version: ${VERSION}"
else
echo "VERSION=latest" >> $GITHUB_OUTPUT
fi
- name: Extract tag name
id: tag
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAG_NAME="${GITHUB_REF#refs/tags/}"
echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT
echo "Extracted version: ${VERSION}"
else
echo "VERSION=latest" >> $GITHUB_OUTPUT
fi

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
build-args: |
BASE_IMAGE=ubuntu:20.04
GO_VERSION=${{ env.GO_VERSION }}
VERSION=${{ steps.branch-names.outputs.current_branch || steps.branch-names.outputs.tag }}-${{ github.sha }}
tags: ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.VERSION }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }}
build-args: |
BASE_IMAGE=ubuntu:20.04
GO_VERSION=${{ env.GO_VERSION }}
VERSION=${{ steps.branch-names.outputs.current_branch || steps.branch-names.outputs.tag }}-${{ github.sha }}
tags: ${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.VERSION }}
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ all: ascend-device-plugin
tidy:
$(GO) mod tidy

test:
$(GO) test -v ./internal/...

docker:
docker build \
--build-arg BASE_IMAGE=ubuntu:20.04 \
Expand All @@ -24,4 +27,4 @@ ascend-device-plugin:
clean:
rm -rf ./ascend-device-plugin

.PHONY: all clean
.PHONY: all tidy test lint clean
20 changes: 19 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ require (
huawei.com/npu-exporter v0.0.0-00010101000000-000000000000
k8s.io/api v0.33.0
k8s.io/apimachinery v0.33.0
k8s.io/client-go v0.33.0
k8s.io/klog/v2 v2.130.1
k8s.io/kubelet v0.31.3
)

require (
github.com/NVIDIA/go-gpuallocator v0.6.0 // indirect
github.com/NVIDIA/go-nvlib v0.7.4 // indirect
github.com/NVIDIA/go-nvml v0.12.9-0 // indirect
github.com/NVIDIA/k8s-device-plugin v0.17.3 // indirect
github.com/NVIDIA/nvidia-container-toolkit v1.18.0-rc.2 // indirect
github.com/ccoveille/go-safecast v1.6.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.3 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
Expand All @@ -27,17 +34,26 @@ require (
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/influxdata/telegraf v1.26.3 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/runtime-spec v1.2.1 // indirect
github.com/opencontainers/runtime-tools v0.9.1-0.20221107090550-2e043c6bd626 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/spf13/pflag v1.0.7 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/urfave/cli/v2 v2.27.7 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sys v0.35.0 // indirect
Expand All @@ -48,14 +64,16 @@ require (
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/client-go v0.33.0 // indirect
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
tags.cncf.io/container-device-interface v1.0.1 // indirect
tags.cncf.io/container-device-interface/specs-go v1.0.0 // indirect
)

replace (
Expand Down
Loading
Loading