-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds zombie removal tool #13718
Merged
Merged
Adds zombie removal tool #13718
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0ddae07
Adds zombie removal tool
supertopher e3c8498
Corrects endpoint adds comments
supertopher 9a54ae4
Merge branch 'master' into toph_kills_a_zombie_in_gh
supertopher 375e66b
Adds API links
supertopher cf3b030
Changes search logic, fixes escape character
supertopher 536e7dc
Corrects help text
supertopher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bash | ||
supertopher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# ------------- Import some defaults for the shell | ||
|
||
# Source shell defaults | ||
# $0 is the currently running program (this file) | ||
this_file_directory=$(dirname $0) | ||
relative_path_to_defaults=$this_file_directory/../shell_defaults | ||
|
||
# if a file exists there, source it. otherwise complain | ||
if test -f $relative_path_to_defaults; then | ||
# source and '.' are the same program | ||
source $relative_path_to_defaults | ||
else | ||
echo -e "\033[31m\nFAILED TO SOURCE TEST RUNNING OPTIONS.\033[39m" | ||
echo -e "\033[31mTried $relative_path_to_defaults\033[39m" | ||
exit 1 | ||
fi | ||
|
||
echo "To run locally use GITHUB_PAT=\$YOUR_PAT_HERE before running" | ||
token=$GITHUB_PAT | ||
org=airbytehq | ||
# FUN POSIX fact, every string is an array! | ||
repo_list="airbyte airbyte-cloud" | ||
supertopher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
for repo in $repo_list; do | ||
# Start the while loop to check for all runners | ||
runner_for_page_count=1 | ||
page_count=0 | ||
all_runner_ids="" | ||
# keep paging through until we find them all | ||
while test $runner_for_page_count -gt 0; do | ||
page_count=$(($page_count+1)) | ||
set +o xtrace | ||
# API for endpoint: | ||
# https://docs.github.com/en/rest/actions/self-hosted-runners#list-self-hosted-runners-for-a-repository | ||
runner_response=$(curl \ | ||
supertopher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--silent \ | ||
--header "Accept: application/vnd.github.v3+json" \ | ||
--header "Authorization: token $token" \ | ||
--request GET https://api.github.com/repos/$org/$repo/actions/runners?page=$page_count&per_page=100) | ||
runner_response_wc=$(echo $runner_response | wc -w) | ||
# For auth errors | ||
if test $runner_response_wc -lt 100; then | ||
echo -e "$blue_text""\$runner_response is \n\n$runner_response\n\n""$default_text" | ||
fi | ||
|
||
supertopher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
runner_ids_for_page=$(echo $runner_response | \ | ||
jq '.runners[] | select(.status!="online") | .id') | ||
|
||
runner_for_page_count=$(echo $runner_ids_for_page | wc -w) | ||
echo -e "$blue_text""jq returned $runner_for_page_count runners for page $page_count""$default_text" | ||
all_runner_ids=$runner_ids_for_page\n$all_runner_ids | ||
all_runner_ids_count=$(echo $all_runner_ids | wc -w) | ||
echo -e "$blue_text""Total count is now $all_runner_ids_count""$default_text" | ||
done | ||
|
||
echo -e "$blue_text""Total ids returned: $all_runner_ids_count""$default_text" | ||
# DELETE THEM ALL! | ||
cursor=0 | ||
for this_runner in $all_runner_ids; do | ||
cursor=$(($cursor+1)) | ||
echo -e "$blue_text""Removing $cursor / $all_runner_ids_count""$default_text" | ||
# API for endpoint: | ||
# https://docs.github.com/en/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-a-repository | ||
curl \ | ||
--silent \ | ||
--request DELETE \ | ||
--header "Accept: application/vnd.github.v3+json" \ | ||
--header "Authorization: token $token" \ | ||
https://api.github.com/repos/$org/$repo/actions/runners/$this_runner && \ | ||
supertopher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo -e "$blue_text""OK ID $this_runner""$default_text" || \ | ||
echo -e "$red_text""FAIL! ID $this_runner""$default_text" | ||
done | ||
|
||
done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see logic to filter out runners older than a day. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that may have been an aspirational day when I started writing the script, I'll update the comment.
We are deleting anything not "online" but I'm changing that in an upcoming PR to
==
offline which seems to be the end state of these runners. Happy to add day logic thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need. wanted to make sure I understood the logic. I think filtering for offline makes sense. I believe the action status is online -> offline. would double check that runners don't start in offline.