From c8c632a33c2776133bcb264b8098238f77e61728 Mon Sep 17 00:00:00 2001 From: Akif Ejaz Date: Tue, 2 Sep 2025 12:59:25 +0500 Subject: [PATCH] Add riscv native build/release CI --- .github/workflows/go.yml | 11 +++++++++++ .github/workflows/release.yml | 23 +++++++++++++++++++++++ Makefile | 8 +++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1ef2babfd..a47d71f0d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,6 +12,9 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-13, windows-latest] + include: + - os: self-hosted # Add a native RISC-V leg that uses your self-hosted riscv64 runner + runs_on: '["self-hosted","Linux","riscv64"]' runs-on: ${{ matrix.os }} environment: CI steps: @@ -23,8 +26,16 @@ jobs: uses: actions/setup-go@v5 with: go-version: "1.23" + + - name: Install dependencies (for self-hosted only) + if: matrix.os == 'self-hosted' + shell: bash + run: | + sudo apt update + sudo apt install -y make build-essential - name: Unit Test + if: matrix.os != 'self-hosted' run: make test - name: Upload coverage infomartion uses: codecov/codecov-action@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14d7de5bb..dfc667693 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -107,6 +107,29 @@ jobs: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-X 'github.com/aliyun/aliyun-cli/v3/cli.Version=${VERSION}'" -o out/aliyun main/main.go tar zcvf out/aliyun-cli-linux-${VERSION}-arm64.tgz -C out aliyun bash tools/upload_asset.sh ${VERSION} out/aliyun-cli-linux-${VERSION}-arm64.tgz + build_for_linux_riscv64: + needs: [create_release] + name: Native RISC-V Build + runs-on: self-hosted + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + steps: + - uses: actions/checkout@v4 + with: + submodules: true + ref: ${{ github.ref }} + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23' + - name: Build + run: | + TAG=${{ github.ref_name }} + VERSION=${TAG#v} + # build for Linux riscv64 (native) + CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -ldflags "-X 'github.com/aliyun/aliyun-cli/v3/cli.Version=${VERSION}'" -o out/aliyun main/main.go + tar zcvf out/aliyun-cli-linux-${VERSION}-riscv64.tgz -C out aliyun + bash tools/upload_asset.sh ${VERSION} out/aliyun-cli-linux-${VERSION}-riscv64.tgz build_for_windows: needs: [create_release] name: Build for Windows diff --git a/Makefile b/Makefile index 2df94195a..dac4c1707 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ export VERSION=3.0.0-beta export RELEASE_PATH="releases/aliyun-cli-${VERSION}" +ARCH ?= $(shell uname -m) all: build publish: build build_mac build_linux build_windows build_linux_arm64 gen_version @@ -14,7 +15,12 @@ build: deps go build -ldflags "-X 'github.com/aliyun/aliyun-cli/cli.Version=${VERSION}'" -o out/aliyun main/main.go install: build - cp out/aliyun /usr/local/bin + @if [ "$(ARCH)" = "riscv64" ]; then \ + install -d "$(HOME)/.local/bin"; \ + install -m755 out/aliyun "$(HOME)/.local/bin/aliyun"; \ + else \ + install -Dm755 out/aliyun /usr/local/bin/aliyun; \ + fi build_mac: CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X 'github.com/aliyun/aliyun-cli/cli.Version=${VERSION}'" -o out/aliyun main/main.go