@@ -12,27 +12,33 @@ set -euo pipefail
12
12
source " $( dirname " ${BASH_SOURCE[0]} " ) /../lib.sh"
13
13
cdroot
14
14
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
+
15
25
if isdarwin; then
16
26
dependencies gsed gawk
17
27
sed () { gsed " $@ " ; }
18
28
awk () { gawk " $@ " ; }
19
29
fi
20
30
21
- # From install.sh
22
31
echo_latest_stable_version () {
23
- # https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
32
+ # Extract redirect URL to determine latest stable tag
24
33
version=" $( curl -fsSLI -o /dev/null -w " %{url_effective}" https://github.com/coder/coder/releases/latest) "
25
34
version=" ${version# https:// github.com/ coder/ coder/ releases/ tag/ v} "
26
35
echo " v${version} "
27
36
}
28
37
29
38
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
34
40
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 |
36
42
awk -F' "' ' /"tag_name"/ {print $4}' |
37
43
tr -d v |
38
44
tr . ' ' |
@@ -42,7 +48,6 @@ echo_latest_mainline_version() {
42
48
) "
43
49
}
44
50
45
- # For testing or including experiments from `main`.
46
51
echo_latest_main_version () {
47
52
echo origin/main
48
53
}
@@ -59,11 +64,6 @@ sparse_clone_codersdk() {
59
64
}
60
65
61
66
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,}
67
67
go doc -all -C " ${dir} " ./codersdk ExperimentsAll |
68
68
tr -d $' \n\t ' |
69
69
grep -E -o ' ExperimentsAll=Experiments\{[^}]*\}' |
@@ -72,20 +72,6 @@ parse_all_experiments() {
72
72
}
73
73
74
74
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
- #
89
75
go doc -all -C " ${1} " ./codersdk Experiment |
90
76
sed \
91
77
-e ' s/\t\(Experiment[^ ]*\)\ \ *Experiment = "\([^"]*\)"\(.*\/\/ \(.*\)\)\?/\1|\2|\4/' \
@@ -104,6 +90,11 @@ for channel in mainline stable; do
104
90
log " Fetching experiments from ${channel} "
105
91
106
92
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
+
107
98
dir=" $( sparse_clone_codersdk " ${workdir} " " ${channel} " " ${tag} " ) "
108
99
109
100
declare -A all_experiments=()
@@ -115,14 +106,12 @@ for channel in mainline stable; do
115
106
done
116
107
fi
117
108
118
- # Track preceding/multiline comments.
119
109
maybe_desc=
120
110
121
111
while read -r line; do
122
112
line=${line// $' \n ' / }
123
113
readarray -d ' |' -t parts <<< " $line"
124
114
125
- # Missing var/key, this is a comment or description.
126
115
if [[ -z ${parts[0]} ]]; then
127
116
maybe_desc+=" ${parts[2]// $' \n ' / } "
128
117
continue
@@ -133,24 +122,20 @@ for channel in mainline stable; do
133
122
desc=" ${parts[2]} "
134
123
desc=${desc// $' \n ' / }
135
124
136
- # If desc (trailing comment) is empty, use the preceding/multiline comment.
137
125
if [[ -z " ${desc} " ]]; then
138
126
desc=" ${maybe_desc% } "
139
127
fi
140
128
maybe_desc=
141
129
142
- # Skip experiments not listed in ExperimentsAll.
143
130
if [[ ! -v all_experiments[$var ] ]]; then
144
131
log " Skipping ${var} , not listed in ExperimentsAll"
145
132
continue
146
133
fi
147
134
148
- # Don't overwrite desc, prefer first come, first served (i.e. mainline > stable).
149
135
if [[ ! -v experiments[$key ] ]]; then
150
136
experiments[$key ]=" $desc "
151
137
fi
152
138
153
- # Track the release channels where the experiment is available.
154
139
experiment_tags[$key ]+=" ${channel} , "
155
140
done < <( parse_experiments " ${dir} " )
156
141
done
@@ -170,14 +155,11 @@ table="$(
170
155
done
171
156
) "
172
157
173
- # Use awk to print everything outside the BEING/END block and insert the
174
- # table in between.
175
158
awk \
176
159
-v table=" ${table} " \
177
160
' BEGIN{include=1} /BEGIN: available-experimental-features/{print; print table; include=0} /END: available-experimental-features/{include=1} include' \
178
161
" ${dest} " \
179
162
> " ${dest} " .tmp
180
163
mv " ${dest} " .tmp " ${dest} "
181
164
182
- # Format the file for a pretty table (target single file for speed).
183
165
(cd site && pnpm exec prettier --cache --write ../" ${dest} " )
0 commit comments