mirror of
https://github.com/codecov/codecov-action.git
synced 2025-12-08 08:06:27 +00:00
347 lines
14 KiB
YAML
347 lines
14 KiB
YAML
---
|
|
# yamllint disable rule:line-length
|
|
name: 'Codecov'
|
|
description: 'GitHub Action that uploads coverage reports for your repository to codecov.io'
|
|
author: 'Thomas Hu <@thomasrockhu-codecov> | Codecov'
|
|
inputs:
|
|
base_sha:
|
|
description: 'The base SHA to select. This is only used in the "pr-base-picking" run command'
|
|
required: false
|
|
binary:
|
|
description: 'The file location of a pre-downloaded version of the CLI. If specified, integrity checking will be bypassed.'
|
|
required: false
|
|
codecov_yml_path:
|
|
description: 'The location of the codecov.yml file. This is crrently ONLY used for automated test selection (https://docs.codecov.com/docs/getting-started-with-ats). Note that for all other cases, the Codecov yaml will need to be located as described here: https://docs.codecov.com/docs/codecov-yaml#can-i-name-the-file-codecovyml'
|
|
required: false
|
|
commit_parent:
|
|
description: 'SHA (with 40 chars) of what should be the parent of this commit.'
|
|
required: false
|
|
directory:
|
|
description: 'Folder to search for coverage files. Default to the current working directory'
|
|
required: false
|
|
disable_file_fixes:
|
|
description: 'Disable file fixes to ignore common lines from coverage (e.g. blank lines or empty brackets). Read more here https://docs.codecov.com/docs/fixing-reports'
|
|
required: false
|
|
default: 'false'
|
|
disable_search:
|
|
description: 'Disable search for coverage files. This is helpful when specifying what files you want to upload with the files option.'
|
|
required: false
|
|
default: 'false'
|
|
disable_safe_directory:
|
|
description: 'Disable setting safe directory. Set to true to disable.'
|
|
required: false
|
|
default: 'false'
|
|
disable_telem:
|
|
description: 'Disable sending telemetry data to Codecov. Set to true to disable.'
|
|
required: false
|
|
default: 'false'
|
|
dry_run:
|
|
description: "Don't upload files to Codecov"
|
|
required: false
|
|
default: 'false'
|
|
env_vars:
|
|
description: 'Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)'
|
|
required: false
|
|
exclude:
|
|
description: 'Comma-separated list of folders to exclude from search.'
|
|
required: false
|
|
fail_ci_if_error:
|
|
description: 'On error, exit with non-zero code'
|
|
required: false
|
|
default: 'false'
|
|
files:
|
|
description: 'Comma-separated list of explicit files to upload. These will be added to the coverage files found for upload. If you wish to only upload the specified files, please consider using disable-search to disable uploading other files.'
|
|
required: false
|
|
flags:
|
|
description: 'Comma-separated list of flags to upload to group coverage metrics.'
|
|
required: false
|
|
force:
|
|
description: 'Only used for empty-upload run command'
|
|
required: false
|
|
git_service:
|
|
description: 'Override the git_service (e.g. github_enterprise)'
|
|
required: false
|
|
default: 'github'
|
|
gcov_args:
|
|
description: 'Extra arguments to pass to gcov'
|
|
required: false
|
|
gcov_executable:
|
|
description: "gcov executable to run. Defaults to 'gcov'"
|
|
required: false
|
|
default: 'gcov'
|
|
gcov_ignore:
|
|
description: 'Paths to ignore during gcov gathering'
|
|
required: false
|
|
gcov_include:
|
|
description: "Paths to include during gcov gathering"
|
|
required: false
|
|
handle_no_reports_found:
|
|
description: 'If no coverage reports are found, do not raise an exception.'
|
|
required: false
|
|
default: 'false'
|
|
job_code:
|
|
description: ''
|
|
required: false
|
|
name:
|
|
description: 'Custom defined name of the upload. Visible in the Codecov UI'
|
|
required: false
|
|
network_filter:
|
|
description: 'Specify a filter on the files listed in the network section of the Codecov report. This will only add files whose path begin with the specified filter. Useful for upload-specific path fixing.'
|
|
required: false
|
|
network_prefix:
|
|
description: 'Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing.'
|
|
required: false
|
|
os:
|
|
description: 'Override the assumed OS. Options available at cli.codecov.io'
|
|
required: false
|
|
override_branch:
|
|
description: 'Specify the branch to be displayed with this commit on Codecov'
|
|
required: false
|
|
override_build:
|
|
description: 'Specify the build number manually'
|
|
required: false
|
|
override_build_url:
|
|
description: 'The URL of the build where this is running'
|
|
required: false
|
|
override_commit:
|
|
description: 'Commit SHA (with 40 chars)'
|
|
required: false
|
|
override_pr:
|
|
description: 'Specify the pull request number manually. Used to override pre-existing CI environment variables.'
|
|
required: false
|
|
plugins:
|
|
description: 'Comma-separated list of plugins to run. Specify `noop` to turn off all plugins'
|
|
required: false
|
|
recurse_submodules:
|
|
description: 'Whether to enumerate files inside of submodules for path-fixing purposes. Off by default.'
|
|
default: 'false'
|
|
report_code:
|
|
description: 'The code of the report if using local upload. If unsure, leave default. Read more here https://docs.codecov.com/docs/the-codecov-cli#how-to-use-local-upload'
|
|
required: false
|
|
report_type:
|
|
description: 'The type of file to upload, coverage by default. Possible values are "test_results", "coverage".'
|
|
required: false
|
|
root_dir:
|
|
description: 'Root folder from which to consider paths on the network section. Defaults to current working directory.'
|
|
required: false
|
|
run_command:
|
|
description: 'Choose which CLI command to run. Options are "upload-coverage", "empty-upload", "pr-base-picking", "send-notifications". "upload-coverage" is run by default.'
|
|
required: false
|
|
default: 'upload-coverage'
|
|
skip_validation:
|
|
description: 'Skip integrity checking of the CLI. This is NOT recommended.'
|
|
required: false
|
|
default: 'false'
|
|
slug:
|
|
description: '[Required when using the org token] Set to the owner/repo slug used instead of the private repo token. Only applicable to some Enterprise users.'
|
|
required: false
|
|
swift_project:
|
|
description: 'Specify the swift project name. Useful for optimization.'
|
|
required: false
|
|
token:
|
|
description: 'Repository Codecov token. Used to authorize report uploads'
|
|
required: false
|
|
url:
|
|
description: 'Set to the Codecov instance URl. Used by Dedicated Enterprise Cloud customers.'
|
|
required: false
|
|
use_legacy_upload_endpoint:
|
|
description: 'Use the legacy upload endpoint.'
|
|
required: false
|
|
default: 'false'
|
|
use_oidc:
|
|
description: 'Use OIDC instead of token. This will ignore any token supplied'
|
|
required: false
|
|
default: 'false'
|
|
use_pypi:
|
|
description: 'Use the pypi version of the CLI instead of from cli.codecov.io'
|
|
required: false
|
|
default: 'false'
|
|
verbose:
|
|
description: 'Enable verbose logging'
|
|
required: false
|
|
default: 'false'
|
|
version:
|
|
description: "Which version of the Codecov CLI to use (defaults to 'latest')"
|
|
required: false
|
|
default: 'latest'
|
|
working-directory:
|
|
description: 'Directory in which to execute codecov.sh'
|
|
required: false
|
|
|
|
branding:
|
|
color: 'red'
|
|
icon: 'umbrella'
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Check system dependencies
|
|
shell: sh
|
|
run: |
|
|
missing_deps=""
|
|
|
|
# Check for required commands
|
|
for cmd in bash git curl gpg; do
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
missing_deps="$missing_deps $cmd"
|
|
fi
|
|
done
|
|
|
|
# Report missing required dependencies
|
|
if [ -n "$missing_deps" ]; then
|
|
echo "Error: The following required dependencies are missing:$missing_deps"
|
|
echo "Please install these dependencies before using this action."
|
|
exit 1
|
|
fi
|
|
|
|
echo "All required system dependencies are available."
|
|
- name: Action version
|
|
shell: bash
|
|
run: |
|
|
CC_ACTION_VERSION=$(cat ${GITHUB_ACTION_PATH}/src/version)
|
|
echo -e "\033[0;32m==>\033[0m Running Action version $CC_ACTION_VERSION"
|
|
- name: Set safe directory
|
|
if: ${{ inputs.disable_safe_directory != 'true' }}
|
|
shell: bash
|
|
run: |
|
|
git config --global --add safe.directory "${{ github.workspace }}"
|
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
|
|
- name: Set fork
|
|
shell: bash
|
|
run: |
|
|
CC_FORK="false"
|
|
if [ -n "$GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME" ] && [ "$GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME" != "$GITHUB_REPOSITORY" ];
|
|
then
|
|
echo -e "\033[0;32m==>\033[0m Fork detected"
|
|
CC_FORK="true"
|
|
fi
|
|
echo "CC_FORK=$CC_FORK" >> "$GITHUB_ENV"
|
|
env:
|
|
GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL: ${{ github.event.pull_request.head.label }}
|
|
GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
|
|
GITHUB_REPOSITORY: ${{ github.repository }}
|
|
|
|
- name: Get OIDC token
|
|
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
|
id: oidc
|
|
with:
|
|
script: |
|
|
if (process.env.CC_USE_OIDC === 'true' && process.env.CC_FORK != 'true') {
|
|
const id_token = await core.getIDToken(process.env.CC_OIDC_AUDIENCE)
|
|
return id_token
|
|
}
|
|
env:
|
|
CC_OIDC_AUDIENCE: ${{ inputs.url || 'https://codecov.io' }}
|
|
CC_USE_OIDC: ${{ inputs.use_oidc }}
|
|
|
|
- name: Get and set token
|
|
shell: bash
|
|
run: |
|
|
if [ "${{ inputs.use_oidc }}" == 'true' ] && [ "$CC_FORK" != 'true' ];
|
|
then
|
|
echo "CC_TOKEN=$CC_OIDC_TOKEN" >> "$GITHUB_ENV"
|
|
elif [ -n "${{ env.CODECOV_TOKEN }}" ];
|
|
then
|
|
echo -e "\033[0;32m==>\033[0m Token set from env"
|
|
echo "CC_TOKEN=${{ env.CODECOV_TOKEN }}" >> "$GITHUB_ENV"
|
|
else
|
|
if [ -n "${{ inputs.token }}" ];
|
|
then
|
|
echo -e "\033[0;32m==>\033[0m Token set from input"
|
|
CC_TOKEN=$(echo "${{ inputs.token }}" | tr -d '\n')
|
|
echo "CC_TOKEN=$CC_TOKEN" >> "$GITHUB_ENV"
|
|
fi
|
|
fi
|
|
env:
|
|
CC_OIDC_TOKEN: ${{ steps.oidc.outputs.result }}
|
|
CC_OIDC_AUDIENCE: ${{ inputs.url || 'https://codecov.io' }}
|
|
|
|
- name: Override branch for forks
|
|
shell: bash
|
|
run: |
|
|
if [ -z "$CC_BRANCH" ] && [ -z "$CC_TOKEN" ] && [ "$CC_FORK" == 'true' ]
|
|
then
|
|
echo -e "\033[0;32m==>\033[0m Fork detected, setting branch to $GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL"
|
|
TOKENLESS="$GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL"
|
|
CC_BRANCH="$GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL"
|
|
echo "TOKENLESS=$TOKENLESS" >> "$GITHUB_ENV"
|
|
fi
|
|
|
|
echo "CC_BRANCH=$CC_BRANCH" >> "$GITHUB_ENV"
|
|
env:
|
|
CC_BRANCH: ${{ inputs.override_branch }}
|
|
GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL: ${{ github.event.pull_request.head.label }}
|
|
GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
|
|
GITHUB_REPOSITORY: ${{ github.repository }}
|
|
|
|
- name: Override commits and pr for pull requests
|
|
shell: bash
|
|
run: |
|
|
if [ -z "$CC_SHA" ];
|
|
then
|
|
CC_SHA="$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA"
|
|
fi
|
|
if [ -z "$CC_PR" ] && [ "${GITHUB_EVENT_NAME}" == "pull_request_target" ];
|
|
then
|
|
CC_PR="$GITHUB_EVENT_NUMBER"
|
|
fi
|
|
|
|
echo "CC_SHA=$CC_SHA" >> "$GITHUB_ENV"
|
|
echo "CC_PR=$CC_PR" >> "$GITHUB_ENV"
|
|
env:
|
|
CC_PR: ${{ inputs.override_pr }}
|
|
CC_SHA: ${{ inputs.override_commit }}
|
|
GITHUB_EVENT_NAME: ${{ github.event_name }}
|
|
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
|
|
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: Upload coverage to Codecov
|
|
run: ${GITHUB_ACTION_PATH}/dist/codecov.sh
|
|
shell: bash
|
|
working-directory: ${{ inputs.working-directory }}
|
|
env:
|
|
CC_BASE_SHA: ${{ inputs.base_sha }}
|
|
CC_BINARY: ${{ inputs.binary }}
|
|
CC_BUILD: ${{ inputs.override_build }}
|
|
CC_BUILD_URL: ${{ inputs.override_build_url }}
|
|
CC_CODE: ${{ inputs.report_code }}
|
|
CC_DIR: ${{ inputs.directory }}
|
|
CC_DISABLE_FILE_FIXES: ${{ inputs.disable_file_fixes }}
|
|
CC_DISABLE_SEARCH: ${{ inputs.disable_search }}
|
|
CC_DISABLE_TELEM: ${{ inputs.disable_telem }}
|
|
CC_DRY_RUN: ${{ inputs.dry_run }}
|
|
CC_ENTERPRISE_URL: ${{ inputs.url }}
|
|
CC_ENV: ${{ inputs.env_vars }}
|
|
CC_EXCLUDES: ${{ inputs.exclude }}
|
|
CC_FAIL_ON_ERROR: ${{ inputs.fail_ci_if_error }}
|
|
CC_FILES: ${{ inputs.files }}
|
|
CC_FLAGS: ${{ inputs.flags }}
|
|
CC_FORCE: ${{ inputs.force }}
|
|
CC_GCOV_ARGS: ${{ inputs.gcov_args }}
|
|
CC_GCOV_EXECUTABLE: ${{ inputs.gcov_executable }}
|
|
CC_GCOV_IGNORE: ${{ inputs.gcov_ignore }}
|
|
CC_GCOV_INCLUDE: ${{ inputs.gcov_include }}
|
|
CC_GIT_SERVICE: ${{ inputs.git_service }}
|
|
CC_HANDLE_NO_REPORTS_FOUND: ${{ inputs.handle_no_reports_found }}
|
|
CC_JOB_CODE: ${{ inputs.job_code }}
|
|
CC_LEGACY: ${{ inputs.use_legacy_upload_endpoint }}
|
|
CC_NAME: ${{ inputs.name }}
|
|
CC_NETWORK_FILTER: ${{ inputs.network_filter }}
|
|
CC_NETWORK_PREFIX: ${{ inputs.network_prefix }}
|
|
CC_NETWORK_ROOT_FOLDER: ${{ inputs.root_dir }}
|
|
CC_OS: ${{ inputs.os }}
|
|
CC_PARENT_SHA: ${{ inputs.commit_parent }}
|
|
CC_PLUGINS: ${{ inputs.plugins }}
|
|
CC_RECURSE_SUBMODULES: ${{ inputs.recurse_submodules }}
|
|
CC_REPORT_TYPE: ${{ inputs.report_type }}
|
|
CC_RUN_CMD: ${{ inputs.run_command }}
|
|
CC_SERVICE: ${{ inputs.git_service }}
|
|
CC_SKIP_VALIDATION: ${{ inputs.skip_validation }}
|
|
CC_SLUG: ${{ inputs.slug }}
|
|
CC_SWIFT_PROJECT: ${{ inputs.swift_project }}
|
|
CC_USE_PYPI: ${{ inputs.use_pypi }}
|
|
CC_VERBOSE: ${{ inputs.verbose }}
|
|
CC_VERSION: ${{ inputs.version }}
|
|
CC_YML_PATH: ${{ inputs.codecov_yml_path }}
|