From fd5e772aec28bd74439d01c61f8c68cdfb439488 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 16 Apr 2025 17:31:01 +0900 Subject: [PATCH] CI: deduplicate execution of unit tests Fix issue 49816 Signed-off-by: Akihiro Suda --- .github/workflows/.test-unit.yml | 123 ++++++++++++++++++++++++++++ .github/workflows/.test.yml | 132 ------------------------------- .github/workflows/test.yml | 7 ++ 3 files changed, 130 insertions(+), 132 deletions(-) create mode 100644 .github/workflows/.test-unit.yml diff --git a/.github/workflows/.test-unit.yml b/.github/workflows/.test-unit.yml new file mode 100644 index 0000000000..d8f66379bb --- /dev/null +++ b/.github/workflows/.test-unit.yml @@ -0,0 +1,123 @@ +# reusable workflow +name: .test-unit + +# TODO: hide reusable workflow from the UI. Tracked in https://github.com/community/community/discussions/12025 + +# Default to 'contents: read', which grants actions to read commits. +# +# If any permission is set, any permission not included in the list is +# implicitly set to "none". +# +# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions +permissions: + contents: read + +on: + workflow_call: + +env: + GO_VERSION: "1.23.8" + GOTESTLIST_VERSION: v0.3.1 + TESTSTAT_VERSION: v0.1.25 + SETUP_BUILDX_VERSION: edge + SETUP_BUILDKIT_IMAGE: moby/buildkit:latest + +jobs: + unit: + runs-on: ubuntu-24.04 + timeout-minutes: 120 # guardrails timeout for the whole job + continue-on-error: ${{ github.event_name != 'pull_request' }} + strategy: + fail-fast: false + matrix: + mode: + - "" + - firewalld + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up runner + uses: ./.github/actions/setup-runner + - + name: Prepare + run: | + CACHE_DEV_SCOPE=dev + if [[ "${{ matrix.mode }}" == *"firewalld"* ]]; then + echo "FIREWALLD=true" >> $GITHUB_ENV + CACHE_DEV_SCOPE="${CACHE_DEV_SCOPE}firewalld" + fi + echo "CACHE_DEV_SCOPE=${CACHE_DEV_SCOPE}" >> $GITHUB_ENV + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + version: ${{ env.SETUP_BUILDX_VERSION }} + driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }} + buildkitd-flags: --debug + - + name: Build dev image + uses: docker/bake-action@v6 + with: + targets: dev + set: | + dev.cache-from=type=gha,scope=${{ env.CACHE_DEV_SCOPE }} + - + name: Test + run: | + make -o build test-unit + - + name: Prepare reports + if: always() + run: | + mkdir -p bundles /tmp/reports + find bundles -type f \( -name '*-report.json' -o -name '*.log' -o -name '*.out' -o -name '*.prof' -o -name '*-report.xml' \) -print | xargs sudo tar -czf /tmp/reports.tar.gz + tar -xzf /tmp/reports.tar.gz -C /tmp/reports + sudo chown -R $(id -u):$(id -g) /tmp/reports + tree -nh /tmp/reports + - + name: Send to Codecov + uses: codecov/codecov-action@v4 + with: + directory: ./bundles + env_vars: RUNNER_OS + flags: unit + token: ${{ secrets.CODECOV_TOKEN }} # used to upload coverage reports: https://github.com/moby/buildkit/pull/4660#issue-2142122533 + - + name: Upload reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-reports-unit--${{ matrix.mode }} + path: /tmp/reports/* + retention-days: 1 + + unit-report: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + continue-on-error: ${{ github.event_name != 'pull_request' }} + if: always() + needs: + - unit + steps: + - + name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache-dependency-path: vendor.sum + - + name: Download reports + uses: actions/download-artifact@v4 + with: + pattern: test-reports-unit-* + path: /tmp/reports + - + name: Install teststat + run: | + go install github.com/vearutop/teststat@${{ env.TESTSTAT_VERSION }} + - + name: Create summary + run: | + find /tmp/reports -type f -name '*-go-test-report.json' -exec teststat -markdown {} \+ >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/.test.yml b/.github/workflows/.test.yml index 49508e0d7b..2092e5cb3c 100644 --- a/.github/workflows/.test.yml +++ b/.github/workflows/.test.yml @@ -32,138 +32,6 @@ env: SETUP_BUILDKIT_IMAGE: moby/buildkit:latest jobs: - unit-prepare: - runs-on: ubuntu-24.04 - timeout-minutes: 10 # guardrails timeout for the whole job - continue-on-error: ${{ github.event_name != 'pull_request' }} - outputs: - includes: ${{ steps.set.outputs.includes }} - steps: - - - name: Create matrix includes - id: set - uses: actions/github-script@v7 - with: - script: | - let includes = [ - { mode: '' }, - { mode: 'systemd' }, - ]; - if ("${{ inputs.storage }}" == "snapshotter") { - includes.push({ mode: 'firewalld' }); - } - await core.group(`Set matrix`, async () => { - core.info(`matrix: ${JSON.stringify(includes)}`); - core.setOutput('includes', JSON.stringify(includes)); - }); - - - name: Show matrix - run: | - echo ${{ steps.set.outputs.includes }} - - unit: - runs-on: ubuntu-24.04 - timeout-minutes: 120 # guardrails timeout for the whole job - continue-on-error: ${{ github.event_name != 'pull_request' }} - needs: - - unit-prepare - strategy: - fail-fast: false - matrix: - include: ${{ fromJson(needs.unit-prepare.outputs.includes) }} - steps: - - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up runner - uses: ./.github/actions/setup-runner - - - name: Prepare - run: | - CACHE_DEV_SCOPE=dev - if [[ "${{ matrix.mode }}" == *"firewalld"* ]]; then - echo "FIREWALLD=true" >> $GITHUB_ENV - CACHE_DEV_SCOPE="${CACHE_DEV_SCOPE}firewalld" - fi - if [[ "${{ matrix.mode }}" == *"systemd"* ]]; then - echo "SYSTEMD=true" >> $GITHUB_ENV - CACHE_DEV_SCOPE="${CACHE_DEV_SCOPE}systemd" - fi - echo "CACHE_DEV_SCOPE=${CACHE_DEV_SCOPE}" >> $GITHUB_ENV - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - version: ${{ env.SETUP_BUILDX_VERSION }} - driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }} - buildkitd-flags: --debug - - - name: Build dev image - uses: docker/bake-action@v6 - with: - targets: dev - set: | - dev.cache-from=type=gha,scope=dev - - - name: Test - run: | - make -o build test-unit - - - name: Prepare reports - if: always() - run: | - mkdir -p bundles /tmp/reports - find bundles -path '*/root/*overlay2' -prune -o -type f \( -name '*-report.json' -o -name '*.log' -o -name '*.out' -o -name '*.prof' -o -name '*-report.xml' \) -print | xargs sudo tar -czf /tmp/reports.tar.gz - tar -xzf /tmp/reports.tar.gz -C /tmp/reports - sudo chown -R $(id -u):$(id -g) /tmp/reports - tree -nh /tmp/reports - - - name: Send to Codecov - uses: codecov/codecov-action@v4 - with: - directory: ./bundles - env_vars: RUNNER_OS - flags: unit - token: ${{ secrets.CODECOV_TOKEN }} # used to upload coverage reports: https://github.com/moby/buildkit/pull/4660#issue-2142122533 - - - name: Upload reports - if: always() - uses: actions/upload-artifact@v4 - with: - name: test-reports-unit-${{ inputs.storage }}-${{ matrix.mode }} - path: /tmp/reports/* - retention-days: 1 - - unit-report: - runs-on: ubuntu-24.04 - timeout-minutes: 10 - continue-on-error: ${{ github.event_name != 'pull_request' }} - if: always() - needs: - - unit - steps: - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - cache-dependency-path: vendor.sum - - - name: Download reports - uses: actions/download-artifact@v4 - with: - pattern: test-reports-unit-${{ inputs.storage }}-* - path: /tmp/reports - - - name: Install teststat - run: | - go install github.com/vearutop/teststat@${{ env.TESTSTAT_VERSION }} - - - name: Create summary - run: | - find /tmp/reports -type f -name '*-go-test-report.json' -exec teststat -markdown {} \+ >> $GITHUB_STEP_SUMMARY - docker-py: runs-on: ubuntu-24.04 timeout-minutes: 120 # guardrails timeout for the whole job diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e4e1d94672..c72b03d541 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,6 +83,13 @@ jobs: with: storage: ${{ matrix.storage }} + test-unit: + needs: + - build-dev + - validate-dco + uses: ./.github/workflows/.test-unit.yml + secrets: inherit + validate-prepare: runs-on: ubuntu-24.04 timeout-minutes: 10 # guardrails timeout for the whole job