blob: a9706e77333cb38d6aeaa9eedafa0b50c3505477 [file] [log] [blame]
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
name: Upload to Codecov with retries
description: |
Checks that the current repository is public and then
uploads to codecov with multiple retries as a workaround
for these issues
- https://github.com/codecov/codecov-action/issues/598
- https://github.com/codecov/codecov-action/issues/837
inputs:
flags:
# see https://github.com/codecov/codecov-action#arguments
description: 'Flag the upload to group coverage metrics. Multiple flags are separated by a comma.'
runs:
using: composite
steps:
- name: "Check that repository is public"
id: repo-check
shell: bash
run: |
if [[ "${{ github.server_url }}" != "https://github.com" ]]; then
echo "Not using github.com server ('${{ github.server_url }}'). Skipping uploading of coverage metrics."
echo "passed=false" >> $GITHUB_OUTPUT
exit 0
fi
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
{
# public repository url will respond to http HEAD request
curl -X HEAD -fs "$REPO_URL" && echo "passed=true" >> $GITHUB_OUTPUT
} || {
echo "$REPO_URL isn't a public repository. Skipping uploading of coverage metrics."
echo "passed=false" >> $GITHUB_OUTPUT
}
- name: "Upload to Codecov (attempt #1)"
id: codecov-upload-1
if: steps.repo-check.outputs.passed == 'true'
uses: codecov/codecov-action@v3
continue-on-error: true
with:
flags: ${{ inputs.flags }}
fail_ci_if_error: true
verbose: true
- name: "Wait 15 seconds before next attempt"
if: steps.codecov-upload-1.outcome == 'failure'
shell: bash
run: sleep 15
- name: "Upload to Codecov (attempt #2)"
id: codecov-upload-2
if: steps.codecov-upload-1.outcome == 'failure'
uses: codecov/codecov-action@v3
continue-on-error: true
with:
flags: ${{ inputs.flags }}
fail_ci_if_error: true
verbose: true
- name: "Wait 60 seconds before next attempt"
if: steps.codecov-upload-2.outcome == 'failure'
shell: bash
run: sleep 60
- name: "Upload to Codecov (attempt #3)"
id: codecov-upload-3
if: steps.codecov-upload-2.outcome == 'failure'
uses: codecov/codecov-action@v3
# fail on last attempt
continue-on-error: false
with:
flags: ${{ inputs.flags }}
fail_ci_if_error: true
verbose: true
- name: "Show link to Codecov report"
shell: bash
run: |
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
head_sha=$(jq -r '.pull_request.head.sha' "${GITHUB_EVENT_PATH}")
else
head_sha=$(git rev-parse HEAD)
fi
tee -a "$GITHUB_STEP_SUMMARY" <<EOF
## Code Coverage report in Codecov
[Code coverage report](https://app.codecov.io/github/$GITHUB_REPOSITORY/commit/${head_sha}/tree)
EOF