Skip to content

Commit

Permalink
Merge branch 'main' of github.com:codecov/codecov-cli into joseph/fix…
Browse files Browse the repository at this point in the history
…-tokenless
  • Loading branch information
joseph-sentry committed Dec 3, 2024
2 parents bf44167 + 87d5916 commit 6681a0d
Show file tree
Hide file tree
Showing 69 changed files with 1,652 additions and 434 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_for_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ jobs:
- name: Publish package to PyPi
if: inputs.publish == true
uses: pypa/gh-action-pypi-publish@release/v1



with:
attestations: false
verbose: true
41 changes: 41 additions & 0 deletions .github/workflows/ci-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: CLI CI Job

on:
pull_request:
push:
branches:
- main

jobs:
build-test-upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 2
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install -e .
pip install -r tests/requirements.txt
- name: Test with pytest
run: |
pytest --cov --junitxml=3.12junit.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: python3.12
fail_ci_if_error: true
verbose: true
88 changes: 42 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install dependencies
- name: Check linting with ruff
run: |
python -m pip install --upgrade pip
pip install black==22.3.0 isort==5.10.1
- name: Check linting with black
run: |
black --check codecov_cli
- name: Check imports order with isort
run: |
isort --check --profile=black codecov_cli -p staticcodecov_languages
make lint
codecov-startup:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,12 +70,18 @@ jobs:
pip install -r tests/requirements.txt
- name: Test with pytest
run: |
pytest --cov --junitxml=junit.xml
pytest --cov --junitxml=${{matrix.python-version}}junit.xml
- name: Dogfooding codecov-cli
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -v do-upload --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} --plugin pycoverage --flag python${{matrix.python-version}}
codecovcli do-upload --report-type test_results --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} --plugin pycoverage --flag python${{matrix.python-version}}
- name: Upload artifacts for test-results-processing
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: ${{matrix.python-version}}junit.xml
path: ${{matrix.python-version}}junit.xml

static-analysis:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -118,10 +118,12 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install CLI
- name: Install dependencies for Dogfooding
run: |
pip install -r requirements.txt -r tests/requirements.txt
pip install codecov-cli
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install -e .
pip install -r tests/requirements.txt
- name: Label Analysis
run: |
BASE_SHA=$(git merge-base HEAD^ origin/main)
Expand All @@ -131,38 +133,32 @@ jobs:
run: |
codecovcli --codecov-yml-path=codecov.yml do-upload --plugin pycoverage --plugin compress-pycoverage --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} --flag smart-labels
test-process-test-results-cmd:
process-test-results:
if: ${{ always() }}
needs: build-test-upload
runs-on: ubuntu-latest
permissions:
pull-requests: write
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.12"
- python-version: "3.11"
- python-version: "3.10"
- python-version: "3.9"
- python-version: "3.8"
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 2
- name: Set up Python ${{matrix.python-version}}
uses: actions/setup-python@v5
with:
python-version: "${{matrix.python-version}}"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install -e .
pip install -r tests/requirements.txt
- name: Test with pytest
run: |
pytest --cov --junitxml=junit.xml
- name: Dogfooding codecov-cli
if: ${{ !cancelled() }}
run: |
codecovcli process-test-results --provider-token ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 2
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies for Dogfooding
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install -e .
pip install -r tests/requirements.txt
- name: Download all test results
uses: actions/download-artifact@v4
with:
pattern: "*junit.xml"
path: "test_results"
merge-multiple: true

- name: Dogfooding codecov-cli
if: ${{ !cancelled() && github.ref && contains(github.ref, 'pull') }}
run: |
codecovcli process-test-results --dir test_results --github-token ${{ secrets.GITHUB_TOKEN }}
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ name ?= codecovcli
# Semantic versioning format https://semver.org/
tag_regex := ^v([0-9]{1,}\.){2}[0-9]{1,}([-_]\w+)?$

lint.install:
echo "Installing ruff..."
pip install -Iv ruff

# The preferred method (for now) w.r.t. fixable rules is to manually update the makefile
# with --fix and re-run 'make lint.' Since ruff is constantly adding rules this is a slight
# amount of "needed" friction imo.
lint.run:
ruff check --ignore F401 --exclude languages --exclude samples
ruff format --exclude languages --exclude samples

lint.check:
echo "Linting..."
ruff check --ignore F401 --exclude languages --exclude samples
echo "Formatting..."
ruff format --check --exclude languages --exclude samples

lint:
pip install black==22.3.0 isort==5.10.1
black codecov_cli
isort --profile=black codecov_cli -p staticcodecov_languages
black tests
isort --profile black tests
make lint.install
make lint.run

tag.release:
ifeq ($(shell echo ${version} | egrep "${tag_regex}"),)
Expand All @@ -16,4 +30,4 @@ else
@echo "Tagging new release ${version}"
git tag -a ${version} -m "Autogenerated release tag for codecov-cli"
git push origin ${version}
endif
endif
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,15 @@ are ignored by codecov (including README and configuration files)

`Usage: codecovcli empty-upload [OPTIONS]`

Options:
-C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required]
-Z, --fail-on-error Exit with non-zero code in case of error
--git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]
-t, --token TEXT Codecov upload token
-r, --slug TEXT owner/repo slug used instead of the private
repo token in Self-hosted
-h, --help Show this message and exit.
| Options | Description | usage |
| :--------------------------: | :----------------------------------------------------------------------------------------: | :------: |
| -C, --sha, --commit-sha TEXT | Commit SHA (with 40 chars) | Required |
| -t, --token TEXT | Codecov upload token | Required |
| -r, --slug TEXT | owner/repo slug used instead of the private repo token in Self-hosted | Optional |
| --force | Always emit passing checks regardless of changed files | Optional |
| -Z, --fail-on-error | Exit with non-zero code in case of error | Optional |
| --git-service | Options: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server | Optional |
| -h, --help | Show this message and exit. | Optional |

# How to Use Local Upload

Expand Down
2 changes: 2 additions & 0 deletions codecov_cli/commands/get_report_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.encoder import encode_slug
from codecov_cli.helpers.git import GitService
from codecov_cli.helpers.options import global_options
from codecov_cli.services.report import send_reports_result_get_request
from codecov_cli.types import CommandContext


logger = logging.getLogger("codecovcli")


Expand Down
8 changes: 4 additions & 4 deletions codecov_cli/commands/labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ def _dry_run_list_output(
logger.warning(f"label-analysis didn't run correctly. Error: {fallback_reason}")

to_run_line = " ".join(
sorted(map(lambda l: f"'{l}'", runner_options))
+ sorted(map(lambda l: f"'{l}'", labels_to_run))
sorted(map(lambda option: f"'{option}'", runner_options))
+ sorted(map(lambda label: f"'{label}'", labels_to_run))
)
to_skip_line = " ".join(
sorted(map(lambda l: f"'{l}'", runner_options))
+ sorted(map(lambda l: f"'{l}'", labels_to_skip))
sorted(map(lambda option: f"'{option}'", runner_options))
+ sorted(map(lambda label: f"'{label}'", labels_to_skip))
)
# ⚠️ DON'T use logger
# logger goes to stderr, we want it in stdout
Expand Down
Loading

0 comments on commit 6681a0d

Please sign in to comment.