Skip to content

Commit 40e7f63

Browse files
authored
Merge pull request #42 from codecov/matt/use-codecov-action
use codecov actions to upload instead of the cli
2 parents 285163a + 54543ce commit 40e7f63

File tree

2 files changed

+217
-39
lines changed

2 files changed

+217
-39
lines changed

.github/workflows/run-tests-split.yml

Lines changed: 122 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,37 @@ on:
1414
type: number
1515
required: false
1616
default: 5
17+
flag_prefix:
18+
type: string
19+
default: ''
1720
env:
1821
AR_REPO: ${{ inputs.repo }}
1922

2023
jobs:
24+
# Create a list from 1 to `inputs.split` to use as our matrix for `test`
25+
prepare_groups:
26+
name: Prepare groups
27+
runs-on: ubuntu-latest
28+
outputs:
29+
groups: ${{ steps.prepare_groups.outputs.groups }}
30+
# echo {1..5} => 1 2 3 4 5
31+
# echo {1..5} | sed 's/ /, /g' => 1, 2, 3, 4, 5
32+
# echo '[$(echo {1..5} | sed 's/ /, /g')]' => [1, 2, 3, 4, 5]
33+
steps:
34+
- name: Prepare groups
35+
id: prepare_groups
36+
run: |
37+
group_list=$(echo "[$(echo {1..${{ inputs.split }}} | sed 's/ /, /g')]")
38+
echo "groups=$group_list" >> $GITHUB_OUTPUT
39+
2140
test:
2241
name: Test
2342
runs-on: ubuntu-latest
43+
needs: [prepare_groups]
2444
strategy:
2545
matrix:
26-
group: [1, 2, 3, 4, 5]
46+
# Parse our group list into a JSON object
47+
group: ${{ fromJSON(needs.prepare_groups.outputs.groups) }}
2748
steps:
2849
- name: Checkout
2950
uses: actions/checkout@v4
@@ -59,20 +80,103 @@ jobs:
5980
if: inputs.run_integration == true
6081
run: |
6182
make test_env.run_integration GROUP=${{ matrix.group }} SPLIT=${{ inputs.split }}
62-
## Don't upload on forks for now.
63-
- name: upload using codecovcli
64-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
65-
run: |
66-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_ORG_TOKEN }} CODECOV_URL=${{ secrets.CODECOV_URL }}
67-
- name: upload using codecovcli staging
68-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
69-
run: |
70-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_ORG_TOKEN_STAGING }} CODECOV_URL=${{ secrets.CODECOV_STAGING_URL }}
71-
- name: upload using codecovcli qa
72-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
73-
run: |
74-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_QA_TOKEN }} CODECOV_URL=${{ secrets.CODECOV_QA_URL }}
75-
- name: upload using codecovcli public qa
76-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
77-
run: |
78-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_PUBLIC_QA_TOKEN }} CODECOV_URL=${{ secrets.CODECOV_PUBLIC_QA_URL }}
83+
84+
- uses: actions/upload-artifact@v4
85+
if: ${{ !cancelled() }}
86+
with:
87+
name: coveragefiles-${{ matrix.group }}
88+
path: ./*.coverage.xml
89+
90+
- uses: actions/upload-artifact@v4
91+
if: ${{ !cancelled() }}
92+
with:
93+
name: junitfiles-${{ matrix.group }}
94+
path: ./*junit*.xml
95+
96+
upload:
97+
name: Upload to Codecov
98+
runs-on: ubuntu-latest
99+
needs: [test]
100+
strategy:
101+
matrix:
102+
include:
103+
- codecov_url_secret: CODECOV_URL
104+
codecov_token_secret: CODECOV_ORG_TOKEN
105+
name: prod
106+
- codecov_url_secret: CODECOV_STAGING_URL
107+
codecov_token_secret: CODECOV_ORG_TOKEN_STAGING
108+
name: staging
109+
- codecov_url_secret: CODECOV_QA_URL
110+
codecov_token_secret: CODECOV_QA_ORG
111+
name: qa
112+
- codecov_url_secret: CODECOV_PUBLIC_QA_URL
113+
codecov_token_secret: CODECOV_PUBLIC_QA_TOKEN
114+
name: public qa
115+
116+
steps:
117+
- name: Checkout
118+
uses: actions/checkout@v4
119+
with:
120+
fetch-depth: 0
121+
122+
- name: Download coverage
123+
uses: actions/download-artifact@v4
124+
with:
125+
pattern: coveragefiles-*
126+
merge-multiple: true
127+
128+
- name: Download test results
129+
uses: actions/download-artifact@v4
130+
with:
131+
pattern: junitfiles-*
132+
merge-multiple: true
133+
134+
- name: Uploading unit test coverage (${{ matrix.name }})
135+
uses: codecov/codecov-action@v5
136+
with:
137+
files: ./unit.*.coverage.xml
138+
flags: ${{ format('{0}unit', inputs.flag_prefix) }}
139+
disable_search: true
140+
# Strange workaround: API has a `codecov` directory in the repo root
141+
# which conflicts with the action's `codecov` binary
142+
use_pypi: true
143+
token: ${{ secrets[matrix.codecov_token_secret] }}
144+
url: ${{ secrets[matrix.codecov_url_secret] }}
145+
146+
- name: Uploading integration test coverage (${{ matrix.name }})
147+
if: ${{ inputs.run_integration == true }}
148+
uses: codecov/codecov-action@v5
149+
with:
150+
files: ./integration.*.coverage.xml
151+
flags: ${{ format('{0}integration', inputs.flag_prefix) }}
152+
disable_search: true
153+
# Strange workaround: API has a `codecov` directory in the repo root
154+
# which conflicts with the action's `codecov` binary
155+
use_pypi: true
156+
token: ${{ secrets[matrix.codecov_token_secret] }}
157+
url: ${{ secrets[matrix.codecov_url_secret] }}
158+
159+
- name: Uploading unit test results (${{ matrix.name }})
160+
uses: codecov/test-results-action@v1
161+
with:
162+
files: ./unit.*.junit.xml
163+
flags: ${{ format('{0}unit', inputs.flag_prefix) }}
164+
disable_search: true
165+
token: ${{ secrets[matrix.codecov_token_secret] }}
166+
url: ${{ secrets[matrix.codecov_url_secret] }}
167+
# The coverage action will have installed codecovcli with pip. The
168+
# actual binary will be found in $PATH.
169+
binary: codecovcli
170+
171+
- name: Uploading integration test results (${{ matrix.name }})
172+
if: ${{ inputs.run_integration == true }}
173+
uses: codecov/test-results-action@v1
174+
with:
175+
files: ./integration.*.junit.xml
176+
flags: ${{ format('{0}integration', inputs.flag_prefix) }}
177+
disable_search: true
178+
token: ${{ secrets[matrix.codecov_token_secret] }}
179+
url: ${{ secrets[matrix.codecov_url_secret] }}
180+
# The coverage action will have installed codecovcli with pip. The
181+
# actual binary will be found in $PATH.
182+
binary: codecovcli

.github/workflows/run-tests.yml

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
repo:
1111
type: string
1212
required: true
13+
flag_prefix:
14+
type: string
15+
default: ''
1316
env:
1417
AR_REPO: ${{ inputs.repo }}
1518

@@ -52,30 +55,101 @@ jobs:
5255
if: ${{ !cancelled() && inputs.run_integration == true }}
5356
run: |
5457
make test_env.run_integration
58+
59+
- uses: actions/upload-artifact@v4
60+
if: ${{ !cancelled() }}
61+
with:
62+
name: coveragefiles
63+
path: ./*.coverage.xml
64+
5565
- uses: actions/upload-artifact@v4
5666
if: ${{ !cancelled() }}
5767
with:
5868
name: junitfiles
5969
path: ./*junit*.xml
60-
## Don't upload on forks for now.
61-
- name: upload using codecovcli
62-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
63-
run: |
64-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_ORG_TOKEN }} CODECOV_URL=${{ secrets.CODECOV_URL }}
65-
- name: upload using codecovcli staging
66-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
67-
run: |
68-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_ORG_TOKEN_STAGING }} CODECOV_URL=${{ secrets.CODECOV_STAGING_URL }}
69-
- name: upload using codecovcli qa
70-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
71-
run: |
72-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_QA_TOKEN }} CODECOV_URL=${{ secrets.CODECOV_QA_URL }}
73-
- name: upload using codecovcli public qa
74-
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
75-
run: |
76-
make test_env.upload CODECOV_UPLOAD_TOKEN=${{ secrets.CODECOV_PUBLIC_QA_TOKEN }} CODECOV_URL=${{ secrets.CODECOV_PUBLIC_QA_URL }}
77-
- name: run basic-test-results
78-
if: ${{ !cancelled() && github.ref && contains(github.ref, 'pull') && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
79-
uses: codecov/basic-test-results@v1
70+
71+
upload:
72+
name: Upload to Codecov
73+
runs-on: ubuntu-latest
74+
needs: [test]
75+
strategy:
76+
matrix:
77+
include:
78+
- codecov_url_secret: CODECOV_URL
79+
codecov_token_secret: CODECOV_ORG_TOKEN
80+
name: prod
81+
- codecov_url_secret: CODECOV_STAGING_URL
82+
codecov_token_secret: CODECOV_ORG_TOKEN_STAGING
83+
name: staging
84+
- codecov_url_secret: CODECOV_QA_URL
85+
codecov_token_secret: CODECOV_QA_ORG
86+
name: qa
87+
- codecov_url_secret: CODECOV_PUBLIC_QA_URL
88+
codecov_token_secret: CODECOV_PUBLIC_QA_TOKEN
89+
name: public qa
90+
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v4
94+
with:
95+
fetch-depth: 0
96+
97+
- name: Download coverage
98+
uses: actions/download-artifact@v4
99+
with:
100+
name: coveragefiles
101+
102+
- name: Download test results
103+
uses: actions/download-artifact@v4
104+
with:
105+
name: junitfiles
106+
107+
- name: Uploading unit test coverage (${{ matrix.name }})
108+
uses: codecov/codecov-action@v5
109+
with:
110+
files: ./unit.coverage.xml
111+
flags: ${{ format('{0}unit', inputs.flag_prefix) }}
112+
disable_search: true
113+
# Strange workaround: API has a `codecov` directory in the repo root
114+
# which conflicts with the action's `codecov` binary
115+
use_pypi: true
116+
token: ${{ secrets[matrix.codecov_token_secret] }}
117+
url: ${{ secrets[matrix.codecov_url_secret] }}
118+
119+
- name: Uploading integration test coverage (${{ matrix.name }})
120+
if: ${{ inputs.run_integration == true }}
121+
uses: codecov/codecov-action@v5
122+
with:
123+
files: ./integration.coverage.xml
124+
flags: ${{ format('{0}integration', inputs.flag_prefix) }}
125+
disable_search: true
126+
# Strange workaround: API has a `codecov` directory in the repo root
127+
# which conflicts with the action's `codecov` binary
128+
use_pypi: true
129+
token: ${{ secrets[matrix.codecov_token_secret] }}
130+
url: ${{ secrets[matrix.codecov_url_secret] }}
131+
132+
- name: Uploading unit test results (${{ matrix.name }})
133+
uses: codecov/test-results-action@v1
134+
with:
135+
files: ./unit.junit.xml
136+
flags: ${{ format('{0}unit', inputs.flag_prefix) }}
137+
disable_search: true
138+
token: ${{ secrets[matrix.codecov_token_secret] }}
139+
url: ${{ secrets[matrix.codecov_url_secret] }}
140+
# The coverage action will have installed codecovcli with pip. The
141+
# actual binary will be found in $PATH.
142+
binary: codecovcli
143+
144+
- name: Uploading integration test results (${{ matrix.name }})
145+
if: ${{ inputs.run_integration == true }}
146+
uses: codecov/test-results-action@v1
80147
with:
81-
github-token: ${{ secrets.GITHUB_TOKEN }}
148+
files: ./integration.junit.xml
149+
flags: ${{ format('{0}integration', inputs.flag_prefix) }}
150+
disable_search: true
151+
token: ${{ secrets[matrix.codecov_token_secret] }}
152+
url: ${{ secrets[matrix.codecov_url_secret] }}
153+
# The coverage action will have installed codecovcli with pip. The
154+
# actual binary will be found in $PATH.
155+
binary: codecovcli

0 commit comments

Comments
 (0)