Skip to content

Commit a8a640f

Browse files
committed
chore: fall back to gh auth login for update_experiments.sh script
1 parent 1f54c36 commit a8a640f

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

scripts/release/docs_update_experiments.sh

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,33 @@ set -euo pipefail
1212
source "$(dirname "${BASH_SOURCE[0]}")/../lib.sh"
1313
cdroot
1414

15+
# Ensure GITHUB_TOKEN is available
16+
if [[ -z "${GITHUB_TOKEN:-}" ]]; then
17+
if GITHUB_TOKEN="$(gh auth token 2>/dev/null)"; then
18+
export GITHUB_TOKEN
19+
else
20+
echo "Error: GitHub token not found. Please run 'gh auth login' to authenticate." >&2
21+
exit 1
22+
fi
23+
fi
24+
1525
if isdarwin; then
1626
dependencies gsed gawk
1727
sed() { gsed "$@"; }
1828
awk() { gawk "$@"; }
1929
fi
2030

21-
# From install.sh
2231
echo_latest_stable_version() {
23-
# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
32+
# Extract redirect URL to determine latest stable tag
2433
version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/coder/releases/latest)"
2534
version="${version#https://github.com/coder/coder/releases/tag/v}"
2635
echo "v${version}"
2736
}
2837

2938
echo_latest_mainline_version() {
30-
# Fetch the releases from the GitHub API, sort by version number,
31-
# and take the first result. Note that we're sorting by space-
32-
# separated numbers and without utilizing the sort -V flag for the
33-
# best compatibility.
39+
# Use GitHub API to get latest release version, authenticated
3440
echo "v$(
35-
curl -fsSL https://api.github.com/repos/coder/coder/releases |
41+
curl -fsSL -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/coder/coder/releases |
3642
awk -F'"' '/"tag_name"/ {print $4}' |
3743
tr -d v |
3844
tr . ' ' |
@@ -42,7 +48,6 @@ echo_latest_mainline_version() {
4248
)"
4349
}
4450

45-
# For testing or including experiments from `main`.
4651
echo_latest_main_version() {
4752
echo origin/main
4853
}
@@ -59,11 +64,6 @@ sparse_clone_codersdk() {
5964
}
6065

6166
parse_all_experiments() {
62-
# Go doc doesn't include inline array comments, so this parsing should be
63-
# good enough. We remove all whitespaces so that we can extract a plain
64-
# string that looks like {}, {ExpA}, or {ExpA,ExpB,}.
65-
#
66-
# Example: ExperimentsAll=Experiments{ExperimentNotifications,ExperimentAutoFillParameters,}
6767
go doc -all -C "${dir}" ./codersdk ExperimentsAll |
6868
tr -d $'\n\t ' |
6969
grep -E -o 'ExperimentsAll=Experiments\{[^}]*\}' |
@@ -72,20 +72,6 @@ parse_all_experiments() {
7272
}
7373

7474
parse_experiments() {
75-
# Extracts the experiment name and description from the Go doc output.
76-
# The output is in the format:
77-
#
78-
# ||Add new experiments here!
79-
# ExperimentExample|example|This isn't used for anything.
80-
# ExperimentAutoFillParameters|auto-fill-parameters|This should not be taken out of experiments until we have redesigned the feature.
81-
# ExperimentMultiOrganization|multi-organization|Requires organization context for interactions, default org is assumed.
82-
# ExperimentCustomRoles|custom-roles|Allows creating runtime custom roles.
83-
# ExperimentNotifications|notifications|Sends notifications via SMTP and webhooks following certain events.
84-
# ExperimentWorkspaceUsage|workspace-usage|Enables the new workspace usage tracking.
85-
# ||ExperimentTest is an experiment with
86-
# ||a preceding multi line comment!?
87-
# ExperimentTest|test|
88-
#
8975
go doc -all -C "${1}" ./codersdk Experiment |
9076
sed \
9177
-e 's/\t\(Experiment[^ ]*\)\ \ *Experiment = "\([^"]*\)"\(.*\/\/ \(.*\)\)\?/\1|\2|\4/' \
@@ -104,6 +90,11 @@ for channel in mainline stable; do
10490
log "Fetching experiments from ${channel}"
10591

10692
tag=$(echo_latest_"${channel}"_version)
93+
if [[ -z "${tag}" || "${tag}" == "v" ]]; then
94+
echo "Error: Failed to retrieve valid ${channel} version tag. Check your GitHub token or rate limit." >&2
95+
exit 1
96+
fi
97+
10798
dir="$(sparse_clone_codersdk "${workdir}" "${channel}" "${tag}")"
10899

109100
declare -A all_experiments=()
@@ -115,14 +106,12 @@ for channel in mainline stable; do
115106
done
116107
fi
117108

118-
# Track preceding/multiline comments.
119109
maybe_desc=
120110

121111
while read -r line; do
122112
line=${line//$'\n'/}
123113
readarray -d '|' -t parts <<<"$line"
124114

125-
# Missing var/key, this is a comment or description.
126115
if [[ -z ${parts[0]} ]]; then
127116
maybe_desc+="${parts[2]//$'\n'/ }"
128117
continue
@@ -133,24 +122,20 @@ for channel in mainline stable; do
133122
desc="${parts[2]}"
134123
desc=${desc//$'\n'/}
135124

136-
# If desc (trailing comment) is empty, use the preceding/multiline comment.
137125
if [[ -z "${desc}" ]]; then
138126
desc="${maybe_desc% }"
139127
fi
140128
maybe_desc=
141129

142-
# Skip experiments not listed in ExperimentsAll.
143130
if [[ ! -v all_experiments[$var] ]]; then
144131
log "Skipping ${var}, not listed in ExperimentsAll"
145132
continue
146133
fi
147134

148-
# Don't overwrite desc, prefer first come, first served (i.e. mainline > stable).
149135
if [[ ! -v experiments[$key] ]]; then
150136
experiments[$key]="$desc"
151137
fi
152138

153-
# Track the release channels where the experiment is available.
154139
experiment_tags[$key]+="${channel}, "
155140
done < <(parse_experiments "${dir}")
156141
done
@@ -170,14 +155,11 @@ table="$(
170155
done
171156
)"
172157

173-
# Use awk to print everything outside the BEING/END block and insert the
174-
# table in between.
175158
awk \
176159
-v table="${table}" \
177160
'BEGIN{include=1} /BEGIN: available-experimental-features/{print; print table; include=0} /END: available-experimental-features/{include=1} include' \
178161
"${dest}" \
179162
>"${dest}".tmp
180163
mv "${dest}".tmp "${dest}"
181164

182-
# Format the file for a pretty table (target single file for speed).
183165
(cd site && pnpm exec prettier --cache --write ../"${dest}")

0 commit comments

Comments
 (0)