Skip to content

Commit

Permalink
Fail only on consecutive failures
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Ruiz <[email protected]>
  • Loading branch information
migruiz4 committed Jan 15, 2025
1 parent bd73e88 commit e094a60
Showing 1 changed file with 66 additions and 22 deletions.
88 changes: 66 additions & 22 deletions .github/workflows/index-monitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: '[Index] Monitor remote index.yaml'

on:
schedule:
# In the 15th and 45th minutes
# To not overlap with the index-update workflow
- cron: '15,45 * * * *'
# Every 10 minutes
- cron: '*/10 * * * *'

# Remove all permissions by default
permissions: {}
Expand All @@ -24,17 +23,35 @@ jobs:
- name: Check index integrity
id: integrity-check
run: |
# Check the index.yaml integrity
REMOTE_MD5=($(curl -Ls http://charts.bitnami.com/bitnami/index.yaml | md5sum))
REPOSITORY_MD5=($(md5sum bitnami/index.yaml))
# Compare the index.yaml checksums remote and locally
if [[ "${REPOSITORY_MD5[0]}" == "${REMOTE_MD5[0]}" ]]; then
echo "result=passed" >> $GITHUB_OUTPUT
else
echo "result=failed" >> $GITHUB_OUTPUT
echo "Integrity check failed. Remote checksum '${REMOTE_MD5[0]}' does not match expected '${REPOSITORY_MD5[0]}'";
exit 1
fi
status="fail"
consecutive_failures=0
# We want to check for consistent failures
# To do so, we will look for 3 consecutive failures with a 30 seconds wait
# A single success is enough to pass
while [[ "${status}" != "ok" && $consecutive_failures -lt 3 ]]; do
# Check the index.yaml integrity
REMOTE_MD5=($(curl -Ls http://charts.bitnami.com/bitnami/index.yaml | md5sum))
REPOSITORY_MD5=($(md5sum bitnami/index.yaml))
# Compare the index.yaml checksums remote and locally
if [[ "${REPOSITORY_MD5[0]}" == "${REMOTE_MD5[0]}" ]]; then
status='ok'
else
consecutive_failures++
echo "Integrity check failed. Remote checksum '${REMOTE_MD5[0]}' does not match expected '${REPOSITORY_MD5[0]}'";
fi
# Wait 30 seconds
sleep 30
done
echo "result=${status}" >> $GITHUB_OUTPUT
- name: Show messages
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
if ("${{ steps.integrity-check.outputs.result }}" != "ok" ) {
core.setFailed("Integrity check failed");
} else {
core.info("Integrity check succeeded")
}
validation-check:
name: Validate the helm repository can be added and updated
runs-on: ubuntu-latest
Expand All @@ -51,17 +68,44 @@ jobs:
id: validation-check
run: |
repo="http://charts.bitnami.com/bitnami"
# Validates the helm repository can be added and updated
if helm repo add bitnami "${repo}" && helm repo update bitnami; then
echo "result=ok" >> $GITHUB_OUTPUT
else
echo "result=fail" >> $GITHUB_OUTPUT
echo "Failed to pull charts from helm repository '${repo}'"
exit 1
fi
status="fail"
consecutive_failures=0
# We want to check for consistent failures
# To do so, we will look for 3 consecutive failures with a 30 seconds wait
# A single success is enough to pass
while [[ "${status}" != "ok" && $consecutive_failures -lt 3 ]]; do
# Validates the helm repository can be added and updated
if helm repo add bitnami "${repo}" && helm repo update bitnami; then
status="ok"
else
consecutive_failures++
echo "Failed to pull charts from helm repository '${repo}'"
fi
# Wait 30 seconds
sleep 30
done
echo "result=${status}" >> $GITHUB_OUTPUT
- name: Show messages
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
if ("${{ steps.validation-check.outputs.result }}" != "ok" ) {
core.setFailed("Validation check failed");
} else {
core.info("Validation check succeeded")
}
upload:
name: Re-upload index.yaml
needs: [validation-check, integrity-check]
if: ${{ always() && (needs.validation-check.outputs.result != 'ok' || needs.integrity-check.outputs.result != 'ok') }}
uses: bitnami/charts/.github/workflows/sync-chart-cloudflare-index.yml@index
secrets: inherit
notify:
name: Send notification
needs: [validation-check, integrity-check]
if: ${{ always() && (needs.validation-check.outputs.result != 'ok' || needs.integrity-check.outputs.result != 'ok') }}
uses: bitnami/charts/.github/workflows/gchat-notification.yml@main
with:
workflow: ${{ github.workflow }}
job-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
secrets: inherit

0 comments on commit e094a60

Please sign in to comment.