diff --git a/.github/actions/setup-go/action.yaml b/.github/actions/setup-go/action.yaml index a3abe8478d11..3b086207b047 100644 --- a/.github/actions/setup-go/action.yaml +++ b/.github/actions/setup-go/action.yaml @@ -16,6 +16,20 @@ runs: env: GH_TOKEN: ${{ github.token }} + - name: Setup Go cache key + id: gocache-key + shell: bash + run: | + echo "key=${{ github.workflow }}-$(uname -m)-gocache-${{ github.sha }}" >> $GITHUB_OUTPUT + echo "restore-keys=${{ github.workflow }}-$(uname -m)-gocache" >> $GITHUB_OUTPUT + + - name: Setup Go cache # must be done before Setup Go so it picks up the cache + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + key: ${{ steps.gocache-key.outputs.key }} + restore-keys: ${{ steps.gocache-key.outputs.restore-keys }} + path: /home/runner/.cache/go-build + - name: Setup Go uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6 with: diff --git a/.github/workflows/build-k3s.yaml b/.github/workflows/build-k3s.yaml index b64a4723b8b7..d9ff78f9d0a0 100644 --- a/.github/workflows/build-k3s.yaml +++ b/.github/workflows/build-k3s.yaml @@ -3,7 +3,7 @@ on: inputs: arch: type: string - description: 'Architecture to build (amd64, arm64, or arm)' + description: 'Architecture to build (amd64, arm64, arm, or riscv64)' default: 'amd64' os: type: string @@ -26,8 +26,8 @@ permissions: jobs: build: name: Build # DO NOT CHANGE THIS NAME, we rely on it for INSTALL_K3S_PR functionality - runs-on: ${{ contains(inputs.arch, 'arm') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} - timeout-minutes: 20 + runs-on: ${{ (contains(inputs.arch, 'riscv') && 'ubuntu-24.04-riscv') || (contains(inputs.arch, 'arm') && 'ubuntu-24.04-arm') || 'ubuntu-24.04' }} + timeout-minutes: ${{ (contains(inputs.arch, 'riscv') && 180) || 20 }} env: BIN_EXT: ${{ inputs.os == 'windows' && '.exe' || '' }} ARCH_EXT: ${{ inputs.os == 'windows' && '-windows' || format('-{0}', inputs.arch) }} @@ -43,6 +43,7 @@ jobs: cache-image: false - name: Set up Docker + if: inputs.arch != 'riscv64' uses: docker/setup-docker-action@1a6edb0ba9ac496f6850236981f15d8f9a82254d # v5 with: version: type=image,tag=28 @@ -64,7 +65,7 @@ jobs: } >> "$GITHUB_OUTPUT" - name: Build K3s Binary Native - if: inputs.arch == 'arm64' || inputs.arch == 'amd64' + if: inputs.arch == 'arm64' || inputs.arch == 'amd64' || inputs.arch == 'riscv64' env: DOCKER_BUILD_SUMMARY: false uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7 @@ -83,9 +84,13 @@ jobs: push: false provenance: mode=min outputs: type=local,dest=. + cache-from: | + ${{ format('type=gha,scope=k3s-binary-{0}-{1}', inputs.os, inputs.arch) }} + cache-to: | + ${{ github.ref_name == github.event.repository.default_branch && format('type=gha,scope=k3s-binary-{0}-{1},mode=max', inputs.os, inputs.arch) || '' }} - name: Build K3s Binary Emulated - if: inputs.arch != 'arm64' && inputs.arch != 'amd64' + if: inputs.arch != 'arm64' && inputs.arch != 'amd64' && inputs.arch != 'riscv64' env: PLATFORM: ${{ inputs.arch == 'arm' && 'linux/arm/v7' || format('linux/{0}', inputs.arch) }} DOCKER_BUILD_SUMMARY: false @@ -103,6 +108,10 @@ jobs: provenance: mode=min platforms: ${{ env.PLATFORM }} outputs: type=local,dest=. + cache-from: | + ${{ format('type=gha,scope=k3s-binary-{0}-{1}', inputs.os, inputs.arch) }} + cache-to: | + ${{ github.ref_name == github.event.repository.default_branch && format('type=gha,scope=k3s-binary-{0}-{1},mode=max', inputs.os, inputs.arch) || '' }} - name: Caculate binary checksum run: | @@ -115,7 +124,7 @@ jobs: fi - name: Build K3s image - if: inputs.upload-image == true && inputs.os == 'linux' && (inputs.arch == 'amd64' || inputs.arch == 'arm64') + if: inputs.upload-image == true && inputs.os == 'linux' && (inputs.arch == 'amd64' || inputs.arch == 'arm64' || inputs.arch == 'riscv64') run: ./scripts/package-image - name: "Save K3s image" diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index bf90bc10ffd8..89622b7dcd26 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -43,6 +43,14 @@ jobs: with: arch: arm64 upload-image: true + build-riscv64: + uses: ./.github/workflows/build-k3s.yaml + permissions: + contents: read + packages: write + with: + arch: riscv64 + upload-image: true e2e: name: "E2E Tests" needs: build @@ -148,8 +156,8 @@ jobs: name: "Build Go Tests" strategy: matrix: - arch: [amd64, arm64] - runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }} + arch: [amd64, arm64, riscv64] + runs-on: ${{ (matrix.arch == 'riscv64' && 'ubuntu-24.04-riscv') || (matrix.arch == 'arm64' && 'ubuntu-24.04-arm') || 'ubuntu-latest' }} outputs: channel: ${{ steps.channel_step.outputs.channel }} steps: @@ -185,14 +193,14 @@ jobs: fi docker-go: - needs: [build, build-arm64, build-go-tests] + needs: [build, build-arm64, build-riscv64, build-go-tests] name: Docker timeout-minutes: 30 strategy: fail-fast: false matrix: dtest: [autoimport, basics, bootstraptoken, cacerts, dualstack, etcd, hardened, lazypull, nixsnapshotter, skew, secretsencryption, snapshotrestore, svcpoliciesandfirewall, token, upgrade] - arch: [amd64, arm64] + arch: [amd64, arm64, riscv64] exclude: - dtest: autoimport arch: arm64 @@ -206,7 +214,9 @@ jobs: arch: arm64 - dtest: svcpoliciesandfirewall arch: arm64 - runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }} + - dtest: nixsnapshotter + arch: riscv64 + runs-on: ${{ (matrix.arch == 'riscv64' && 'ubuntu-24.04-riscv') || (matrix.arch == 'arm64' && 'ubuntu-24.04-arm') || 'ubuntu-latest' }} env: CHANNEL: ${{ needs.build-go-tests.outputs.channel }} steps: @@ -238,6 +248,7 @@ jobs: path: ./dist/artifacts - name: Set up Docker uses: docker/setup-docker-action@1a6edb0ba9ac496f6850236981f15d8f9a82254d # v5 + if: matrix.arch != 'riscv64' with: version: type=image,tag=28 daemon-config: '{"features":{"containerd-snapshotter":true}}' @@ -246,6 +257,8 @@ jobs: run: | if [ ${{ matrix.arch }} = "arm64" ]; then mv ./dist/artifacts/k3s-arm64 ./dist/artifacts/k3s + elif [ ${{ matrix.arch }} = "riscv64" ]; then + mv ./dist/artifacts/k3s-riscv64 ./dist/artifacts/k3s fi chmod +x ./dist/artifacts/k3s docker image load -i ./dist/artifacts/k3s-image.tar