Merge pull request #71 from Project-HAMi/release-v1.3 #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow will build a golang project | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
| name: CI | |
| 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]+ | |
| pull_request: | |
| branches: [ "main" ] | |
| env: | |
| GO_VERSION: "1.22.5" | |
| jobs: | |
| 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/* | |
| build: | |
| env: | |
| IMAGE_NAME: ${{ secrets.IMAGE_NAME || 'projecthami/ascend-device-plugin' }} | |
| runs-on: ubuntu-latest | |
| needs: ["build-vnpu"] | |
| 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 | |
| - 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: Set up QEMU | |
| uses: docker/setup-qemu-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#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 }} |