From 80c9dfba5eafcc8d4fc497d75a91ade955b98bb5 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:27:39 +0100 Subject: [PATCH] ci: split docker install integration tests Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/test.yml | 56 ++++++++++++++++------ __tests__/docker/install.test.itg.ts | 70 +++++++++++++--------------- 2 files changed, 73 insertions(+), 53 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a2e6ee00..ee26b519 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,7 +60,7 @@ jobs: prepare-itg: runs-on: ubuntu-latest outputs: - matrix: ${{ steps.tests.outputs.matrix }} + includes: ${{ steps.set.outputs.includes }} steps: - name: Checkout @@ -80,14 +80,43 @@ jobs: name: Install run: yarn install - - name: Create matrix - id: tests - run: | - declare -a tests - for test in $(yarn run test:itg-list); do - tests+=("${test#$(pwd)/__tests__/}") - done - echo "matrix=$(echo ${tests[@]} | jq -cR 'split(" ")')" >>${GITHUB_OUTPUT} + name: Create includes + id: set + uses: actions/github-script@v7 + with: + script: | + let tests = []; + await core.group(`Set includes`, async () => { + const res = await exec.getExecOutput('yarn', ['run', 'test:itg-list'], { + silent: true, + ignoreReturnCode: true + }); + if (res.stderr.length > 0 && res.exitCode != 0) { + throw new Error(res.stderr); + } + for (const test of res.stdout.trim().split('\n')) { + tests.push(test.replace(/^.*__tests__\//, '')); + } + core.info(`tests: ${JSON.stringify(tests)}`); + }); + await core.group(`Set includes`, async () => { + let includes = []; + for (const os of ['ubuntu-latest', 'macos-13', 'windows-latest']) { + for (const test of tests) { + if (os === 'macos-13' && test === 'docker/install.test.itg.ts') { + includes.push({ os: os, test: test, docker_install_type: 'image', docker_install_version: '27.3.1' }); + includes.push({ os: os, test: test, docker_install_type: 'image', docker_install_version: 'master' }); + includes.push({ os: os, test: test, docker_install_type: 'image', docker_install_version: 'latest' }); + includes.push({ os: os, test: test, docker_install_type: 'archive', docker_install_version: '27.3.1' }); + includes.push({ os: os, test: test, docker_install_type: 'archive', docker_install_version: 'latest' }); + } else { + includes.push({ os: os, test: test }); + } + } + } + core.info(`includes: ${JSON.stringify(includes)}`); + core.setOutput('includes', JSON.stringify(includes)); + }); - name: Show matrix run: | @@ -100,12 +129,7 @@ jobs: strategy: fail-fast: false matrix: - test: ${{ fromJson(needs.prepare-itg.outputs.matrix) }} - os: - - ubuntu-latest - #- macos-14 # no virt: https://github.com/docker/actions-toolkit/issues/317 - - macos-13 - - windows-latest + include: ${{ fromJson(needs.prepare-itg.outputs.includes) }} steps: - name: Checkout @@ -158,6 +182,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CTN_BUILDER_NAME: ${{ steps.builder.outputs.name }} TEST_FOR_SUMMARY: ${{ secrets.TEST_FOR_SUMMARY }} + DOCKER_INSTALL_TYPE: ${{ matrix.docker_install_type }} + DOCKER_INSTALL_VERSION: ${{ matrix.docker_install_version }} - name: Check coverage run: | diff --git a/__tests__/docker/install.test.itg.ts b/__tests__/docker/install.test.itg.ts index b960e77a..98f5dad4 100644 --- a/__tests__/docker/install.test.itg.ts +++ b/__tests__/docker/install.test.itg.ts @@ -14,66 +14,45 @@ * limitations under the License. */ -import {jest, describe, test, beforeEach, afterEach, expect} from '@jest/globals'; +import {describe, expect, it} from '@jest/globals'; import fs from 'fs'; import os from 'os'; import path from 'path'; -import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install'; +import {Install, InstallSource, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install'; import {Docker} from '../../src/docker/docker'; import {Exec} from '../../src/exec'; +const dockerInstallType = process.env.DOCKER_INSTALL_TYPE || 'archive'; +const dockerInstallVersion = process.env.DOCKER_INSTALL_VERSION || 'latest'; + const tmpDir = () => fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-itg-')); -describe('install', () => { - const originalEnv = process.env; - beforeEach(() => { - jest.resetModules(); - process.env = { - ...originalEnv, - LIMA_START_ARGS: '--cpus 4 --memory 8', - LIMA_IMAGES: `x86_64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-genericcloud-amd64-20231013-1532.qcow2@sha512:6b55e88b027c14da1b55c85a25a9f7069d4560a8fdb2d948c986a585db469728a06d2c528303e34bb62d8b2984def38fd9ddfc00965846ff6e05b01d6e883bfe -aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-genericcloud-arm64-20231013-1532.qcow2` - }; - }); - afterEach(() => { - process.env = originalEnv; - }); - // prettier-ignore - test.each([ - {type: 'image', tag: '27.3.1'} as InstallSourceImage, - {type: 'image', tag: 'master'} as InstallSourceImage, - {type: 'image', tag: 'latest'} as InstallSourceImage, - {type: 'archive', version: 'v26.1.4', channel: 'stable'} as InstallSourceArchive, - {type: 'archive', version: 'latest', channel: 'stable'} as InstallSourceArchive, - ])( - 'install docker %s', async (source) => { +describe('root', () => { + it( + 'install docker', + async () => { await ensureNoSystemContainerd(); const install = new Install({ - source: source, + source: getSource(), runDir: tmpDir(), contextName: 'foo', daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}` }); await expect(tryInstall(install)).resolves.not.toThrow(); - }, 30 * 60 * 1000); -}); - -describe('rootless', () => { - // prettier-ignore - test.each([ - {type: 'image', tag: 'latest'} as InstallSourceImage, - {type: 'archive', version: 'latest', channel: 'stable'} as InstallSourceArchive, - ])( - 'install %s', async (source) => { + }, + 30 * 60 * 1000 + ); + it( + 'install rootless docker', + async () => { // Skip on non linux if (os.platform() !== 'linux') { return; } - await ensureNoSystemContainerd(); const install = new Install({ - source: source, + source: getSource(), runDir: tmpDir(), contextName: 'foo', daemonConfig: `{"debug":true}`, @@ -122,3 +101,18 @@ async function ensureNoSystemContainerd() { }); } } + +function getSource(): InstallSource { + if (dockerInstallType === 'archive') { + return { + type: dockerInstallType, + version: dockerInstallVersion, + channel: 'stable' + } as InstallSourceArchive; + } else { + return { + type: dockerInstallType, + tag: dockerInstallVersion + } as InstallSourceImage; + } +}