Skip to content

Commit c1c5b11

Browse files
committed
Implement tokenless coverage report uploads for forks
Signed-off-by: Shyamsundar Gadde <[email protected]>
1 parent 93dbf21 commit c1c5b11

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

.github/workflows/php-test-plugins.yml

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ jobs:
128128
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress
129129
- name: Update Composer Dependencies
130130
run: composer update --with-all-dependencies --no-interaction --no-progress
131-
- name: Download Codecov CLI
132-
if: ${{ matrix.coverage == true }}
133-
run: |
134-
# Create a temporary directory for GPG operations
135-
mkdir -p .gpg
136-
137-
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --homedir .gpg --no-default-keyring --keyring trustedkeys.gpg --import
138-
curl -Os https://cli.codecov.io/latest/linux/codecov
139-
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM
140-
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM.sig
141-
gpg --homedir .gpg --no-default-keyring --keyring trustedkeys.gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
142-
shasum -a 256 -c codecov.SHA256SUM
143-
chmod +x codecov
144131
- name: Install PHPUnit
145132
run: |
146133
if [ "${{ matrix.php }}" == "8.2" ]; then
@@ -154,13 +141,6 @@ jobs:
154141
if [ "${{ matrix.coverage }}" == "true" ]; then
155142
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
156143
npm run test-php:$PLUGIN -- -- -- --coverage-clover=./single-site-reports/coverage-$PLUGIN.xml
157-
158-
# Upload coverage report to Codecov.
159-
./codecov --verbose upload-process --disable-search --fail-on-error \
160-
-t ${{ secrets.CODECOV_TOKEN }} \
161-
-n ${{ matrix.php }}-$PLUGIN-single-site-coverage \
162-
-F $PLUGIN \
163-
-f ./single-site-reports/coverage-$PLUGIN.xml
164144
done
165145
else
166146
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
@@ -172,16 +152,57 @@ jobs:
172152
if [ "${{ matrix.coverage }}" == "true" ]; then
173153
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
174154
npm run test-php-multisite:$PLUGIN -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-$PLUGIN.xml
175-
176-
# Upload coverage report to Codecov.
177-
./codecov --verbose upload-process --disable-search --fail-on-error \
178-
-t ${{ secrets.CODECOV_TOKEN }} \
179-
-n ${{ matrix.php }}-$PLUGIN-multisite-coverage \
180-
-F $PLUGIN \
181-
-f ./multisite-reports/coverage-multisite-$PLUGIN.xml
182155
done
183156
else
184157
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
185158
npm run test-php-multisite:$PLUGIN
186159
done
187160
fi
161+
- name: Download Codecov CLI
162+
if: ${{ matrix.coverage == true }}
163+
run: |
164+
# Create a temporary directory for GPG operations
165+
mkdir -p .gpg
166+
167+
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --homedir .gpg --no-default-keyring --keyring trustedkeys.gpg --import
168+
curl -Os https://cli.codecov.io/latest/linux/codecov
169+
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM
170+
curl -Os https://cli.codecov.io/latest/linux/codecov.SHA256SUM.sig
171+
gpg --homedir .gpg --no-default-keyring --keyring trustedkeys.gpg --verify codecov.SHA256SUM.sig codecov.SHA256SUM
172+
shasum -a 256 -c codecov.SHA256SUM
173+
chmod +x codecov
174+
- name: Upload coverage reports to Codecov
175+
if: ${{ matrix.coverage == true }}
176+
run: |
177+
# Build common arguments for all uploads
178+
cc_args=()
179+
cc_args+=(--fail-on-error)
180+
cc_args+=(--disable-search)
181+
cc_args+=(--git-service github)
182+
cc_args+=(--gcov-executable "gcov")
183+
184+
# Add SHA for PRs
185+
if [ -n "${{ github.event.pull_request.head.sha }}" ]; then
186+
cc_args+=(--sha "${{ github.event.pull_request.head.sha }}")
187+
fi
188+
189+
# Handle authentication differently for forks vs. internal PRs
190+
if [ -n "${{ github.event.pull_request.head.repo.full_name }}" ] && \
191+
[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
192+
echo "::notice::Processing PR from fork - using tokenless upload with branch override."
193+
cc_args+=(--branch "${{ github.event.pull_request.head.label }}")
194+
else
195+
echo "::notice::Processing internal PR or push - using token."
196+
cc_args+=(--token "${{ secrets.CODECOV_TOKEN }}")
197+
fi
198+
199+
# Upload reports for each changed plugin
200+
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
201+
echo "::group::Uploading coverage for plugin: $PLUGIN"
202+
./codecov upload-coverage "${cc_args[@]}" \
203+
--file ./single-site-reports/coverage-$PLUGIN.xml \
204+
--file ./multisite-reports/coverage-multisite-$PLUGIN.xml \
205+
--flag $PLUGIN \
206+
--name $PLUGIN-coverage
207+
echo "::endgroup::"
208+
done

0 commit comments

Comments
 (0)