mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Upload code coverage to codecov once all tests finish
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
eba7a074df
commit
01dd7d5722
7 changed files with 196 additions and 156 deletions
26
.github/workflows/ci.yml
vendored
26
.github/workflows/ci.yml
vendored
|
@ -2306,6 +2306,10 @@ jobs:
|
|||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Setup Python Tools Scripts
|
||||
id: python-tools-scripts
|
||||
uses: ./.github/actions/setup-python-tools-scripts
|
||||
|
||||
- name: Install Nox
|
||||
run: |
|
||||
python3 -m pip install 'nox==2022.8.7'
|
||||
|
@ -2322,6 +2326,28 @@ jobs:
|
|||
- name: Display structure of downloaded files
|
||||
run: tree -a artifacts/
|
||||
|
||||
- name: Install Codecov CLI
|
||||
run: |
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
# python3 -m pip install codecov-cli
|
||||
#
|
||||
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --import
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
|
||||
gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
|
||||
shasum -a 256 -c codecov.SHA256SUM
|
||||
chmod +x codecov
|
||||
mv ./codecov /usr/local/bin/
|
||||
|
||||
- name: Create XML Coverage Reports
|
||||
run: |
|
||||
nox -e create-xml-coverage-reports
|
||||
|
||||
- name: Upload Code Coverage To Codecov
|
||||
run: |
|
||||
tools ci upload-coverage --commit-sha=${{ github.event.pull_request.head.sha || github.sha }} artifacts/coverage/
|
||||
|
||||
- name: Combine Code Coverage
|
||||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
|
26
.github/workflows/nightly.yml
vendored
26
.github/workflows/nightly.yml
vendored
|
@ -2367,6 +2367,10 @@ jobs:
|
|||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Setup Python Tools Scripts
|
||||
id: python-tools-scripts
|
||||
uses: ./.github/actions/setup-python-tools-scripts
|
||||
|
||||
- name: Install Nox
|
||||
run: |
|
||||
python3 -m pip install 'nox==2022.8.7'
|
||||
|
@ -2383,6 +2387,28 @@ jobs:
|
|||
- name: Display structure of downloaded files
|
||||
run: tree -a artifacts/
|
||||
|
||||
- name: Install Codecov CLI
|
||||
run: |
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
# python3 -m pip install codecov-cli
|
||||
#
|
||||
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --import
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
|
||||
gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
|
||||
shasum -a 256 -c codecov.SHA256SUM
|
||||
chmod +x codecov
|
||||
mv ./codecov /usr/local/bin/
|
||||
|
||||
- name: Create XML Coverage Reports
|
||||
run: |
|
||||
nox -e create-xml-coverage-reports
|
||||
|
||||
- name: Upload Code Coverage To Codecov
|
||||
run: |
|
||||
tools ci upload-coverage --commit-sha=${{ github.event.pull_request.head.sha || github.sha }} artifacts/coverage/
|
||||
|
||||
- name: Combine Code Coverage
|
||||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
|
26
.github/workflows/scheduled.yml
vendored
26
.github/workflows/scheduled.yml
vendored
|
@ -2340,6 +2340,10 @@ jobs:
|
|||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Setup Python Tools Scripts
|
||||
id: python-tools-scripts
|
||||
uses: ./.github/actions/setup-python-tools-scripts
|
||||
|
||||
- name: Install Nox
|
||||
run: |
|
||||
python3 -m pip install 'nox==2022.8.7'
|
||||
|
@ -2356,6 +2360,28 @@ jobs:
|
|||
- name: Display structure of downloaded files
|
||||
run: tree -a artifacts/
|
||||
|
||||
- name: Install Codecov CLI
|
||||
run: |
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
# python3 -m pip install codecov-cli
|
||||
#
|
||||
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --import
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
|
||||
gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
|
||||
shasum -a 256 -c codecov.SHA256SUM
|
||||
chmod +x codecov
|
||||
mv ./codecov /usr/local/bin/
|
||||
|
||||
- name: Create XML Coverage Reports
|
||||
run: |
|
||||
nox -e create-xml-coverage-reports
|
||||
|
||||
- name: Upload Code Coverage To Codecov
|
||||
run: |
|
||||
tools ci upload-coverage --commit-sha=${{ github.event.pull_request.head.sha || github.sha }} artifacts/coverage/
|
||||
|
||||
- name: Combine Code Coverage
|
||||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
|
26
.github/workflows/templates/ci.yml.jinja
vendored
26
.github/workflows/templates/ci.yml.jinja
vendored
|
@ -343,6 +343,10 @@
|
|||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Setup Python Tools Scripts
|
||||
id: python-tools-scripts
|
||||
uses: ./.github/actions/setup-python-tools-scripts
|
||||
|
||||
- name: Install Nox
|
||||
run: |
|
||||
python3 -m pip install 'nox==<{ nox_version }>'
|
||||
|
@ -370,6 +374,28 @@
|
|||
- name: Display structure of downloaded files
|
||||
run: tree -a artifacts/
|
||||
|
||||
- name: Install Codecov CLI
|
||||
run: |
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
# python3 -m pip install codecov-cli
|
||||
#
|
||||
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --import
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
|
||||
gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
|
||||
shasum -a 256 -c codecov.SHA256SUM
|
||||
chmod +x codecov
|
||||
mv ./codecov /usr/local/bin/
|
||||
|
||||
- name: Create XML Coverage Reports
|
||||
run: |
|
||||
nox -e create-xml-coverage-reports
|
||||
|
||||
- name: Upload Code Coverage To Codecov
|
||||
run: |
|
||||
tools ci upload-coverage --commit-sha=${{ github.event.pull_request.head.sha || github.sha }} artifacts/coverage/
|
||||
|
||||
- name: Combine Code Coverage
|
||||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
|
80
.github/workflows/test-action-macos.yml
vendored
80
.github/workflows/test-action-macos.yml
vendored
|
@ -404,84 +404,8 @@ jobs:
|
|||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
nox -e create-xml-coverage-reports
|
||||
|
||||
- name: Install Codecov CLI
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
# python3 -m pip install codecov-cli
|
||||
#
|
||||
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --import
|
||||
curl -Os https://uploader.codecov.io/latest/macos/codecov
|
||||
curl -Os https://uploader.codecov.io/latest/macos/codecov.SHA256SUM
|
||||
curl -Os https://uploader.codecov.io/latest/macos/codecov.SHA256SUM.sig
|
||||
gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
|
||||
shasum -a 256 -c codecov.SHA256SUM
|
||||
chmod +x codecov
|
||||
|
||||
- name: Upload Source Code Coverage To Codecov
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
if [ ! -s artifacts/coverage/salt.xml ]; then
|
||||
echo "The artifacts/coverage/salt.xml file does not exist"
|
||||
exit 1
|
||||
fi
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
#codecovcli --auto-load-params-from GithubActions --verbose --token ${{ secrets.CODECOV_TOKEN }} \
|
||||
# do-upload --git-service github --sha ${{ github.sha }} \
|
||||
# --file artifacts/coverage/salt.xml \
|
||||
# --flag salt --flag ${{ inputs.distro-slug }} \
|
||||
# --name salt.${{ inputs.distro-slug }}.${{ inputs.nox-session }}
|
||||
n=0
|
||||
until [ "$n" -ge 5 ]
|
||||
do
|
||||
if ./codecov --file artifacts/coverage/salt.xml \
|
||||
--sha ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event_name == 'pull_request' && format('--parent {0}', github.event.pull_request.base.sha) }} \
|
||||
--flags salt,${{ inputs.distro-slug }} \
|
||||
--name salt.${{ inputs.distro-slug }}.${{ inputs.nox-session }} --nonZero; then
|
||||
rc=$?
|
||||
break
|
||||
fi
|
||||
rc=$?
|
||||
n=$((n+1))
|
||||
sleep 15
|
||||
done
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "Failed to upload codecov stats"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Upload Tests Code Coverage To Codecov
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
if [ ! -s artifacts/coverage/tests.xml ]; then
|
||||
echo "The artifacts/coverage/tests.xml file does not exist"
|
||||
exit 1
|
||||
fi
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
#codecovcli --auto-load-params-from GithubActions --verbose --token ${{ secrets.CODECOV_TOKEN }} \
|
||||
# do-upload --git-service github --sha ${{ github.sha }} \
|
||||
# --file artifacts/coverage/tests.xml \
|
||||
# --flag tests --flag ${{ inputs.distro-slug }} \
|
||||
# --name tests.${{ inputs.distro-slug }}.${{ inputs.nox-session }}
|
||||
n=0
|
||||
until [ "$n" -ge 5 ]
|
||||
do
|
||||
if ./codecov --file artifacts/coverage/tests.xml \
|
||||
--sha ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event_name == 'pull_request' && format('--parent {0}', github.event.pull_request.base.sha) }} \
|
||||
--flags tests,${{ inputs.distro-slug }} \
|
||||
--name tests.${{ inputs.distro-slug }}.${{ inputs.nox-session }} --nonZero; then
|
||||
rc=$?
|
||||
break
|
||||
fi
|
||||
rc=$?
|
||||
n=$((n+1))
|
||||
sleep 15
|
||||
done
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "Failed to upload codecov stats"
|
||||
exit 1
|
||||
fi
|
||||
mv artifacts/coverage/salt.xml artifacts/coverage/salt.${{ inputs.distro-slug }}.${{ inputs.nox-session }}.xml
|
||||
mv artifacts/coverage/tests.xml artifacts/coverage/tests.${{ inputs.distro-slug }}.${{ inputs.nox-session }}.xml
|
||||
|
||||
- name: Report Salt Code Coverage
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success'
|
||||
|
|
80
.github/workflows/test-action.yml
vendored
80
.github/workflows/test-action.yml
vendored
|
@ -351,84 +351,8 @@ jobs:
|
|||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
nox -e create-xml-coverage-reports
|
||||
|
||||
- name: Install Codecov CLI
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
# python3 -m pip install codecov-cli
|
||||
#
|
||||
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --import
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
|
||||
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
|
||||
gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
|
||||
shasum -a 256 -c codecov.SHA256SUM
|
||||
chmod +x codecov
|
||||
|
||||
- name: Upload Source Code Coverage To Codecov
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
if [ ! -s artifacts/coverage/salt.xml ]; then
|
||||
echo "The artifacts/coverage/salt.xml file does not exist"
|
||||
exit 1
|
||||
fi
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
#codecovcli --auto-load-params-from GithubActions --verbose --token ${{ secrets.CODECOV_TOKEN }} \
|
||||
# do-upload --git-service github --sha ${{ github.sha }} \
|
||||
# --file artifacts/coverage/salt.xml \
|
||||
# --flag salt --flag ${{ inputs.distro-slug }} \
|
||||
# --name salt.${{ inputs.distro-slug }}.${{ inputs.nox-session }}
|
||||
n=0
|
||||
until [ "$n" -ge 5 ]
|
||||
do
|
||||
if ./codecov --file artifacts/coverage/salt.xml \
|
||||
--sha ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event_name == 'pull_request' && format('--parent {0}', github.event.pull_request.base.sha) }} \
|
||||
--flags salt,${{ inputs.distro-slug }} \
|
||||
--name salt.${{ inputs.distro-slug }}.${{ inputs.nox-session }} --nonZero; then
|
||||
rc=$?
|
||||
break
|
||||
fi
|
||||
rc=$?
|
||||
n=$((n+1))
|
||||
sleep 15
|
||||
done
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "Failed to upload codecov stats"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Upload Tests Code Coverage To Codecov
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
if [ ! -s artifacts/coverage/tests.xml ]; then
|
||||
echo "The artifacts/coverage/tests.xml file does not exist"
|
||||
exit 1
|
||||
fi
|
||||
# We can't yet use tokenless uploads with the codecov CLI
|
||||
#codecovcli --auto-load-params-from GithubActions --verbose --token ${{ secrets.CODECOV_TOKEN }} \
|
||||
# do-upload --git-service github --sha ${{ github.sha }} \
|
||||
# --file artifacts/coverage/tests.xml \
|
||||
# --flag tests --flag ${{ inputs.distro-slug }} \
|
||||
# --name tests.${{ inputs.distro-slug }}.${{ inputs.nox-session }}
|
||||
n=0
|
||||
until [ "$n" -ge 5 ]
|
||||
do
|
||||
if ./codecov --file artifacts/coverage/tests.xml \
|
||||
--sha ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event_name == 'pull_request' && format('--parent {0}', github.event.pull_request.base.sha) }} \
|
||||
--flags tests,${{ inputs.distro-slug }} \
|
||||
--name tests.${{ inputs.distro-slug }}.${{ inputs.nox-session }} --nonZero; then
|
||||
rc=$?
|
||||
break
|
||||
fi
|
||||
rc=$?
|
||||
n=$((n+1))
|
||||
sleep 15
|
||||
done
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "Failed to upload codecov stats"
|
||||
exit 1
|
||||
fi
|
||||
mv artifacts/coverage/salt.xml artifacts/coverage/salt.${{ inputs.distro-slug }}.${{ inputs.nox-session }}.xml
|
||||
mv artifacts/coverage/tests.xml artifacts/coverage/tests.${{ inputs.distro-slug }}.${{ inputs.nox-session }}.xml
|
||||
|
||||
- name: Report Salt Code Coverage
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success'
|
||||
|
|
88
tools/ci.py
88
tools/ci.py
|
@ -9,6 +9,7 @@ import logging
|
|||
import os
|
||||
import pathlib
|
||||
import random
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
@ -1047,3 +1048,90 @@ def define_cache_seed(ctx: Context, static_cache_seed: str, randomize: bool = Fa
|
|||
ctx.info("Writing 'cache-seed' to the github outputs file")
|
||||
with open(github_output, "a", encoding="utf-8") as wfh:
|
||||
wfh.write(f"cache-seed={cache_seed}\n")
|
||||
|
||||
|
||||
@ci.command(
|
||||
name="upload-coverage",
|
||||
arguments={
|
||||
"commit_sha": {
|
||||
"help": "The commit SHA",
|
||||
"required": True,
|
||||
},
|
||||
"reports_path": {
|
||||
"help": "The path to the directory containing the XML Coverage Reports",
|
||||
},
|
||||
},
|
||||
)
|
||||
def upload_coverage(ctx: Context, reports_path: pathlib.Path, commit_sha: str = None):
|
||||
"""
|
||||
Upload code coverage to codecov.
|
||||
"""
|
||||
codecov = shutil.which("codecov")
|
||||
if not codecov:
|
||||
ctx.error("Could not find the path to the 'codecov' binary")
|
||||
ctx.exit(1)
|
||||
|
||||
codecov_args = [
|
||||
codecov,
|
||||
"--nonZero",
|
||||
"--sha",
|
||||
commit_sha,
|
||||
]
|
||||
|
||||
gh_event_path = os.environ.get("GITHUB_EVENT_PATH") or None
|
||||
if gh_event_path is not None:
|
||||
try:
|
||||
gh_event = json.loads(open(gh_event_path).read())
|
||||
pr_event_data = gh_event.get("pull_request")
|
||||
if pr_event_data:
|
||||
codecov_args.extend(["--parent", pr_event_data["base"]["sha"]])
|
||||
except Exception as exc:
|
||||
ctx.error(
|
||||
f"Could not load the GH Event payload from {gh_event_path!r}:\n", exc
|
||||
)
|
||||
|
||||
sleep_time = 15
|
||||
for fpath in reports_path.glob("*.xml"):
|
||||
if fpath.name in ("salt.xml", "tests.xml"):
|
||||
flags = fpath.stem
|
||||
else:
|
||||
try:
|
||||
section, distro_slug, nox_session = fpath.stem.split(".")
|
||||
ctx.print(section, distro_slug, nox_session)
|
||||
except ValueError:
|
||||
ctx.error(
|
||||
f"The file {fpath} does not respect the expected naming convention "
|
||||
"'{salt|tests}.<distro-slug>.<nox-session>.xml'. Skipping..."
|
||||
)
|
||||
continue
|
||||
flags = f"{section},{distro_slug}"
|
||||
|
||||
max_attempts = 3
|
||||
current_attempt = 0
|
||||
while True:
|
||||
current_attempt += 1
|
||||
ctx.info(
|
||||
f"Uploading '{fpath}' coverage report to codecov (attempt {current_attempt} of {max_attempts}) ..."
|
||||
)
|
||||
|
||||
ret = ctx.run(
|
||||
*codecov_args,
|
||||
"--file",
|
||||
str(fpath),
|
||||
"--name",
|
||||
fpath.stem,
|
||||
"--flags",
|
||||
flags,
|
||||
check=False,
|
||||
)
|
||||
if ret.returncode == 0:
|
||||
break
|
||||
|
||||
if current_attempt >= max_attempts:
|
||||
ctx.error(f"Failed to upload {fpath} to codecov")
|
||||
ctx.exit(1)
|
||||
|
||||
ctx.warn(f"Waiting {sleep_time} seconds until next retry...")
|
||||
time.sleep(sleep_time)
|
||||
|
||||
ctx.exit(0)
|
||||
|
|
Loading…
Add table
Reference in a new issue