-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to bury drafts for failed releases
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# servo-nightly-builds | ||
Repository to host Servo nightly builds using Github Releases. | ||
|
||
## How to bury drafts for failed releases | ||
```sh | ||
$ tools/bury-old-drafts.sh servo/servo-nightly-builds | ||
``` |
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,52 @@ | ||
#!/usr/bin/env zsh | ||
# usage: tools/bury-old-drafts.sh | ||
# requires: zsh, gh, jq, rg | ||
set -euo pipefail | ||
missing() { >&2 echo "fatal: $1 not found"; exit 1; } | ||
> /dev/null command -v gh || missing gh | ||
> /dev/null command -v jq || missing jq | ||
> /dev/null command -v rg || missing rg | ||
|
||
set -- | ||
org_repo_slug=servo/servo-nightly-builds | ||
now=$(date +\%s) | ||
result=$(mktemp) | ||
page=1 | ||
while :; do | ||
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
/repos/"$org_repo_slug"'/releases?per_page=100&page='$page > $result | ||
length=$(< $result jq length) | ||
if [ $length -eq 0 ]; then | ||
break | ||
fi | ||
for draft in $(< $result jq '.[] | select(.draft) | .id'); do | ||
created_at=$(< $result jq -r '.[] | select(.id == '"$draft"') | .created_at') | ||
created_at=$(date +\%s --date="$created_at") | ||
age=$((now - created_at)) | ||
# Ignore young drafts, because their release builds may still be running | ||
if [ $age -lt 86400 ]; then | ||
>&2 echo "Warning: ignoring release $draft, which is only $age seconds old" | ||
else | ||
set -- "$@" "$draft" | ||
fi | ||
done | ||
>&2 echo "Page $page has $length releases; found $# drafts so far" | ||
page=$((page+1)) | ||
done | ||
for draft; do | ||
# Mark as prerelease and unmark as draft | ||
set -- PATCH "/repos/$org_repo_slug/releases/$draft" -F prerelease=true -F draft=false | ||
echo "$@" | ||
if ! gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
--method "$@" > $result; then | ||
< $result jq | ||
>&2 printf 'Delete release? [y/N] ' | ||
read -r yn | ||
if [ "$yn" = y ]; then | ||
set -- DELETE "/repos/$org_repo_slug/releases/$draft" | ||
echo "$@" | ||
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
--method "$@" | ||
fi | ||
fi | ||
done |