Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): upgrade to codecov v4 #12

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .github/workflows/java-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ name: Github Actions Java Standard
on:
push:
branches:
- master
- ain
thomasrockhu-codecov marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
branches:
- master
- ain
thomasrockhu-codecov marked this conversation as resolved.
Show resolved Hide resolved
jobs:
standard-upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Set up Python 3.9
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.10'
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
Expand All @@ -27,15 +25,19 @@ jobs:
pip install requests
chmod +x gradlew
chmod +x gradle/wrapper/gradle-wrapper.jar
- name: Run Tests
env:
API_KEY: ${{ secrets.API_KEY }}
EXPECTED_COVERAGE: ${{ secrets.EXPECTED_COVERAGE }}
- name: Run tests
run: |
./gradlew build
./gradlew test
bash <(curl -s https://codecov.io/bash)
python request.py
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
- name: Check coverage
run: python request.py
env:
API_KEY: ${{ secrets.API_KEY }}
EXPECTED_COVERAGE: ${{ secrets.EXPECTED_COVERAGE }}
- name: Upstream to Standards
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
Expand Down
22 changes: 10 additions & 12 deletions request.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
#Function: this is a python script that checks to see if coverage reported from the Codecov API is accurate
# Function: this is a python script that checks to see if coverage reported from the Codecov API is accurate

import requests
import time
import os

payload = {'token': os.environ['API_KEY']}

link = 'https://codecov.io/api/gh/codecov/java-standard'
link = 'https://api.codecov.io/api/v2/github/codecov/repos/java-standard/commits'

print("Waiting 60 seconds for report to upload before pinging API...")

# Sleep 60 seconds
# night night
time.sleep(60)

print("Pinging Codecov's API..")
# Get latest coverage data
#get latest coverage data
all_data = requests.get(link, params=payload).json()
commit_data = all_data['commits'][0]
coverage_percentage = commit_data['totals']['c']
commit_data = all_data['results'][0]
coverage_percentage = commit_data['totals']['coverage']

print("Ensuring coverage percentage is accurate...")
# Result should return 60.00000 as its coverage metric
expected_coverage = os.environ['EXPECTED_COVERAGE']

if(coverage_percentage == expected_coverage):
print("Success! Codecov's API returned the correct coverage percentage, "+ expected_coverage)
# result should return 85.71429 as its coverage metric
if(str(coverage_percentage) == os.environ['CORRECT_COVERAGE']):
print("Success! Codecov's API returned the correct coverage percentage, " + os.environ['CORRECT_COVERAGE'])
exit(0)
else:
print("Whoops, something is wrong D: Codecov did not return the correct coverage percentage. Coverage percentage should be "+expected_coverage+" but Codecov returned "+coverage_percentage)
print("Whoops, something is wrong D: Codecov did not return the correct coverage percentage. Coverage percentage should be " + os.environ['CORRECT_COVERAGE']+" but Codecov returned "+ str(coverage_percentage))
exit(1)