Skip to content

Commit 5c47607

Browse files
fix: override commit and pr values for PR cases (#1657)
* fix: override commit and pr values for PR cases * fix: remove unnecessary env vars * fix: add back in with env * fix: try no env * fix: do we need them at all? * fix: dollar curlies * fix: wrap github_env * fix: remove dollar curlies * fix: remove
1 parent 3b1354a commit 5c47607

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
deploy:
2-
$(eval VERSION := $(shell cat src/version | grep 'CODECOV_ACTION_VERSION=' | cut -d\" -f2))
2+
$(eval VERSION := $(shell cat src/version | grep 'CODECOV_ACTION_VERSION=' | cut -d\" -f2))
33
git tag -d v5
44
git push origin :v5
55
git tag v5

action.yml

+28-11
Original file line numberDiff line numberDiff line change
@@ -166,41 +166,61 @@ runs:
166166
if [ ${{ inputs.use_oidc }} == 'true' ];
167167
then
168168
# {"count":1984,"value":"***"}
169-
CODECOV_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange" | cut -d\' -f6)
170-
echo "CODECOV_TOKEN=$CODECOV_TOKEN" >> $GITHUB_ENV
169+
CC_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange" | cut -d\' -f6)
170+
echo "CC_TOKEN=$CC_TOKEN" >> "$GITHUB_ENV"
171171
else
172172
if [ -n ${{ inputs.token }} ];
173173
then
174-
CODECOV_TOKEN=${{ inputs.token }}
175-
echo "CODECOV_TOKEN=$CODECOV_TOKEN" >> $GITHUB_ENV
174+
CC_TOKEN=${{ inputs.token }}
175+
echo "CC_TOKEN=$CC_TOKEN" >> "$GITHUB_ENV"
176176
fi
177177
fi
178178
179179
- name: Override branch for forks
180180
shell: bash
181181
run: |
182-
if [ -z "$CC_BRANCH" ] && [ -z "$CODECOV_TOKEN" ] && [ "${GITHUB_EVENT_PULL_REQUEST_REPO_FULL_NAME}" != "$GITHUB_REPOSITORY" ];
182+
if [ -z "$CC_BRANCH" ] && [ -z "$CC_TOKEN" ] && [ "${GITHUB_EVENT_PULL_REQUEST_REPO_FULL_NAME}" != "$GITHUB_REPOSITORY" ];
183183
then
184184
echo -e "\033[0;32m==>\033[0m Fork detected, tokenless uploading used"
185185
TOKENLESS="$GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL"
186186
CC_BRANCH="$GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL"
187-
echo "TOKENLESS=$TOKENLESS" >> $GITHUB_ENV
187+
echo "TOKENLESS=$TOKENLESS" >> "$GITHUB_ENV"
188188
fi
189189
190-
echo "CC_BRANCH=$CC_BRANCH" >> $GITHUB_ENV
190+
echo "CC_BRANCH=$CC_BRANCH" >> "$GITHUB_ENV"
191191
env:
192192
CC_BRANCH: ${{ inputs.override_branch }}
193193
GITHUB_EVENT_PULL_REQUEST_HEAD_LABEL: ${{ github.event.pull_request.head.label }}
194194
GITHUB_EVENT_PULL_REQUEST_REPO_FULL_NAME: ${{ github.event.pull_request.repo.full_name }}
195195
GITHUB_REPOSITORY: ${{ github.repository }}
196196

197+
- name: Override commits and pr for pull requests
198+
shell: bash
199+
run: |
200+
if [ -z "$CC_SHA" ];
201+
then
202+
CC_SHA="$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA"
203+
fi
204+
if [ -z "$CC_PR" ] && [ "${GITHUB_EVENT_NAME}" == "pull_request_target" ];
205+
then
206+
CC_PR="$GITHUB_EVENT_NUMBER"
207+
fi
208+
209+
echo "CC_SHA=$CC_SHA" >> "$GITHUB_ENV"
210+
echo "CC_PR=$CC_PR" >> "$GITHUB_ENV"
211+
env:
212+
CC_PR: ${{ inputs.override_pr }}
213+
CC_SHA: ${{ inputs.override_commit }}
214+
GITHUB_EVENT_NAME: ${{ github.event_name }}
215+
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
216+
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
217+
197218
- name: Upload coverage to Codecov
198219
run: ${GITHUB_ACTION_PATH}/dist/codecov.sh
199220
shell: bash
200221
working-directory: ${{ inputs.working-directory }}
201222
env:
202223
CC_BINARY: ${{ inputs.binary }}
203-
CC_BRANCH: $CC_BRANCH
204224
CC_BUILD: ${{ inputs.override_build }}
205225
CC_BUILD_URL: ${{ inputs.override_build_url }}
206226
CC_CODE: ${{ inputs.report_code }}
@@ -229,13 +249,10 @@ runs:
229249
CC_OS: ${{ inputs.os }}
230250
CC_PARENT_SHA: ${{ inputs.commit_parent }}
231251
CC_PLUGINS: ${{ inputs.plugins }}
232-
CC_PR: ${{ inputs.override_pr }}
233252
CC_REPORT_TYPE: ${{ inputs.report_type }}
234-
CC_SHA: ${{ inputs.override_commit }}
235253
CC_SKIP_VALIDATION: ${{ inputs.skip_validation }}
236254
CC_SLUG: ${{ inputs.slug }}
237255
CC_SWIFT_PROJECT: ${{ inputs.swift_project }}
238-
CC_TOKEN: $CODECOV_TOKEN
239256
CC_VERBOSE: ${{ inputs.verbose }}
240257
CC_VERSION: ${{ inputs.version }}
241258
CC_YML_PATH: ${{ inputs.codecov_yml_path }}

src/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CODECOV_ACTION_VERSION="5.0.1"
1+
CODECOV_ACTION_VERSION="5.0.2"

0 commit comments

Comments
 (0)