diff --git a/.github/actions/install_lima_from_artifact/action.yml b/.github/actions/install_lima_from_artifact/action.yml new file mode 100644 index 00000000000..349b4d7271a --- /dev/null +++ b/.github/actions/install_lima_from_artifact/action.yml @@ -0,0 +1,25 @@ +name: install lima from artifact +description: install lima from artifact +inputs: + artifact: + description: artifact to install + required: true +runs: + using: "composite" + steps: + - uses: actions/download-artifact@v4 + with: + name: ${{ inputs.artifact }} + path: _artifacts + - name: Install lima from downloaded archive on Linux + if: runner.os == 'Linux' + run: | + sudo make uninstall + sudo tar -C /usr/local -xvf _artifacts/${{ inputs.artifact }} --no-same-owner + shell: bash + - name: Install lima from downloaded archive on macOS + if: runner.os == 'macOS' + run: | + make uninstall || true + tar -C /usr/local -xvmf _artifacts/${{ inputs.artifact }} --no-same-owner + shell: bash diff --git a/.github/actions/setup_go_with_cache/action.yml b/.github/actions/setup_go_with_cache/action.yml new file mode 100644 index 00000000000..a00172a73cf --- /dev/null +++ b/.github/actions/setup_go_with_cache/action.yml @@ -0,0 +1,82 @@ +name: setup go with cache +description: setup go with cache. export GOMODCACHE environment variable +inputs: + additional-gocache-key: + description: additional cache key for GOCACHE + required: false + go-version: + description: go version + required: true + ignore-go-mod-and-go-sum: + description: ignore go.mod and go.sum if true + required: false + runs-on: + description: runs on + required: true + working-directory: + description: working directory + default: '.' +runs: + using: "composite" + steps: + - id: setup-go + uses: actions/setup-go@v5 + with: + cache: false + go-version: ${{ inputs.go-version }} + - name: Set GOMODCACHE environment variable + if: runner.os != 'Windows' + run: echo "GOMODCACHE=$(pwd)/.gomodcache" >> $GITHUB_ENV + shell: bash + - name: Set GOMODCACHE environment variable on Windows + if: runner.os == 'Windows' + run: echo "GOMODCACHE=$(cygpath -w $(pwd)/.gomodcache)" >> $GITHUB_ENV + shell: bash + - id: go-env + run: | + echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT + if [[ "${{ inputs.ignore-go-mod-and-go-sum }}" == "true" ]]; then + echo "GOMOD=" >> $GITHUB_OUTPUT + echo "GOSUM=" >> $GITHUB_OUTPUT + else + GOMOD=$(go env GOMOD) + case $GOMOD in + /dev/null|NUL) GOMOD= ;; + esac + GOSUM=${GOMOD/%.mod/.sum} + echo "GOMOD=${GOMOD}" >> $GITHUB_OUTPUT + echo "GOSUM=${GOSUM}" >> $GITHUB_OUTPUT + fi + shell: bash + working-directory: ${{ inputs.working-directory }} + - id: base-key + run: | + echo "gomodcache-key=go-modcache-${WORKING_DIRECTORY}" >> $GITHUB_OUTPUT + echo "gocache-key=go-cache-${WORKING_DIRECTORY}-${RUNS_ON}-${ADDITIONAL_GOCACHE_KEY}-${GO_VERSION}" >> $GITHUB_OUTPUT + shell: bash + env: + ADDITIONAL_GOCACHE_KEY: ${{ inputs.additional-gocache-key }} + GO_VERSION: ${{ steps.setup-go.outputs.go-version }} + RUNS_ON: ${{ inputs.runs-on }} + WORKING_DIRECTORY: ${{ inputs.working-directory }} + - name: Cache go modules + uses: actions/cache@v4 + with: + path: .gomodcache + key: ${{ steps.base-key.outputs.gomodcache-key }}-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles(steps.go-env.outputs.GOMOD) }} + restore-keys: | + ${{ steps.base-key.outputs.gomodcache-key }}-${{ steps.setup-go.outputs.go-version }}- + ${{ steps.base-key.outputs.gomodcache-key }}- + enableCrossOsArchive: true + - name: Cache go build cache + uses: actions/cache@v4 + with: + path: ${{ steps.go-env.outputs.GOCACHE }} + key: ${{ steps.base-key.outputs.gocache-key }}-${{ hashFiles(steps.go-env.outputs.GOSUM) }} + restore-keys: | + ${{ steps.base-key.outputs.gocache-key }}- + - name: Download dependencies + if: inputs.ignore-go-mod-and-go-sum != 'true' + run: go mod download -x + shell: bash + working-directory: ${{ inputs.working-directory }} diff --git a/.github/workflows/build_lima_and_fill_cache.yml b/.github/workflows/build_lima_and_fill_cache.yml new file mode 100644 index 00000000000..d7c33346184 --- /dev/null +++ b/.github/workflows/build_lima_and_fill_cache.yml @@ -0,0 +1,65 @@ +name: build lima and fill cache +run-name: build lima and fill cache on ${{ inputs.runs-on }} using go ${{ inputs.go-version }} + +on: + workflow_call: + inputs: + go-version: + type: string + description: 'The version of Go to use' + required: true + runs-on: + type: string + description: 'The type of runner to use' + required: true + outputs: + artifact: + description: 'The name of the artifact' + value: ${{ jobs.build.outputs.artifact }} + +jobs: + build: + name: "Build on ${{ inputs.runs-on }} using go ${{ inputs.go-version }}" + runs-on: ${{ inputs.runs-on }} + timeout-minutes: 30 + outputs: + artifact: ${{ steps.make-artifacts.outputs.artifact }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: ./.github/actions/setup_go_with_cache + with: + go-version: ${{ inputs.go-version }} + runs-on: ${{ inputs.runs-on }} + - name: go test to filling cache + run: go test ./... --run=nope + shell: bash + - name: make artifacts to filling cache + id: make-artifacts + run: | + case "${RUNNER_OS}" in + Linux) + make artifact-linux-$(uname -m) VERSION_TRIMMED="${RUNS_ON}" + artifact=lima-${RUNS_ON}-Linux-$(uname -m).tar.gz + ;; + macOS) + make artifact-darwin-$(uname -m) VERSION_TRIMMED="${RUNS_ON}" + artifact=lima-${RUNS_ON}-Darwin-$(uname -m).tar.gz + ;; + Windows) + make artifact-windows-$(uname -m) VERSION_TRIMMED="${RUNS_ON}" + artifact=lima-${RUNS_ON}-Windows-$(uname -m).tar.gz + ;; + *) + echo "Unsupported OS: ${RUNNER_OS}" + exit 1 ;; + esac + echo "artifact=${artifact}" >> $GITHUB_OUTPUT + env: + RUNS_ON: ${{ inputs.runs-on }} + - name: upload archive + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.make-artifacts.outputs.artifact }} + path: _artifacts/${{ steps.make-artifacts.outputs.artifact }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2bc463a296f..5549b711132 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,9 +28,11 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup_go_with_cache with: + additional-gocache-key: release go-version: 1.23.x + runs-on: macos-12 - name: Make darwin artifacts run: make artifacts-darwin - name: "Upload artifacts" @@ -55,9 +57,11 @@ jobs: with: name: artifacts-darwin path: _artifacts/ - - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup_go_with_cache with: + additional-gocache-key: release go-version: 1.23.x + runs-on: ubuntu-20.04 - name: Install gcc-x86-64-linux-gnu run: | sudo apt-get update diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e861d09a79f..7d610ed74a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-go@v5 with: + cache-dependency-path: "" # disable using hash for cache key go-version: 1.23.x - name: Install protoc run: | @@ -67,6 +68,7 @@ jobs: unit: name: "Unit tests" + needs: build-lima-and-fill-cache-on-ubuntu runs-on: ubuntu-24.04 timeout-minutes: 30 strategy: @@ -82,9 +84,10 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup_go_with_cache with: go-version: ${{ matrix.go-version }} + runs-on: ubuntu-24.04 - name: Unit tests run: go test -v ./... - name: Make @@ -130,9 +133,10 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup_go_with_cache with: go-version: 1.23.x + runs-on: windows-2022-8-cores - name: Unit tests run: go test -v ./... - name: Make @@ -151,9 +155,17 @@ jobs: if: always() run: type C:\Users\runneradmin\.lima\wsl2\ha.stderr.log + build-lima-and-fill-cache-on-macos-12: + name: "Build on macOS 12" + uses: ./.github/workflows/build_lima_and_fill_cache.yml + with: + go-version: 1.23.x + runs-on: macos-12 + integration: name: Integration tests # on macOS 12, the default vmType is QEMU + needs: build-lima-and-fill-cache-on-macos-12 runs-on: macos-12 timeout-minutes: 120 steps: @@ -161,9 +173,10 @@ jobs: with: # To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format" fetch-depth: 0 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup_go_with_cache with: go-version: 1.23.x + runs-on: macos-12 - name: Unit tests run: go test -v ./... - name: Make @@ -208,10 +221,18 @@ jobs: if: always() run: ./hack/debug-cache.sh + build-lima-and-fill-cache-on-ubuntu: + name: "Build on Ubuntu" + uses: ./.github/workflows/build_lima_and_fill_cache.yml + with: + go-version: 1.23.x + runs-on: ubuntu-24.04 + # Non-default templates are tested on Linux instances of GHA, # as they seem more stable than macOS instances. integration-linux: name: Integration tests (on Linux) + needs: build-lima-and-fill-cache-on-ubuntu runs-on: ubuntu-24.04 timeout-minutes: 120 strategy: @@ -232,13 +253,9 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/install_lima_from_artifact with: - go-version: 1.23.x - - name: Make - run: make - - name: Install - run: sudo make install + artifact: ${{ needs.build-lima-and-fill-cache-on-ubuntu.outputs.artifact }} - name: Cache image used by templates/${{ matrix.template }} uses: ./.github/actions/setup_cache_for_template with: @@ -272,6 +289,7 @@ jobs: colima: name: Colima + needs: build-lima-and-fill-cache-on-ubuntu runs-on: ubuntu-24.04 timeout-minutes: 120 strategy: @@ -283,24 +301,29 @@ jobs: # fetch-depth is set to 0 to let `limactl --version` print semver-ish version fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} - - uses: actions/setup-go@v5 - with: - go-version: 1.23.x - uses: actions/cache@v4 with: path: ~/.cache/lima/download key: ${{ runner.os }}-colima-${{ matrix.colima-version }} - - name: Make - run: make - - name: Install - run: sudo make install + - uses: ./.github/actions/install_lima_from_artifact + with: + artifact: ${{ needs.build-lima-and-fill-cache-on-ubuntu.outputs.artifact }} + - name: Checkout colima + uses: actions/checkout@v4 + with: + repository: abiosoft/colima + ref: ${{ matrix.colima-version }} + path: colima + - uses: ./.github/actions/setup_go_with_cache + with: + go-version: 1.23.x + runs-on: macos-12 + working-directory: ./colima - name: Install colima run: | - git clone https://github.com/abiosoft/colima - cd colima - git checkout ${{ matrix.colima-version }} make sudo make install + working-directory: ./colima - name: Install test dependencies run: | sudo apt-get update @@ -322,22 +345,20 @@ jobs: vmnet: name: "VMNet test" + needs: build-lima-and-fill-cache-on-macos-12 runs-on: macos-12 timeout-minutes: 120 steps: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/install_lima_from_artifact with: - go-version: 1.23.x - - name: Make - run: make - - name: Install - run: make install + artifact: ${{ needs.build-lima-and-fill-cache-on-macos-12.outputs.artifact }} - name: "Inject `no_timer_check` to kernel cmdline" # workaround to https://github.com/lima-vm/lima/issues/84 run: ./hack/inject-cmdline-to-template.sh templates/vmnet.yaml no_timer_check + - name: Cache image used by vmnet.yaml uses: ./.github/actions/setup_cache_for_template with: @@ -357,6 +378,11 @@ jobs: sudo make PREFIX=/opt/socket_vmnet install ) limactl sudoers | sudo tee /etc/sudoers.d/lima + - uses: ./.github/actions/setup_go_with_cache + with: + additional-gocache-key: vmnet + go-version: 1.23.x + runs-on: macos-12 - name: Unit test (pkg/networks) with socket_vmnet # Set -count=1 to disable cache run: go test -v -count=1 ./pkg/networks/... @@ -372,6 +398,7 @@ jobs: upgrade: name: "Upgrade test" + needs: build-lima-and-fill-cache-on-macos-12 runs-on: macos-12 timeout-minutes: 120 strategy: @@ -389,9 +416,10 @@ jobs: path: homebrew-core fetch-depth: 0 filter: tree:0 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/setup_go_with_cache with: go-version: 1.23.x + runs-on: macos-12 - name: Cache image used by ${{ matrix.oldver }}/examples/ubuntu-lts.yaml uses: ./.github/actions/setup_cache_for_template with: @@ -412,8 +440,16 @@ jobs: - if: always() uses: ./.github/actions/upload_failure_logs_if_exists + build-lima-and-fill-cache-on-macos-13: + name: "Build on macOS 13" + uses: ./.github/workflows/build_lima_and_fill_cache.yml + with: + go-version: 1.23.x + runs-on: macos-13 + vz: name: "vz" + needs: build-lima-and-fill-cache-on-macos-13 # on macOS 13, the default vmType is VZ runs-on: macos-13 timeout-minutes: 120 @@ -427,13 +463,9 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-go@v5 + - uses: ./.github/actions/install_lima_from_artifact with: - go-version: 1.23.x - - name: Make - run: make - - name: Install - run: make install + artifact: ${{ needs.build-lima-and-fill-cache-on-macos-13.outputs.artifact }} - name: Cache image used by templates/${{ matrix.template }} uses: ./.github/actions/setup_cache_for_template with: