77
88set -euo pipefail
99
10+ MODULES_TO_TAG=()
11+
1012usage () {
1113 echo " Usage: $0 "
1214 echo " "
@@ -35,15 +37,12 @@ extract_version_from_readme() {
3537 local readme_path=" $1 "
3638 local namespace=" $2 "
3739 local module_name=" $3 "
38-
39- if [ ! -f " $readme_path " ]; then
40- echo " ❌ README not found: $readme_path " >&2
41- return 1
42- fi
43-
40+
41+ [ ! -f " $readme_path " ] && return 1
42+
4443 local version_line
4544 version_line=$( grep -E " source\s*=\s*\" registry\.coder\.com/${namespace} /${module_name} " " $readme_path " | head -1 || echo " " )
46-
45+
4746 if [ -n " $version_line " ]; then
4847 local version
4948 version=$( echo " $version_line " | sed -n ' s/.*version\s*=\s*"\([^"]*\)".*/\1/p' )
@@ -52,165 +51,155 @@ extract_version_from_readme() {
5251 return 0
5352 fi
5453 fi
55-
54+
5655 local fallback_version
5756 fallback_version=$( grep -E ' version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"' " $readme_path " | head -1 | sed ' s/.*version\s*=\s*"\([^"]*\)".*/\1/' || echo " " )
58-
57+
5958 if [ -n " $fallback_version " ]; then
6059 echo " $fallback_version "
6160 return 0
6261 fi
63-
62+
6463 return 1
6564}
6665
6766check_module_needs_tagging () {
6867 local namespace=" $1 "
6968 local module_name=" $2 "
7069 local readme_version=" $3 "
71-
70+
7271 local tag_name=" release/${namespace} /${module_name} /v${readme_version} "
73-
74- if git rev-parse --verify " $tag_name " > /dev/null 2>&1 ; then
72+
73+ if git rev-parse --verify " $tag_name " > /dev/null 2>&1 ; then
7574 return 1
7675 else
7776 return 0
7877 fi
7978}
8079
8180detect_modules_needing_tags () {
82- local modules_to_tag =()
83-
81+ MODULES_TO_TAG =()
82+
8483 echo " 🔍 Scanning all modules for missing release tags..."
8584 echo " "
86-
8785
8886 local all_modules
8987 all_modules=$( find registry -type d -path " */modules/*" -mindepth 3 -maxdepth 3 | sort -u || echo " " )
90-
91- if [ -z " $all_modules " ]; then
88+
89+ [ -z " $all_modules " ] && {
9290 echo " ❌ No modules found to check"
9391 return 1
94- fi
95-
92+ }
93+
9694 local total_checked=0
9795 local needs_tagging=0
98-
96+
9997 while IFS= read -r module_path; do
10098 if [ -z " $module_path " ]; then continue ; fi
101-
99+
102100 local namespace
103101 namespace=$( echo " $module_path " | cut -d' /' -f2)
104102 local module_name
105103 module_name=$( echo " $module_path " | cut -d' /' -f4)
106-
104+
107105 total_checked=$(( total_checked + 1 ))
108-
106+
109107 local readme_path=" $module_path /README.md"
110108 local readme_version
111-
109+
112110 if ! readme_version=$( extract_version_from_readme " $readme_path " " $namespace " " $module_name " ) ; then
113111 echo " ⚠️ $namespace /$module_name : No version found in README, skipping"
114112 continue
115113 fi
116-
114+
117115 if ! validate_version " $readme_version " ; then
118116 echo " ⚠️ $namespace /$module_name : Invalid version format '$readme_version ', skipping"
119117 continue
120118 fi
121-
119+
122120 if check_module_needs_tagging " $namespace " " $module_name " " $readme_version " ; then
123121 echo " 📦 $namespace /$module_name : v$readme_version (needs tag)"
124- modules_to_tag +=(" $module_path :$namespace :$module_name :$readme_version " )
122+ MODULES_TO_TAG +=(" $module_path :$namespace :$module_name :$readme_version " )
125123 needs_tagging=$(( needs_tagging + 1 ))
126124 else
127125 echo " ✅ $namespace /$module_name : v$readme_version (already tagged)"
128126 fi
129-
127+
130128 done <<< " $all_modules"
131-
129+
132130 echo " "
133131 echo " 📊 Summary: $needs_tagging of $total_checked modules need tagging"
134132 echo " "
135-
136- if [ $needs_tagging -eq 0 ]; then
133+
134+ [ $needs_tagging -eq 0 ] && {
137135 echo " 🎉 All modules are up to date! No tags needed."
138136 return 0
139- fi
140-
137+ }
141138
142139 echo " ## Tags to be created:"
143- for module_info in " ${modules_to_tag [@]} " ; do
140+ for module_info in " ${MODULES_TO_TAG [@]} " ; do
144141 IFS=' :' read -r module_path namespace module_name version <<< " $module_info"
145142 echo " - \` release/$namespace /$module_name /v$version \` "
146143 done
147144 echo " "
148-
149145
150- printf ' %s\n' " ${modules_to_tag[@]} " > /tmp/modules_to_tag.txt
151-
152146 return 0
153147}
154148
155149create_and_push_tags () {
156- if [ ! -f /tmp/modules_to_tag.txt ] ; then
150+ [ ${ # MODULES_TO_TAG[@]} -eq 0 ] && {
157151 echo " ❌ No modules to tag found"
158152 return 1
159- fi
160-
153+ }
154+
161155 local current_commit
162156 current_commit=$( git rev-parse HEAD)
163-
157+
164158 echo " 🏷️ Creating release tags for commit: $current_commit "
165159 echo " "
166-
160+
167161 local created_tags=0
168162 local failed_tags=0
169-
170- while IFS= read -r module_info; do
171- if [ -z " $module_info " ]; then continue ; fi
172-
163+
164+ for module_info in " ${MODULES_TO_TAG[@]} " ; do
173165 IFS=' :' read -r module_path namespace module_name version <<< " $module_info"
174-
166+
175167 local tag_name=" release/$namespace /$module_name /v$version "
176168 local tag_message=" Release $namespace /$module_name v$version "
177-
169+
178170 echo " Creating tag: $tag_name "
179-
171+
180172 if git tag -a " $tag_name " -m " $tag_message " " $current_commit " ; then
181173 echo " ✅ Created: $tag_name "
182174 created_tags=$(( created_tags + 1 ))
183175 else
184176 echo " ❌ Failed to create: $tag_name "
185177 failed_tags=$(( failed_tags + 1 ))
186178 fi
187-
188- done < /tmp/modules_to_tag.txt
189-
179+ done
180+
190181 echo " "
191182 echo " 📊 Tag creation summary:"
192183 echo " Created: $created_tags "
193184 echo " Failed: $failed_tags "
194185 echo " "
195-
196- if [ $created_tags -eq 0 ]; then
186+
187+ [ $created_tags -eq 0 ] && {
197188 echo " ❌ No tags were created successfully"
198189 return 1
199- fi
200-
190+ }
191+
201192 echo " 🚀 Pushing tags to origin..."
202-
193+
203194 local pushed_tags=0
204195 local failed_pushes=0
205-
206- while IFS= read -r module_info; do
207- if [ -z " $module_info " ]; then continue ; fi
208-
196+
197+ for module_info in " ${MODULES_TO_TAG[@]} " ; do
209198 IFS=' :' read -r module_path namespace module_name version <<< " $module_info"
210-
199+
211200 local tag_name=" release/$namespace /$module_name /v$version "
212-
213- if git rev-parse --verify " $tag_name " > /dev/null 2>&1 ; then
201+
202+ if git rev-parse --verify " $tag_name " > /dev/null 2>&1 ; then
214203 echo " Pushing: $tag_name "
215204 if git push origin " $tag_name " ; then
216205 echo " ✅ Pushed: $tag_name "
@@ -220,15 +209,14 @@ create_and_push_tags() {
220209 failed_pushes=$(( failed_pushes + 1 ))
221210 fi
222211 fi
223-
224- done < /tmp/modules_to_tag.txt
225-
212+ done
213+
226214 echo " "
227215 echo " 📊 Push summary:"
228216 echo " Pushed: $pushed_tags "
229217 echo " Failed: $failed_pushes "
230218 echo " "
231-
219+
232220 if [ $pushed_tags -gt 0 ]; then
233221 echo " 🎉 Successfully created and pushed $pushed_tags release tags!"
234222 echo " "
@@ -237,55 +225,43 @@ create_and_push_tags() {
237225 echo " - Monitor the registry website for updates"
238226 echo " - Check GitHub releases for any issues"
239227 fi
240-
241228
242- rm -f /tmp/modules_to_tag.txt
243-
244229 return 0
245230}
246231
247232main () {
248- if [ $# -gt 0 ]; then
249- usage
250- fi
251-
233+ [ $# -gt 0 ] && usage
234+
252235 echo " 🚀 Coder Registry Tag Release Script"
253236 echo " Operating on commit: $( git rev-parse HEAD) "
254237 echo " "
255-
256238
257- if ! git rev-parse --git-dir > /dev/null 2>&1 ; then
239+ if ! git rev-parse --git-dir > /dev/null 2>&1 ; then
258240 echo " ❌ Not in a git repository"
259241 exit 1
260242 fi
261-
262243
263- if ! detect_modules_needing_tags; then
264- exit 1
265- fi
266-
244+ detect_modules_needing_tags || exit 1
267245
268- if [ ! -f /tmp/modules_to_tag.txt ] || [ ! -s /tmp/modules_to_tag.txt ] ; then
246+ [ ${ # MODULES_TO_TAG[@]} -eq 0 ] && {
269247 echo " ✨ No modules need tagging. All done!"
270248 exit 0
271- fi
272-
249+ }
273250
274251 echo " "
275252 echo " ❓ Do you want to proceed with creating and pushing these release tags?"
276253 echo " This will create git tags and push them to the remote repository."
277254 echo " "
278255 read -p " Continue? [y/N]: " -r response
279-
256+
280257 case " $response " in
281- [yY]| [yY][eE][sS])
258+ [yY] | [yY][eE][sS])
282259 echo " "
283260 create_and_push_tags
284261 ;;
285262 * )
286263 echo " "
287264 echo " 🚫 Operation cancelled by user"
288- rm -f /tmp/modules_to_tag.txt
289265 exit 0
290266 ;;
291267 esac
0 commit comments