Skip to content

Commit 37709f4

Browse files
CH-9368: Added retry if rate limit
1 parent d6724db commit 37709f4

File tree

2 files changed

+231
-55
lines changed

2 files changed

+231
-55
lines changed

.gflows/libs/build_publish_steps.lib.yml

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,48 @@ with:
5858
---
5959
#@ def _publish_test_result_as_check_step(filePath, check_name):
6060
name: #@ "Publish {} results as check".format(check_name)
61-
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
6261
if: always()
63-
with:
64-
report_individual_runs: "true"
65-
check_name: #@ "{} check".format(check_name)
66-
github_token: ${{ secrets.GITHUB_TOKEN }}
67-
files: #@ filePath
62+
env:
63+
CHECK_NAME: #@ "{} check".format(check_name)
64+
FILE_PATH: #@ "{}".format(filePath)
65+
run: |
66+
RETRY_COUNT=0
67+
MAX_RETRIES=3
68+
BACKOFF=10
69+
70+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
71+
# Check GitHub Rate Limit
72+
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
73+
if [ "$REMAINING" -lt 100 ]; then
74+
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
75+
sleep $BACKOFF
76+
BACKOFF=$((BACKOFF * 2))
77+
RETRY_COUNT=$((RETRY_COUNT + 1))
78+
continue
79+
fi
80+
81+
# Publish test results as check
82+
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
83+
--check_name "$CHECK_NAME" \
84+
--report_individual_runs "true" \
85+
--files "$FILE_PATH"
86+
87+
# Check if publishing succeeded
88+
if [ $? -eq 0 ]; then
89+
echo "Test results published successfully!"
90+
break
91+
else
92+
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
93+
sleep $BACKOFF
94+
BACKOFF=$((BACKOFF * 2))
95+
RETRY_COUNT=$((RETRY_COUNT + 1))
96+
fi
97+
98+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
99+
echo "Max retries reached. Failing the job."
100+
exit 1
101+
fi
102+
done
68103
#@ end
69104
---
70105
#@ def _copy_between_registries_step(tag_from, tag_to, target_registry_name):

github-sample/workflows/build-publish.yml

