Skip to content

Commit

Permalink
Split codecov upload to separate github actions workflow to make CI c…
Browse files Browse the repository at this point in the history
…heck run with pull_request trigger

Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Nov 14, 2024
1 parent 5514bc7 commit 70345f8
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 44 deletions.
88 changes: 44 additions & 44 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
pull_request_target:
pull_request:

env:
python-version: '3.11'
Expand Down Expand Up @@ -42,17 +42,20 @@ jobs:
run: |
flake8 $(git ls-files '*.py')
python-tests:
console-python-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
py-project:
- ./TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link
- ./TrafficCapture/dockerSolution/src/main/docker/migrationConsole/cluster_tools
- lib/console_link
- cluster_tools
- console_api
env:
WORKING_DIR: ./TrafficCapture/dockerSolution/src/main/docker/migrationConsole/${{ matrix.py-project }}
defaults:
run:
working-directory: ${{ matrix.py-project }}
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -63,38 +66,36 @@ jobs:
pipenv install --deploy --dev
pipenv run test
pipenv run coverage xml
- name: Upload Coverage
uses: codecov/codecov-action@v4
- name: Get Sanitized Name
env:
PY_PROJECT: ${{ matrix.py-project }}
run: echo "SANITIZED_PY_PROJECT=${PY_PROJECT/\//-}" >> $GITHUB_ENV
- name: Upload Coverage Reports
uses: actions/upload-artifact@v4
with:
fail_ci_if_error: true
files: ./coverage.xml
flags: python-test
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
if-no-files-found: error
name: coverage-reports-python-tests-${{ env.SANITIZED_PY_PROJECT }}
path: ${{ env.WORKING_DIR }}/coverage.xml

console-api-tests:
upload-codecov-info:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./TrafficCapture/dockerSolution/src/main/docker/migrationConsole/console_api
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}
- run: |
python3 -m pip install --upgrade pipenv
pipenv install --deploy --dev
pipenv run coverage run --source='.' manage.py test console_api
pipenv run coverage xml
- name: Upload Coverage
uses: codecov/codecov-action@v4
- name: Create JSON Artifact
run: |
echo '{' > codecov_info.json
echo ' "pr_number": "${{ github.event.pull_request.number }}",' >> codecov_info.json
echo ' "commit": "${{ github.event.pull_request.head.sha || github.event.after || github.sha }}",' >> codecov_info.json
echo ' "branch": "${{ github.ref }}",' >> codecov_info.json
echo ' "commit_parent": "${{ github.event.pull_request.base.sha || github.event.before || github.base.sha }}",' >> codecov_info.json
echo ' "build_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",' >> codecov_info.json
echo ' "build": "${{ github.run_id }}"' >> codecov_info.json
echo '}' >> codecov_info.json
echo "codecov_info.json created"
- name: Upload JSON Artifact
uses: actions/upload-artifact@v4
with:
fail_ci_if_error: true
files: ./coverage.xml
flags: python-test
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
name: codecov-info
path: codecov_info.json


gradle-tests:
Expand Down Expand Up @@ -122,19 +123,16 @@ jobs:
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports
name: test-reports-gradle-tests
path: |
**/build/reports/tests/
**/reports/jacoco/mergedReport/
- name: Upload Coverage
uses: codecov/codecov-action@v4
- name: Upload Coverage Reports
uses: actions/upload-artifact@v4
with:
disable_search: true
fail_ci_if_error: true
files: ${{ github.workspace }}/build/reports/jacoco/mergedReport/jacocoMergedReport.xml
flags: gradle-test
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
if-no-files-found: error
name: coverage-reports-gradle-tests
path: /**/jacocoMergedReport.xml


python-e2e-tests:
Expand Down Expand Up @@ -236,15 +234,16 @@ jobs:
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}


all-ci-checks-pass:
needs:
- style-check
- node-tests
- console-python-tests
- gradle-tests
- link-checker
- node-tests
- python-e2e-tests
- python-lint
- python-tests
- style-check
if: always()
runs-on: ubuntu-latest
steps:
Expand All @@ -253,3 +252,4 @@ jobs:
echo "One or more job cancelled, failed, or skipped" && exit 1
- run: |
echo '## :heavy_check_mark: All continous integration checks pass' >> $GITHUB_STEP_SUMMARY
56 changes: 56 additions & 0 deletions .github/workflows/codecov-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Codecov Publish

# Due to the behavior of workflow_run, changes to this file will
# only be reflected once it is pushed up to the `default` (main) branch
#
# It is recommended to test changes to this file by pushing to the default branch
# on a fork and evaluating the correctness of the action execution

on:
workflow_run:
workflows: [CI]
types:
- completed

jobs:
publish-codecov:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Download CodeCov Info
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
name: codecov-info
run-id: ${{ github.event.workflow_run.id }}
- name: Set Environment Variables from JSON
run: |
ls
# Read the JSON file and export each key-value pair as an environment variable
for key in $(jq -r 'keys[]' ./codecov_info.json); do
value=$(jq -r --arg key "$key" '.[$key]' ./codecov_info.json)
echo "codecov_info_$key=$value"
echo "codecov_info_$key=$value" >> $GITHUB_ENV
done
- name: Download Coverage Artifacts
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./coverage-reports
pattern: coverage-reports-*
run-id: ${{ github.event.workflow_run.id }}

- name: Upload coverage report
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: /**/coverage-reports/**/*.*
flags: unittests
override_branch: ${{ env.codecov_info_branch }}
override_commit: ${{ env.codecov_info_commit }}
override_pr: ${{ env.codecov_info_pr_number }}
commit_parent: ${{ env.codecov_info_commit_parent }}
override_build_url: ${{ env.codecov_info_build_url }}
override_build: ${{ env.codecov_info_build }}
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ moto = {version = "*", extras = ["sts"]}

[requires]
python_version = "3.11"

[scripts]
test = "coverage run --source='.' manage.py test console_api"
coverage = "coverage"

0 comments on commit 70345f8

Please sign in to comment.