From cacc2bbb8e96b367bd54fbbd48cb5045aafe81ff Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Wed, 13 Aug 2025 16:02:36 +0300 Subject: [PATCH] simplify sharding in package tests for CI; increase to 12 shards (#4158) * simplify sharding in package tests for CI; increase to 12 shards Signed-off-by: Avi Deitcher * for CI setup-go action, determine it based on go.mod file Signed-off-by: Avi Deitcher --------- Signed-off-by: Avi Deitcher --- .github/workflows/ci.yml | 48 ++++++++++++++++++++++----- .github/workflows/package_release.yml | 10 +++--- .github/workflows/release.yml | 24 +++++++------- src/cmd/linuxkit/go.mod | 4 +-- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b74aa89cb..09272e6b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,9 @@ name: LinuxKit CI on: [push, pull_request] +env: + TOTAL_SHARDS: 12 # change here once + jobs: build: name: Build & Test @@ -35,15 +38,15 @@ jobs: runs-on: ${{ matrix.target.runner }} steps: - - name: Set up Go 1.22 - uses: actions/setup-go@v5 - with: - go-version: 1.22.3 - id: go - - name: Check out code uses: actions/checkout@v4 + - name: Set up Go based on go.mod + uses: actions/setup-go@v5 + with: + go-version-file: 'src/cmd/linuxkit/go.mod' + id: go + - name: Set path run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH env: @@ -150,14 +153,43 @@ jobs: - name: list cache contents run: | linuxkit cache ls + + gen_package_test_matrix: + name: Generate Package Test Matrix + needs: [ build_packages, build ] + runs-on: ubuntu-latest + outputs: + shard_list: ${{ steps.mk.outputs.list }} + steps: + - name: Generate Test Matrix + id: mk + shell: bash + run: | + set -x + N="${{ env.TOTAL_SHARDS }}" + # Priority: repo var SHARDS → event-based default (PR=6, else 10) + if [ -n "${{ vars.SHARDS }}" ]; then + N="${{ vars.SHARDS }}" + fi + + # Build JSON array ["1/N","2/N",...,"N/N"] + shards="" + for i in $(seq 1 "$N"); do + if [ -z "$shards" ]; then + shards="\"$i/$N\"" + else + shards="$shards,\"$i/$N\"" + fi + done + echo "list=[$shards]" >> "$GITHUB_OUTPUT" test_packages: name: Packages Tests - needs: [ build_packages, build ] + needs: [ build_packages, build, gen_package_test_matrix ] runs-on: ubuntu-latest strategy: matrix: - shard: [1/10,2/10,3/10,4/10,5/10,6/10,7/10,8/10,9/10,10/10] + shard: ${{ fromJson(needs.gen_package_test_matrix.outputs.shard_list) }} steps: - name: Check out code uses: actions/checkout@v4 diff --git a/.github/workflows/package_release.yml b/.github/workflows/package_release.yml index 8616adad3..db53174cb 100644 --- a/.github/workflows/package_release.yml +++ b/.github/workflows/package_release.yml @@ -9,13 +9,13 @@ jobs: if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/pkg-v') runs-on: ubuntu-latest steps: - - name: Set up Go 1.22 - uses: actions/setup-go@v5 - with: - go-version: 1.22.3 - id: go - name: Check out code uses: actions/checkout@v4 + - name: Set up Go based on go.mod + uses: actions/setup-go@v5 + with: + go-version-file: 'src/cmd/linuxkit/go.mod' + id: go - name: Ensure bin/ directory run: mkdir -p bin - name: Install linuxkit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 86034e751..f072f7c5a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,14 +10,14 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.122 - uses: actions/setup-go@v5 - with: - go-version: 1.22.3 - id: go - - name: Check out code uses: actions/checkout@v4 + - name: Set up Go based on go.mod + uses: actions/setup-go@v5 + with: + go-version-file: 'src/cmd/linuxkit/go.mod' + id: go + - name: Set path run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH @@ -42,14 +42,14 @@ jobs: runs-on: macos-latest steps: - - name: Set up Go 1.122 - uses: actions/setup-go@v5 - with: - go-version: 1.22.3 - id: go - - name: Check out code uses: actions/checkout@v4 + - name: Set up Go based on go.mod + uses: actions/setup-go@v5 + with: + go-version-file: 'src/cmd/linuxkit/go.mod' + id: go + - name: Set path run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH diff --git a/src/cmd/linuxkit/go.mod b/src/cmd/linuxkit/go.mod index f401b873b..e13537dba 100644 --- a/src/cmd/linuxkit/go.mod +++ b/src/cmd/linuxkit/go.mod @@ -1,8 +1,6 @@ module github.com/linuxkit/linuxkit/src/cmd/linuxkit -go 1.23.0 - -toolchain go1.24.2 +go 1.24.2 require ( github.com/Azure/azure-sdk-for-go v56.3.0+incompatible