Lines changed: 190 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,44 @@ jobs:
4444
echo ::set-output name=is_production::true
4545
fi
4646
scan-code-net:
47-
name: Sonar scan
48-
timeout-minutes: 20
47+
name: Sonar Code
4948
runs-on: ubuntu-latest-4-cores
49+
timeout-minutes: 10
5050
needs:
5151
- version
52-
- docker-build-auth-service
53-
- docker-build-auth-test-unit
52+
- build-and-run-integration-tests
53+
- run-acceptance-tests
54+
- run-api-test-integration
55+
- run-auth-test-unit
5456
steps:
55-
- name: Checkout repository
56-
uses: actions/checkout@v3
57+
- uses: actions/checkout@v3
5758
with:
5859
fetch-depth: 0
5960
- name: Set up Java 17
6061
uses: actions/setup-java@v3
6162
with:
6263
java-version: 17
6364
distribution: adopt
64-
- name: Add GitHub Packages to NuGet config
65-
env:
66-
GH_ACCOUNT: ${{ secrets.PAT_USER_READ_PACKAGES }}
67-
GH_TOKEN: ${{ secrets.PAT_READ_PACKAGES }}
65+
- name: Setup Dotnet
66+
uses: actions/setup-dotnet@v4
67+
with:
68+
dotnet-version: 6.x
69+
- name: CoverGo Nuget
70+
run: dotnet nuget update source github --username ${{ secrets.PAT_USER_READ_PACKAGES }} --password ${{ secrets.PAT_READ_PACKAGES }} --store-password-in-clear-text
71+
- name: Download Coverage Artifacts
72+
uses: actions/download-artifact@v4
73+
with:
74+
path: ./
75+
- name: Fix coverage paths
6876
run: |
69-
dotnet nuget update source github --username ${GH_ACCOUNT} --password ${GH_TOKEN} --store-password-in-clear-text
70-
- name: Scan
71-
uses: CoverGo/[email protected]
72-
with:
73-
test-result-artifacts: Unit tests results,Integration tests results,Acceptance tests results,Integration API tests results
74-
sonar-token: ${{ secrets.SONAR_TOKEN }}
75-
coverage-solution-root-path: /sln
76-
verbose: "true"
77-
dotnet-build-command: dotnet build -v q -nologo --configuration Release
78-
opencover-reports-paths: /**/*.opencover.test.xml
79-
vstest-reports-paths: /**/*.test.trx
80-
project-name: Auth Service
81-
coverage-artifact-pooling-timeout-sec: "1200"
82-
env:
83-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
echo "Root directory: $GITHUB_WORKSPACE"
78+
find . -name "*.opencover.xml" -exec sed -i -e "s@/app@$GITHUB_WORKSPACE@g" {} \;
79+
- name: SonarCloud Scan
80+
run: |
81+
dotnet tool install --global dotnet-sonarscanner
82+
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
83+
dotnet build --configuration Release
84+
dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
8485
scan-code:
8586
name: Sonar scan
8687
runs-on: ubuntu-latest
@@ -469,13 +470,48 @@ jobs:
469470
!hep/**/.tmp
470471
include-hidden-files: true
471472
- name: Publish Unit tests results as check
472-
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
473473
if: always()
474-
with:
475-
report_individual_runs: "true"
476-
check_name: Unit tests check
477-
github_token: ${{ secrets.GITHUB_TOKEN }}
478-
files: ./TestResults/**/*.xml
474+
env:
475+
CHECK_NAME: Unit tests check
476+
FILE_PATH: ./TestResults/**/*.xml
477+
run: |
478+
RETRY_COUNT=0
479+
MAX_RETRIES=3
480+
BACKOFF=10
481+
482+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
483+
# Check GitHub Rate Limit
484+
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
485+
if [ "$REMAINING" -lt 100 ]; then
486+
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
487+
sleep $BACKOFF
488+
BACKOFF=$((BACKOFF * 2))
489+
RETRY_COUNT=$((RETRY_COUNT + 1))
490+
continue
491+
fi
492+
493+
# Publish test results as check
494+
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
495+
--check_name "$CHECK_NAME" \
496+
--report_individual_runs "true" \
497+
--files "$FILE_PATH"
498+
499+
# Check if publishing succeeded
500+
if [ $? -eq 0 ]; then
501+
echo "Test results published successfully!"
502+
break
503+
else
504+
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
505+
sleep $BACKOFF
506+
BACKOFF=$((BACKOFF * 2))
507+
RETRY_COUNT=$((RETRY_COUNT + 1))
508+
fi
509+
510+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
511+
echo "Max retries reached. Failing the job."
512+
exit 1
513+
fi
514+
done
479515
build-and-run-integration-tests:
480516
name: Build and run Integration tests
481517
timeout-minutes: 20
@@ -586,13 +622,48 @@ jobs:
586622
path: TestResults
587623
include-hidden-files: true
588624
- name: Publish Integration tests results as check
589-
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
590625
if: always()
591-
with:
592-
report_individual_runs: "true"
593-
check_name: Integration tests check
594-
github_token: ${{ secrets.GITHUB_TOKEN }}
595-
files: ./TestResults/**/*.xml
626+
env:
627+
CHECK_NAME: Integration tests check
628+
FILE_PATH: ./TestResults/**/*.xml
629+
run: |
630+
RETRY_COUNT=0
631+
MAX_RETRIES=3
632+
BACKOFF=10
633+
634+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
635+
# Check GitHub Rate Limit
636+
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
637+
if [ "$REMAINING" -lt 100 ]; then
638+
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
639+
sleep $BACKOFF
640+
BACKOFF=$((BACKOFF * 2))
641+
RETRY_COUNT=$((RETRY_COUNT + 1))
642+
continue
643+
fi
644+
645+
# Publish test results as check
646+
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
647+
--check_name "$CHECK_NAME" \
648+
--report_individual_runs "true" \
649+
--files "$FILE_PATH"
650+
651+
# Check if publishing succeeded
652+
if [ $? -eq 0 ]; then
653+
echo "Test results published successfully!"
654+
break
655+
else
656+
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
657+
sleep $BACKOFF
658+
BACKOFF=$((BACKOFF * 2))
659+
RETRY_COUNT=$((RETRY_COUNT + 1))
660+
fi
661+
662+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
663+
echo "Max retries reached. Failing the job."
664+
exit 1
665+
fi
666+
done
596667
docker-build-acceptance-tests:
597668
name: Build Acceptance tests image
598669
timeout-minutes: 20
@@ -717,13 +788,48 @@ jobs:
717788
path: TestResults
718789
include-hidden-files: true
719790
- name: Publish Acceptance tests results as check
720-
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
721791
if: always()
722-
with:
723-
report_individual_runs: "true"
724-
check_name: Acceptance tests check
725-
github_token: ${{ secrets.GITHUB_TOKEN }}
726-
files: ./TestResults/TestResultJUnit.xml
792+
env:
793+
CHECK_NAME: Acceptance tests check
794+
FILE_PATH: ./TestResults/TestResultJUnit.xml
795+
run: |
796+
RETRY_COUNT=0
797+
MAX_RETRIES=3
798+
BACKOFF=10
799+
800+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
801+
# Check GitHub Rate Limit
802+
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
803+
if [ "$REMAINING" -lt 100 ]; then
804+
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
805+
sleep $BACKOFF
806+
BACKOFF=$((BACKOFF * 2))
807+
RETRY_COUNT=$((RETRY_COUNT + 1))
808+
continue
809+
fi
810+
811+
# Publish test results as check
812+
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
813+
--check_name "$CHECK_NAME" \
814+
--report_individual_runs "true" \
815+
--files "$FILE_PATH"
816+
817+
# Check if publishing succeeded
818+
if [ $? -eq 0 ]; then
819+
echo "Test results published successfully!"
820+
break
821+
else
822+
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
823+
sleep $BACKOFF
824+
BACKOFF=$((BACKOFF * 2))
825+
RETRY_COUNT=$((RETRY_COUNT + 1))
826+
fi
827+
828+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
829+
echo "Max retries reached. Failing the job."
830+
exit 1
831+
fi
832+
done
727833
- name: Upload Acceptance tests results to Behave.Pro
728834
if: always()
729835
env:
@@ -874,13 +980,48 @@ jobs:
874980
path: abc
875981
include-hidden-files: true
876982
- name: Publish Integration API tests results as check
877-
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:latest
878983
if: always()
879-
with:
880-
report_individual_runs: "true"
881-
check_name: Integration API tests check
882-
github_token: ${{ secrets.GITHUB_TOKEN }}
883-
files: ./TestResults/*.JUnit.xml
984+
env:
985+
CHECK_NAME: Integration API tests check
986+
FILE_PATH: ./TestResults/*.JUnit.xml
987+
run: |
988+
RETRY_COUNT=0
989+
MAX_RETRIES=3
990+
BACKOFF=10
991+
992+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
993+
# Check GitHub Rate Limit
994+
REMAINING=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/rate_limit | jq '.rate.remaining')
995+
if [ "$REMAINING" -lt 100 ]; then
996+
echo "API rate limit is too low: $REMAINING remaining requests. Retrying in $BACKOFF seconds..."
997+
sleep $BACKOFF
998+
BACKOFF=$((BACKOFF * 2))
999+
RETRY_COUNT=$((RETRY_COUNT + 1))
1000+
continue
1001+
fi
1002+
1003+
# Publish test results as check
1004+
docker run --rm -v $PWD:/workspace -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} ghcr.io/enricomi/publish-unit-test-result-action \
1005+
--check_name "$CHECK_NAME" \
1006+
--report_individual_runs "true" \
1007+
--files "$FILE_PATH"
1008+
1009+
# Check if publishing succeeded
1010+
if [ $? -eq 0 ]; then
1011+
echo "Test results published successfully!"
1012+
break
1013+
else
1014+
echo "Failed to publish test results. Retrying in $BACKOFF seconds..."
1015+
sleep $BACKOFF
1016+
BACKOFF=$((BACKOFF * 2))
1017+
RETRY_COUNT=$((RETRY_COUNT + 1))
1018+
fi
1019+
1020+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
1021+
echo "Max retries reached. Failing the job."
1022+
exit 1
1023+
fi
1024+
done
8841025
docker-publish-github-auth-service:
8851026
name: Tag service image in GitHub
8861027
timeout-minutes: 20

0 commit comments

Comments
 (0)