mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-25 00:44:40 +00:00
Fix CI Test Collision (#1162)
* Fix CI concurrency issue * More CI fixes * Fix coverage job install * Install correct test dependencies
This commit is contained in:
85
.github/workflows/all_green_check.yaml
vendored
85
.github/workflows/all_green_check.yaml
vendored
@@ -33,48 +33,37 @@ jobs:
|
|||||||
coverage:
|
coverage:
|
||||||
name: Unit test coverage
|
name: Unit test coverage
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
|
||||||
- sanity
|
|
||||||
- units
|
|
||||||
env:
|
|
||||||
ANSIBLE_CORE_VERSION: "2.19.5"
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: ansible_collections/kubernetes/core
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.12"
|
python-version: "3.12"
|
||||||
|
|
||||||
- name: Install Ansible (ansible-test)
|
- name: Run unit tests with coverage
|
||||||
|
working-directory: ansible_collections/kubernetes/core
|
||||||
|
env:
|
||||||
|
PYTHONPATH: ${{ github.workspace }}
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
python -m pip install "ansible-core==${ANSIBLE_CORE_VERSION}"
|
python -m pip install ansible-compat
|
||||||
|
python -m pip install https://github.com/ansible/ansible/archive/stable-2.19.tar.gz
|
||||||
- name: Run unit tests with coverage
|
# Same deps as the units matrix (build_install_collection); do not use
|
||||||
run: ansible-test units --venv --coverage --python 3.12 --requirements
|
# tests/unit/requirements.txt — its kubernetes pin breaks test_core.py.
|
||||||
|
python -m pip install -r requirements.txt -r test-requirements.txt
|
||||||
- name: Combine and emit coverage XML
|
python -m coverage run --source=plugins -m pytest tests/unit \
|
||||||
run: |
|
--ansible-host-pattern localhost
|
||||||
ansible-test coverage combine --venv --python 3.12 --requirements
|
python -m coverage xml -o coverage.xml
|
||||||
ansible-test coverage xml --venv --python 3.12 --requirements
|
|
||||||
|
|
||||||
- name: Prepare coverage.xml for SonarCloud
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
mkdir -p "${GITHUB_WORKSPACE}"
|
|
||||||
xml=$(find tests/output/reports -maxdepth 1 -name '*.xml' ! -name '*powershell*' | head -1)
|
|
||||||
test -n "${xml}"
|
|
||||||
cp "${xml}" "${GITHUB_WORKSPACE}/coverage.xml"
|
|
||||||
# Strip workspace prefix so Sonar sees repo-relative paths (same idea as amazon.aws path rewrite)
|
|
||||||
sed -i "s#${GITHUB_WORKSPACE}/##g" "${GITHUB_WORKSPACE}/coverage.xml"
|
|
||||||
|
|
||||||
- name: Upload coverage artifact
|
- name: Upload coverage artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: coverage
|
name: coverage
|
||||||
path: ${{ github.workspace }}/coverage.xml
|
path: ansible_collections/kubernetes/core/coverage.xml
|
||||||
|
|
||||||
all_green:
|
all_green:
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
@@ -87,8 +76,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- run: |
|
- run: |
|
||||||
python -c "
|
python -c "
|
||||||
import sys
|
|
||||||
|
|
||||||
required = ['sanity', 'units', 'coverage']
|
required = ['sanity', 'units', 'coverage']
|
||||||
if '${{ github.event_name }}' == 'pull_request':
|
if '${{ github.event_name }}' == 'pull_request':
|
||||||
required = ['linters', 'sanity', 'units', 'coverage']
|
required = ['linters', 'sanity', 'units', 'coverage']
|
||||||
@@ -98,43 +85,7 @@ jobs:
|
|||||||
'units': '${{ needs.units.result }}',
|
'units': '${{ needs.units.result }}',
|
||||||
'coverage': '${{ needs.coverage.result }}',
|
'coverage': '${{ needs.coverage.result }}',
|
||||||
}
|
}
|
||||||
|
ok = all(results[j] == 'success' for j in required)
|
||||||
for name in required:
|
skipped_ok = all(results[j] in ('success', 'skipped') for j in results)
|
||||||
if results[name] == 'failure':
|
assert ok and skipped_ok, f'required={required} results={results}'
|
||||||
print(f'all_green: required job failed: {name} results={results}', file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# cancel-in-progress superseded this run; do not fail (newer run is authoritative)
|
|
||||||
if any(v == 'cancelled' for v in results.values()):
|
|
||||||
print(
|
|
||||||
'all_green: one or more jobs cancelled (usually concurrency); skipping strict gate.',
|
|
||||||
results,
|
|
||||||
)
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
not_ok = [j for j in required if results[j] != 'success']
|
|
||||||
if not_ok:
|
|
||||||
print(f'all_green: required jobs not success: {not_ok} results={results}', file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
for job, status in results.items():
|
|
||||||
if job not in required and status not in ('success', 'skipped'):
|
|
||||||
print(f'all_green: unexpected {job}={status} results={results}', file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print('all_green OK', results)
|
|
||||||
"
|
"
|
||||||
|
|
||||||
sonarcloud:
|
|
||||||
name: SonarCloud scan
|
|
||||||
needs:
|
|
||||||
- all_green
|
|
||||||
- coverage
|
|
||||||
if: >-
|
|
||||||
${{ needs.all_green.result == 'success'
|
|
||||||
&& (github.event_name == 'push'
|
|
||||||
|| (github.event_name == 'pull_request'
|
|
||||||
&& github.event.pull_request.head.repo.full_name == github.repository)) }}
|
|
||||||
uses: ./.github/workflows/sonarcloud.yml
|
|
||||||
secrets:
|
|
||||||
ANSIBLE_COLLECTIONS_ORG_SONAR_TOKEN_CICD_BOT: ${{ secrets.ANSIBLE_COLLECTIONS_ORG_SONAR_TOKEN_CICD_BOT }}
|
|
||||||
|
|||||||
2
.github/workflows/integration-tests.yaml
vendored
2
.github/workflows/integration-tests.yaml
vendored
@@ -64,7 +64,7 @@ jobs:
|
|||||||
python-version:
|
python-version:
|
||||||
- "3.12"
|
- "3.12"
|
||||||
workflow-id: ${{ fromJson(needs.splitter.outputs.test_jobs) }}
|
workflow-id: ${{ fromJson(needs.splitter.outputs.test_jobs) }}
|
||||||
name: "integration-py${{ matrix.python-version }}-${{ matrix.ansible-version }}-${{ matrix.workflow-id }}-enable_turbo=${{ matrix.enable-turbo-mode }}"
|
name: Integration tests
|
||||||
steps:
|
steps:
|
||||||
- name: Read target
|
- name: Read target
|
||||||
id: read-targets
|
id: read-targets
|
||||||
|
|||||||
12
.github/workflows/linters.yaml
vendored
12
.github/workflows/linters.yaml
vendored
@@ -1,17 +1,7 @@
|
|||||||
---
|
---
|
||||||
name: Linters
|
name: Linters
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
on:
|
on: [workflow_call]
|
||||||
workflow_call:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- stable-*
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
linters:
|
linters:
|
||||||
|
|||||||
10
.github/workflows/sanity-tests.yaml
vendored
10
.github/workflows/sanity-tests.yaml
vendored
@@ -1,15 +1,7 @@
|
|||||||
---
|
---
|
||||||
name: Sanity tests
|
name: Sanity tests
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
on:
|
on: [workflow_call]
|
||||||
workflow_call:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- stable-*
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sanity:
|
sanity:
|
||||||
|
|||||||
73
.github/workflows/sonarcloud.yml
vendored
73
.github/workflows/sonarcloud.yml
vendored
@@ -1,67 +1,88 @@
|
|||||||
## SonarCloud scan (reusable)
|
## SonarCloud Analysis Workflow for kubernetes.core
|
||||||
#
|
#
|
||||||
# Invoked from **all_green** after the aggregate gate and **coverage** succeed. Uses the **caller's**
|
# This workflow runs SonarCloud analysis triggered by all_green workflow completion.
|
||||||
# **pull_request** / **push** event so **actions/checkout** can use **github.event.pull_request.head.sha**
|
#
|
||||||
# on PRs (Sonar-compliant). Not triggered by **workflow_run** + **workflow_run.head_sha** checkout.
|
# FLOW: all_green completes (linters, ansible-test, coverage) → workflow_run triggers this workflow → finalize job runs
|
||||||
|
#
|
||||||
|
# - Triggered by: workflow_run (all_green on pull_request or push to main/stable-*)
|
||||||
|
# - Steps: Checkout → Download coverage from all_green run → Get PR info (if PR) → Run SonarCloud scan
|
||||||
|
# - Coverage: Unit test coverage is produced by the coverage job in all_green and passed to SonarCloud here.
|
||||||
|
|
||||||
---
|
---
|
||||||
name: SonarCloud
|
name: SonarCloud
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_run:
|
||||||
secrets:
|
workflows:
|
||||||
ANSIBLE_COLLECTIONS_ORG_SONAR_TOKEN_CICD_BOT:
|
- all_green
|
||||||
required: true
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
pull-requests: read
|
pull-requests: read
|
||||||
|
actions: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
scan:
|
finalize:
|
||||||
name: SonarCloud scan
|
name: finalize
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.workflow_run.conclusion == 'success'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
|
ref: ${{ github.event.workflow_run.head_sha }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
show-progress: false
|
show-progress: false
|
||||||
|
|
||||||
- name: Download coverage artifact
|
- name: Download coverage artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: dawidd6/action-download-artifact@2536c51d3d126276eb39f74d6bc9c72ac6ef30d3 # v16
|
||||||
with:
|
with:
|
||||||
name: coverage
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
path: .
|
workflow: all_green
|
||||||
|
run_id: ${{ github.event.workflow_run.id }}
|
||||||
|
pattern: coverage*
|
||||||
|
|
||||||
- name: Set coverage report paths
|
- name: Set coverage report paths
|
||||||
run: |
|
run: |
|
||||||
coverage_files=$(find . -name "coverage*.xml" -type f 2>/dev/null | tr '\n' ',' | sed 's/,$//')
|
coverage_files=$(find . -name "coverage*.xml" -type f 2>/dev/null | tr '\n' ',' | sed 's/,$//')
|
||||||
echo "Found coverage files: ${coverage_files:-none}"
|
echo "Found coverage files: ${coverage_files:-none}"
|
||||||
echo "COVERAGE_PATHS=${coverage_files}" >> "$GITHUB_ENV"
|
echo "COVERAGE_PATHS=${coverage_files}" >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
- name: Get PR number and info
|
||||||
|
if: github.event.workflow_run.event == 'pull_request'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
PR_NUMBER=$(gh pr list --head "$HEAD_BRANCH" --repo "$REPO" --json number -q '.[0].number')
|
||||||
|
echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_ENV}"
|
||||||
|
if [ -n "${PR_NUMBER}" ]; then
|
||||||
|
PR_DATA=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}")
|
||||||
|
echo "PR_BASE=$(echo "${PR_DATA}" | jq -r '.base.ref')" >> "${GITHUB_ENV}"
|
||||||
|
echo "PR_HEAD=$(echo "${PR_DATA}" | jq -r '.head.ref')" >> "${GITHUB_ENV}"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Prepare SonarCloud args
|
- name: Prepare SonarCloud args
|
||||||
env:
|
env:
|
||||||
COMMIT_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
|
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
|
||||||
EVENT_NAME: ${{ github.event_name }}
|
EVENT_TYPE: ${{ github.event.workflow_run.event }}
|
||||||
PR_NUMBER: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || '' }}
|
|
||||||
PR_HEAD_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}
|
|
||||||
PR_BASE_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || '' }}
|
|
||||||
run: |
|
run: |
|
||||||
SONAR_ARGS="-Dsonar.scm.revision=\"${COMMIT_SHA}\""
|
SONAR_ARGS="-Dsonar.scm.revision=\"${COMMIT_SHA}\""
|
||||||
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
|
if [[ "${EVENT_TYPE}" == "pull_request" && -n "${PR_NUMBER:-}" ]]; then
|
||||||
SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.key=${PR_NUMBER}"
|
SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.key=${PR_NUMBER}"
|
||||||
SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.branch=${PR_HEAD_REF}"
|
SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.branch=${PR_HEAD}"
|
||||||
SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.base=${PR_BASE_REF}"
|
SONAR_ARGS="${SONAR_ARGS} -Dsonar.pullrequest.base=${PR_BASE}"
|
||||||
fi
|
fi
|
||||||
if [[ -n "${COVERAGE_PATHS:-}" ]]; then
|
if [[ -n "${COVERAGE_PATHS:-}" ]]; then
|
||||||
SONAR_ARGS="${SONAR_ARGS} -Dsonar.python.coverage.reportPaths=${COVERAGE_PATHS}"
|
SONAR_ARGS="${SONAR_ARGS} -Dsonar.python.coverage.reportPaths=${COVERAGE_PATHS}"
|
||||||
fi
|
fi
|
||||||
echo "SONAR_ARGS=${SONAR_ARGS}" >> "$GITHUB_ENV"
|
echo "SONAR_ARGS=${SONAR_ARGS}" >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
- name: SonarCloud Scan
|
- name: SonarCloud Scan
|
||||||
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9
|
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7
|
||||||
env:
|
env:
|
||||||
SONAR_TOKEN: ${{ secrets.ANSIBLE_COLLECTIONS_ORG_SONAR_TOKEN_CICD_BOT }}
|
SONAR_TOKEN: ${{ secrets.ANSIBLE_COLLECTIONS_ORG_SONAR_TOKEN_CICD_BOT }}
|
||||||
with:
|
with:
|
||||||
|
|||||||
10
.github/workflows/unit-tests.yaml
vendored
10
.github/workflows/unit-tests.yaml
vendored
@@ -1,14 +1,6 @@
|
|||||||
name: Unit tests
|
name: Unit tests
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
on:
|
on: [workflow_call]
|
||||||
workflow_call:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- stable-*
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
unit-source:
|
unit-source:
|
||||||
|
|||||||
Reference in New Issue
Block a user