Skip to content

Commit 11e564c

Browse files
authored
fix: Allow fork PRs to run without CODECOV_TOKEN (#240)
Closes: apify/apify-sdk-python#728
1 parent e86aabf commit 11e564c

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

.github/workflows/python_integration_tests.yaml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
description: Apify API token for a secondary test user, used in multi-user scenarios (e.g. sharing restricted storage).
1111
required: false
1212
CODECOV_TOKEN:
13-
required: true
13+
required: false
1414
description: Token for uploading coverage reports to Codecov.
1515
inputs:
1616
python-versions:
@@ -41,7 +41,11 @@ jobs:
4141
name: Integration tests
4242

4343
# Run this only for PRs from the main repository or for pushes to master. Skip otherwise.
44-
if: github.event.pull_request.head.repo.owner.login == 'apify' || github.ref == 'refs/heads/master'
44+
if: >-
45+
${{
46+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.owner.login == 'apify') ||
47+
(github.event_name == 'push' && github.ref == 'refs/heads/master')
48+
}}
4549
4650
strategy:
4751
matrix:
@@ -51,6 +55,9 @@ jobs:
5155

5256
runs-on: ${{ matrix.os }}
5357

58+
env:
59+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
60+
5461
steps:
5562
- name: Checkout repository
5663
uses: actions/checkout@v6
@@ -74,11 +81,17 @@ jobs:
7481
APIFY_TEST_USER_API_TOKEN: ${{ secrets.APIFY_TEST_USER_PYTHON_SDK_API_TOKEN }}
7582
APIFY_TEST_USER_2_API_TOKEN: ${{ secrets.APIFY_TEST_USER_2_API_TOKEN }}
7683

77-
# Upload coverage only for the latest Python to avoid redundant uploads.
84+
# Upload coverage only for the ubuntu-latest and latest Python, and only when the Codecov token
85+
# is available (e.g. not for fork PRs).
7886
- name: Upload integration test coverage
79-
if: ${{ matrix.os == inputs.operating-system-for-codecov && matrix.python-version == inputs.python-version-for-codecov }}
87+
if: >-
88+
${{
89+
matrix.os == inputs.operating-system-for-codecov &&
90+
matrix.python-version == inputs.python-version-for-codecov &&
91+
env.CODECOV_TOKEN != ''
92+
}}
8093
uses: codecov/codecov-action@v5
8194
with:
82-
token: ${{ secrets.CODECOV_TOKEN }}
95+
token: ${{ env.CODECOV_TOKEN }}
8396
files: coverage-integration.xml
8497
flags: integration

.github/workflows/python_unit_tests.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
required: false
88
description: URL that sets the HTTPBIN_URL environment variable.
99
CODECOV_TOKEN:
10-
required: true
10+
required: false
1111
description: Token for uploading coverage reports to Codecov.
1212
inputs:
1313
python-versions:
@@ -38,6 +38,7 @@ jobs:
3838
runs-on: ${{ matrix.os }}
3939
env:
4040
HTTPBIN_URL: ${{ secrets.httpbin_url || 'https://httpbin.org' }}
41+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4142

4243
steps:
4344
- name: macOS cleanup
@@ -66,11 +67,17 @@ jobs:
6667
- name: Run unit tests
6768
run: make unit-tests-cov
6869

69-
# Upload coverage only for the ubuntu-latest and latest Python to avoid redundant uploads.
70+
# Upload coverage only for the ubuntu-latest and latest Python, and only when the Codecov token
71+
# is available (e.g. not for fork PRs).
7072
- name: Upload unit test coverage
71-
if: ${{ matrix.os == inputs.operating-system-for-codecov && matrix.python-version == inputs.python-version-for-codecov }}
73+
if: >-
74+
${{
75+
matrix.os == inputs.operating-system-for-codecov &&
76+
matrix.python-version == inputs.python-version-for-codecov &&
77+
env.CODECOV_TOKEN != ''
78+
}}
7279
uses: codecov/codecov-action@v5
7380
with:
74-
token: ${{ secrets.CODECOV_TOKEN }}
81+
token: ${{ env.CODECOV_TOKEN }}
7582
files: coverage-unit.xml
7683
flags: unit

0 commit comments

Comments
 (0)