Skip to content

Commit

Permalink
chore: prevent revision check from retrying unnecessary (#1315)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

The revision check kept on retrying even though the revision had failed

## Related Issue(s)

- #{issue number}

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved handling of exit codes during container app revision
verification, enhancing clarity and control flow.
- Adjusted output messages for better user understanding based on
revision state.

- **Refactor**
- Streamlined the verification process to improve readability and
maintainability of the script.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
arealmaas authored Oct 17, 2024
1 parent 0ac07b0 commit c3e8e8c
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions .github/tools/revisionVerifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ revision_name="$1"
resource_group="$2"
query_filter="{name:name, runningState:properties.runningState, healthState:properties.healthState}"

# Define exit codes
readonly EXIT_SUCCESS=0
readonly EXIT_NOT_READY=1
readonly EXIT_FAILED=2

verify_revision() {
local json_output

Expand All @@ -33,24 +38,40 @@ verify_revision() {
echo "Running state: $running_state"
echo " "

# Check if running state is Failed
if [[ $running_state == "Failed" ]]; then
echo "Error: Revision $revision_name has failed."
return $EXIT_FAILED
fi

# Check health and running status
if [[ $health_state == "Healthy" && ($running_state == "Running" || $running_state == "RunningAtMaxScale") ]]; then
return 0 # OK!
return $EXIT_SUCCESS
else
return 1 # Not OK!
return $EXIT_NOT_READY
fi
}

attempt=1

# Loop until verified (GitHub action will do a timeout)
# Loop until verified or failed (GitHub action will do a timeout)
while true; do
if verify_revision; then
echo "Revision $revision_name is healthy and running"
break
else
echo "Attempt $attempt: Waiting for revision $revision_name ..."
sleep 10 # Sleep for 10 seconds
attempt=$((attempt+1))
fi
verify_revision
result=$?

case $result in
$EXIT_SUCCESS)
echo "Revision $revision_name is healthy and running"
exit $EXIT_SUCCESS
;;
$EXIT_FAILED)
echo "Revision $revision_name has failed. Exiting."
exit $EXIT_FAILED
;;
$EXIT_NOT_READY)
echo "Attempt $attempt: Waiting for revision $revision_name ..."
sleep 10 # Sleep for 10 seconds
attempt=$((attempt+1))
;;
esac
done

0 comments on commit c3e8e8c

Please sign in to comment.