Skip to content

Commit

Permalink
CH-9368: Added retry if rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-petrusheuski-covergo committed Sep 19, 2024
1 parent d6724db commit 37709f4
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 55 deletions.
47 changes: 41 additions & 6 deletions .gflows/libs/build_publish_steps.lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,48 @@ with:
---
#@ def _publish_test_result_as_check_step(filePath, check_name):
name: #@ "Publish {} results as check".format(check_name)
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
if: always()
with:
report_individual_runs: "true"
check_name: #@ "{} check".format(check_name)
github_token: ${{ secrets.GITHUB_TOKEN }}
files: #@ filePath
env:
CHECK_NAME: #@ "{} check".format(check_name)
FILE_PATH: #@ "{}".format(filePath)
run: |
RETRY_COUNT=0
MAX_RETRIES=3
BACKOFF=10
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# Check GitHub Rate Limit
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
if [ "$REMAINING" -lt 100 ]; then
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
continue
fi
# Publish test results as check
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
--check_name "$CHECK_NAME" \
--report_individual_runs "true" \
--files "$FILE_PATH"
# Check if publishing succeeded
if [ $? -eq 0 ]; then
echo "Test results published successfully!"
break
else
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
fi
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Max retries reached. Failing the job."
exit 1
fi
done
#@ end
---
#@ def _copy_between_registries_step(tag_from, tag_to, target_registry_name):
Expand Down
239 changes: 190 additions & 49 deletions github-sample/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,44 @@ jobs:
echo ::set-output name=is_production::true
fi
scan-code-net:
name: Sonar scan
timeout-minutes: 20
name: Sonar Code
runs-on: ubuntu-latest-4-cores
timeout-minutes: 10
needs:
- version
- docker-build-auth-service
- docker-build-auth-test-unit
- build-and-run-integration-tests
- run-acceptance-tests
- run-api-test-integration
- run-auth-test-unit
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Java 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: adopt
- name: Add GitHub Packages to NuGet config
env:
GH_ACCOUNT: ${{ secrets.PAT_USER_READ_PACKAGES }}
GH_TOKEN: ${{ secrets.PAT_READ_PACKAGES }}
- name: Setup Dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.x
- name: CoverGo Nuget
run: dotnet nuget update source github --username ${{ secrets.PAT_USER_READ_PACKAGES }} --password ${{ secrets.PAT_READ_PACKAGES }} --store-password-in-clear-text
- name: Download Coverage Artifacts
uses: actions/download-artifact@v4
with:
path: ./
- name: Fix coverage paths
run: |
dotnet nuget update source github --username ${GH_ACCOUNT} --password ${GH_TOKEN} --store-password-in-clear-text
- name: Scan
uses: CoverGo/[email protected]
with:
test-result-artifacts: Unit tests results,Integration tests results,Acceptance tests results,Integration API tests results
sonar-token: ${{ secrets.SONAR_TOKEN }}
coverage-solution-root-path: /sln
verbose: "true"
dotnet-build-command: dotnet build -v q -nologo --configuration Release
opencover-reports-paths: /**/*.opencover.test.xml
vstest-reports-paths: /**/*.test.trx
project-name: Auth Service
coverage-artifact-pooling-timeout-sec: "1200"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
echo "Root directory: $GITHUB_WORKSPACE"
find . -name "*.opencover.xml" -exec sed -i -e "s@/app@$GITHUB_WORKSPACE@g" {} \;
- name: SonarCloud Scan
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet sonarscanner begin /k:"${{ github.repository_owner }}_${{ github.event.repository.name }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /o:covergo /d:sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml
dotnet build --configuration Release
dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
scan-code:
name: Sonar scan
runs-on: ubuntu-latest
Expand Down Expand Up @@ -469,13 +470,48 @@ jobs:
!hep/**/.tmp
include-hidden-files: true
- name: Publish Unit tests results as check
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
if: always()
with:
report_individual_runs: "true"
check_name: Unit tests check
github_token: ${{ secrets.GITHUB_TOKEN }}
files: ./TestResults/**/*.xml
env:
CHECK_NAME: Unit tests check
FILE_PATH: ./TestResults/**/*.xml
run: |
RETRY_COUNT=0
MAX_RETRIES=3
BACKOFF=10
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# Check GitHub Rate Limit
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
if [ "$REMAINING" -lt 100 ]; then
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
continue
fi
# Publish test results as check
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
--check_name "$CHECK_NAME" \
--report_individual_runs "true" \
--files "$FILE_PATH"
# Check if publishing succeeded
if [ $? -eq 0 ]; then
echo "Test results published successfully!"
break
else
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
fi
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Max retries reached. Failing the job."
exit 1
fi
done
build-and-run-integration-tests:
name: Build and run Integration tests
timeout-minutes: 20
Expand Down Expand Up @@ -586,13 +622,48 @@ jobs:
path: TestResults
include-hidden-files: true
- name: Publish Integration tests results as check
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
if: always()
with:
report_individual_runs: "true"
check_name: Integration tests check
github_token: ${{ secrets.GITHUB_TOKEN }}
files: ./TestResults/**/*.xml
env:
CHECK_NAME: Integration tests check
FILE_PATH: ./TestResults/**/*.xml
run: |
RETRY_COUNT=0
MAX_RETRIES=3
BACKOFF=10
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# Check GitHub Rate Limit
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
if [ "$REMAINING" -lt 100 ]; then
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
continue
fi
# Publish test results as check
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
--check_name "$CHECK_NAME" \
--report_individual_runs "true" \
--files "$FILE_PATH"
# Check if publishing succeeded
if [ $? -eq 0 ]; then
echo "Test results published successfully!"
break
else
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
fi
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Max retries reached. Failing the job."
exit 1
fi
done
docker-build-acceptance-tests:
name: Build Acceptance tests image
timeout-minutes: 20
Expand Down Expand Up @@ -717,13 +788,48 @@ jobs:
path: TestResults
include-hidden-files: true
- name: Publish Acceptance tests results as check
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
if: always()
with:
report_individual_runs: "true"
check_name: Acceptance tests check
github_token: ${{ secrets.GITHUB_TOKEN }}
files: ./TestResults/TestResultJUnit.xml
env:
CHECK_NAME: Acceptance tests check
FILE_PATH: ./TestResults/TestResultJUnit.xml
run: |
RETRY_COUNT=0
MAX_RETRIES=3
BACKOFF=10
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# Check GitHub Rate Limit
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
if [ "$REMAINING" -lt 100 ]; then
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
continue
fi
# Publish test results as check
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
--check_name "$CHECK_NAME" \
--report_individual_runs "true" \
--files "$FILE_PATH"
# Check if publishing succeeded
if [ $? -eq 0 ]; then
echo "Test results published successfully!"
break
else
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
fi
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Max retries reached. Failing the job."
exit 1
fi
done
- name: Upload Acceptance tests results to Behave.Pro
if: always()
env:
Expand Down Expand Up @@ -874,13 +980,48 @@ jobs:
path: abc
include-hidden-files: true
- name: Publish Integration API tests results as check
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
if: always()
with:
report_individual_runs: "true"
check_name: Integration API tests check
github_token: ${{ secrets.GITHUB_TOKEN }}
files: ./TestResults/*.JUnit.xml
env:
CHECK_NAME: Integration API tests check
FILE_PATH: ./TestResults/*.JUnit.xml
run: |
RETRY_COUNT=0
MAX_RETRIES=3
BACKOFF=10
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# Check GitHub Rate Limit
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
if [ "$REMAINING" -lt 100 ]; then
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
continue
fi
# Publish test results as check
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
--check_name "$CHECK_NAME" \
--report_individual_runs "true" \
--files "$FILE_PATH"
# Check if publishing succeeded
if [ $? -eq 0 ]; then
echo "Test results published successfully!"
break
else
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
sleep $BACKOFF
BACKOFF=$((BACKOFF * 2))
RETRY_COUNT=$((RETRY_COUNT + 1))
fi
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Max retries reached. Failing the job."
exit 1
fi
done
docker-publish-github-auth-service:
name: Tag service image in GitHub
timeout-minutes: 20
Expand Down

0 comments on commit 37709f4

Please sign in to comment.