Skip to content

Commit

Permalink
More intelligent waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
angerman committed Sep 10, 2023
1 parent d78d9a9 commit c24ac1f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,39 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
wait-for-hydra-eval:
env:
HYDRA_JOB: ci/eval
name: "Wait for hydra status"
runs-on: ubuntu-latest
steps:
- name: Get specific check run status
run: |
# start with a random sleep to prevent hitting the api too hard.
while [[ true ]]; do
# For GitHub Apps
# conclusion=$(gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/status --jq '.check_runs[] | select(.name == "ci/hydra-build:$DEV_SHELL") | .conclusion')
# For GitHub Statuses; we need --paginate because there are so many statuses
echo "Querying: gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/status --paginate --jq '.statuses[] | select(.context == \"$HYDRA_JOB\") | .state'"
conclusion=$(gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/status --paginate --jq '.statuses[] | select(.context == "$HYDRA_JOB") | .state')
case "$conclusion" in
success)
echo "$HYDRA_JOB succeeded"
exit 0;;
failure)
echo "$HYDRA_JOB failed"
exit 1;;
*)
echo "conclusion is: '$conclusion'"
gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/status --paginate --jq '.statuses[] | .state+"\t"+.context'|sort
WAIT=$((30 + $RANDOM % 30))
echo "$HYDRA_JOB pending. Waiting ${WAIT}s..."
sleep $WAIT;;
esac
done
upload:
needs: wait-for-hydra-eval
name: Container Upload
strategy:
fail-fast: false
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wait-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Get specific check run status
run: |
# start with a random sleep to prevent hitting the api too hard.
sleep $(($RANDOM % 180))
sleep $(($RANDOM % 360))
while [[ true ]]; do
# For GitHub Apps
# conclusion=$(gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/status --jq '.check_runs[] | select(.name == "ci/hydra-build:$DEV_SHELL") | .conclusion')
Expand All @@ -55,7 +55,7 @@ jobs:
exit 1;;
*)
echo "conclusion is: '$conclusion'"
gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/status --paginate --jq '.'
gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/status --paginate --jq '.statuses[] | .state+"\t"+.context'|sort
WAIT=$((180 + $RANDOM % 180))
echo "ci/hydra-build:$DEV_SHELL pending. Waiting ${WAIT}s..."
sleep $WAIT;;
Expand Down

0 comments on commit c24ac1f

Please sign in to comment.