From 1fb2fe8d8abb92cdf688647afc7e69c643b7ae4c Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Tue, 22 Jul 2025 02:46:35 +0000 Subject: [PATCH 1/5] feat(tag_release): initial commit for tag_release script - needs testing and a few tweaks --- .github/scripts/tag_release.sh | 294 +++++++++++++++++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100755 .github/scripts/tag_release.sh diff --git a/.github/scripts/tag_release.sh b/.github/scripts/tag_release.sh new file mode 100755 index 00000000..bc4a255a --- /dev/null +++ b/.github/scripts/tag_release.sh @@ -0,0 +1,294 @@ +#!/bin/bash + +# Tag Release Script +# Automatically detects modules that need tagging and creates release tags +# Usage: ./tag_release.sh +# Operates on the current checked-out commit + +set -euo pipefail + +usage() { + echo "Usage: $0" + echo "" + echo "This script will:" + echo " 1. Scan all modules in the registry" + echo " 2. Check which modules need new release tags" + echo " 3. Extract version information from README files" + echo " 4. Generate a report for confirmation" + echo " 5. Create and push release tags after confirmation" + echo "" + echo "The script operates on the current checked-out commit." + echo "Make sure you have checked out the commit you want to tag before running." + exit 1 +} + +validate_version() { + local version="$1" + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "❌ Invalid version format: '$version'. Expected X.Y.Z format." >&2 + return 1 + fi + return 0 +} + +extract_version_from_readme() { + local readme_path="$1" + local namespace="$2" + local module_name="$3" + + if [ ! -f "$readme_path" ]; then + echo "❌ README not found: $readme_path" >&2 + return 1 + fi + + local version_line + version_line=$(grep -E "source\s*=\s*\"registry\.coder\.com/${namespace}/${module_name}" "$readme_path" | head -1 || echo "") + + if [ -n "$version_line" ]; then + local version + version=$(echo "$version_line" | sed -n 's/.*version\s*=\s*"\([^"]*\)".*/\1/p') + if [ -n "$version" ]; then + echo "$version" + return 0 + fi + fi + + local fallback_version + fallback_version=$(grep -E 'version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"' "$readme_path" | head -1 | sed 's/.*version\s*=\s*"\([^"]*\)".*/\1/' || echo "") + + if [ -n "$fallback_version" ]; then + echo "$fallback_version" + return 0 + fi + + return 1 +} + +check_module_needs_tagging() { + local namespace="$1" + local module_name="$2" + local readme_version="$3" + + local tag_name="release/${namespace}/${module_name}/v${readme_version}" + + if git rev-parse --verify "$tag_name" >/dev/null 2>&1; then + return 1 + else + return 0 + fi +} + +detect_modules_needing_tags() { + local modules_to_tag=() + + echo "🔍 Scanning all modules for missing release tags..." + echo "" + + + local all_modules + all_modules=$(find registry -type d -path "*/modules/*" -mindepth 3 -maxdepth 3 | sort -u || echo "") + + if [ -z "$all_modules" ]; then + echo "❌ No modules found to check" + return 1 + fi + + local total_checked=0 + local needs_tagging=0 + + while IFS= read -r module_path; do + if [ -z "$module_path" ]; then continue; fi + + local namespace + namespace=$(echo "$module_path" | cut -d'/' -f2) + local module_name + module_name=$(echo "$module_path" | cut -d'/' -f4) + + total_checked=$((total_checked + 1)) + + local readme_path="$module_path/README.md" + local readme_version + + if ! readme_version=$(extract_version_from_readme "$readme_path" "$namespace" "$module_name"); then + echo "⚠️ $namespace/$module_name: No version found in README, skipping" + continue + fi + + if ! validate_version "$readme_version"; then + echo "⚠️ $namespace/$module_name: Invalid version format '$readme_version', skipping" + continue + fi + + if check_module_needs_tagging "$namespace" "$module_name" "$readme_version"; then + echo "📦 $namespace/$module_name: v$readme_version (needs tag)" + modules_to_tag+=("$module_path:$namespace:$module_name:$readme_version") + needs_tagging=$((needs_tagging + 1)) + else + echo "✅ $namespace/$module_name: v$readme_version (already tagged)" + fi + + done <<< "$all_modules" + + echo "" + echo "📊 Summary: $needs_tagging of $total_checked modules need tagging" + echo "" + + if [ $needs_tagging -eq 0 ]; then + echo "🎉 All modules are up to date! No tags needed." + return 0 + fi + + + echo "## Tags to be created:" + for module_info in "${modules_to_tag[@]}"; do + IFS=':' read -r module_path namespace module_name version <<< "$module_info" + echo "- \`release/$namespace/$module_name/v$version\`" + done + echo "" + + + printf '%s\n' "${modules_to_tag[@]}" > /tmp/modules_to_tag.txt + + return 0 +} + +create_and_push_tags() { + if [ ! -f /tmp/modules_to_tag.txt ]; then + echo "❌ No modules to tag found" + return 1 + fi + + local current_commit + current_commit=$(git rev-parse HEAD) + + echo "🏷️ Creating release tags for commit: $current_commit" + echo "" + + local created_tags=0 + local failed_tags=0 + + while IFS= read -r module_info; do + if [ -z "$module_info" ]; then continue; fi + + IFS=':' read -r module_path namespace module_name version <<< "$module_info" + + local tag_name="release/$namespace/$module_name/v$version" + local tag_message="Release $namespace/$module_name v$version" + + echo "Creating tag: $tag_name" + + if git tag -a "$tag_name" -m "$tag_message" "$current_commit"; then + echo "✅ Created: $tag_name" + created_tags=$((created_tags + 1)) + else + echo "❌ Failed to create: $tag_name" + failed_tags=$((failed_tags + 1)) + fi + + done < /tmp/modules_to_tag.txt + + echo "" + echo "📊 Tag creation summary:" + echo " Created: $created_tags" + echo " Failed: $failed_tags" + echo "" + + if [ $created_tags -eq 0 ]; then + echo "❌ No tags were created successfully" + return 1 + fi + + echo "🚀 Pushing tags to origin..." + + local pushed_tags=0 + local failed_pushes=0 + + while IFS= read -r module_info; do + if [ -z "$module_info" ]; then continue; fi + + IFS=':' read -r module_path namespace module_name version <<< "$module_info" + + local tag_name="release/$namespace/$module_name/v$version" + + if git rev-parse --verify "$tag_name" >/dev/null 2>&1; then + echo "Pushing: $tag_name" + if git push origin "$tag_name"; then + echo "✅ Pushed: $tag_name" + pushed_tags=$((pushed_tags + 1)) + else + echo "❌ Failed to push: $tag_name" + failed_pushes=$((failed_pushes + 1)) + fi + fi + + done < /tmp/modules_to_tag.txt + + echo "" + echo "📊 Push summary:" + echo " Pushed: $pushed_tags" + echo " Failed: $failed_pushes" + echo "" + + if [ $pushed_tags -gt 0 ]; then + echo "🎉 Successfully created and pushed $pushed_tags release tags!" + echo "" + echo "📝 Next steps:" + echo " - Tags will be automatically published to registry.coder.com" + echo " - Monitor the registry website for updates" + echo " - Check GitHub releases for any issues" + fi + + + rm -f /tmp/modules_to_tag.txt + + return 0 +} + +main() { + if [ $# -gt 0 ]; then + usage + fi + + echo "🚀 Coder Registry Tag Release Script" + echo "Operating on commit: $(git rev-parse HEAD)" + echo "" + + + if ! git rev-parse --git-dir >/dev/null 2>&1; then + echo "❌ Not in a git repository" + exit 1 + fi + + + if ! detect_modules_needing_tags; then + exit 1 + fi + + + if [ ! -f /tmp/modules_to_tag.txt ] || [ ! -s /tmp/modules_to_tag.txt ]; then + echo "✨ No modules need tagging. All done!" + exit 0 + fi + + + echo "" + echo "❓ Do you want to proceed with creating and pushing these release tags?" + echo " This will create git tags and push them to the remote repository." + echo "" + read -p "Continue? [y/N]: " -r response + + case "$response" in + [yY]|[yY][eE][sS]) + echo "" + create_and_push_tags + ;; + *) + echo "" + echo "🚫 Operation cancelled by user" + rm -f /tmp/modules_to_tag.txt + exit 0 + ;; + esac +} + +main "$@" From da1c844830bcff33696096ecd8c10a8e3d0ab22f Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 23 Jul 2025 00:40:29 +0000 Subject: [PATCH 2/5] refactor: replace temp file with global array for module tagging in release script --- .github/scripts/tag_release.sh | 154 ++++++++++++++------------------- 1 file changed, 65 insertions(+), 89 deletions(-) diff --git a/.github/scripts/tag_release.sh b/.github/scripts/tag_release.sh index bc4a255a..921b3af1 100755 --- a/.github/scripts/tag_release.sh +++ b/.github/scripts/tag_release.sh @@ -7,6 +7,8 @@ set -euo pipefail +MODULES_TO_TAG=() + usage() { echo "Usage: $0" echo "" @@ -35,15 +37,12 @@ extract_version_from_readme() { local readme_path="$1" local namespace="$2" local module_name="$3" - - if [ ! -f "$readme_path" ]; then - echo "❌ README not found: $readme_path" >&2 - return 1 - fi - + + [ ! -f "$readme_path" ] && return 1 + local version_line version_line=$(grep -E "source\s*=\s*\"registry\.coder\.com/${namespace}/${module_name}" "$readme_path" | head -1 || echo "") - + if [ -n "$version_line" ]; then local version version=$(echo "$version_line" | sed -n 's/.*version\s*=\s*"\([^"]*\)".*/\1/p') @@ -52,15 +51,15 @@ extract_version_from_readme() { return 0 fi fi - + local fallback_version fallback_version=$(grep -E 'version\s*=\s*"[0-9]+\.[0-9]+\.[0-9]+"' "$readme_path" | head -1 | sed 's/.*version\s*=\s*"\([^"]*\)".*/\1/' || echo "") - + if [ -n "$fallback_version" ]; then echo "$fallback_version" return 0 fi - + return 1 } @@ -68,10 +67,10 @@ check_module_needs_tagging() { local namespace="$1" local module_name="$2" local readme_version="$3" - + local tag_name="release/${namespace}/${module_name}/v${readme_version}" - - if git rev-parse --verify "$tag_name" >/dev/null 2>&1; then + + if git rev-parse --verify "$tag_name" > /dev/null 2>&1; then return 1 else return 0 @@ -79,104 +78,97 @@ check_module_needs_tagging() { } detect_modules_needing_tags() { - local modules_to_tag=() - + MODULES_TO_TAG=() + echo "🔍 Scanning all modules for missing release tags..." echo "" - local all_modules all_modules=$(find registry -type d -path "*/modules/*" -mindepth 3 -maxdepth 3 | sort -u || echo "") - - if [ -z "$all_modules" ]; then + + [ -z "$all_modules" ] && { echo "❌ No modules found to check" return 1 - fi - + } + local total_checked=0 local needs_tagging=0 - + while IFS= read -r module_path; do if [ -z "$module_path" ]; then continue; fi - + local namespace namespace=$(echo "$module_path" | cut -d'/' -f2) local module_name module_name=$(echo "$module_path" | cut -d'/' -f4) - + total_checked=$((total_checked + 1)) - + local readme_path="$module_path/README.md" local readme_version - + if ! readme_version=$(extract_version_from_readme "$readme_path" "$namespace" "$module_name"); then echo "⚠️ $namespace/$module_name: No version found in README, skipping" continue fi - + if ! validate_version "$readme_version"; then echo "⚠️ $namespace/$module_name: Invalid version format '$readme_version', skipping" continue fi - + if check_module_needs_tagging "$namespace" "$module_name" "$readme_version"; then echo "📦 $namespace/$module_name: v$readme_version (needs tag)" - modules_to_tag+=("$module_path:$namespace:$module_name:$readme_version") + MODULES_TO_TAG+=("$module_path:$namespace:$module_name:$readme_version") needs_tagging=$((needs_tagging + 1)) else echo "✅ $namespace/$module_name: v$readme_version (already tagged)" fi - + done <<< "$all_modules" - + echo "" echo "📊 Summary: $needs_tagging of $total_checked modules need tagging" echo "" - - if [ $needs_tagging -eq 0 ]; then + + [ $needs_tagging -eq 0 ] && { echo "🎉 All modules are up to date! No tags needed." return 0 - fi - + } echo "## Tags to be created:" - for module_info in "${modules_to_tag[@]}"; do + for module_info in "${MODULES_TO_TAG[@]}"; do IFS=':' read -r module_path namespace module_name version <<< "$module_info" echo "- \`release/$namespace/$module_name/v$version\`" done echo "" - - printf '%s\n' "${modules_to_tag[@]}" > /tmp/modules_to_tag.txt - return 0 } create_and_push_tags() { - if [ ! -f /tmp/modules_to_tag.txt ]; then + [ ${#MODULES_TO_TAG[@]} -eq 0 ] && { echo "❌ No modules to tag found" return 1 - fi - + } + local current_commit current_commit=$(git rev-parse HEAD) - + echo "🏷️ Creating release tags for commit: $current_commit" echo "" - + local created_tags=0 local failed_tags=0 - - while IFS= read -r module_info; do - if [ -z "$module_info" ]; then continue; fi - + + for module_info in "${MODULES_TO_TAG[@]}"; do IFS=':' read -r module_path namespace module_name version <<< "$module_info" - + local tag_name="release/$namespace/$module_name/v$version" local tag_message="Release $namespace/$module_name v$version" - + echo "Creating tag: $tag_name" - + if git tag -a "$tag_name" -m "$tag_message" "$current_commit"; then echo "✅ Created: $tag_name" created_tags=$((created_tags + 1)) @@ -184,33 +176,30 @@ create_and_push_tags() { echo "❌ Failed to create: $tag_name" failed_tags=$((failed_tags + 1)) fi - - done < /tmp/modules_to_tag.txt - + done + echo "" echo "📊 Tag creation summary:" echo " Created: $created_tags" echo " Failed: $failed_tags" echo "" - - if [ $created_tags -eq 0 ]; then + + [ $created_tags -eq 0 ] && { echo "❌ No tags were created successfully" return 1 - fi - + } + echo "🚀 Pushing tags to origin..." - + local pushed_tags=0 local failed_pushes=0 - - while IFS= read -r module_info; do - if [ -z "$module_info" ]; then continue; fi - + + for module_info in "${MODULES_TO_TAG[@]}"; do IFS=':' read -r module_path namespace module_name version <<< "$module_info" - + local tag_name="release/$namespace/$module_name/v$version" - - if git rev-parse --verify "$tag_name" >/dev/null 2>&1; then + + if git rev-parse --verify "$tag_name" > /dev/null 2>&1; then echo "Pushing: $tag_name" if git push origin "$tag_name"; then echo "✅ Pushed: $tag_name" @@ -220,15 +209,14 @@ create_and_push_tags() { failed_pushes=$((failed_pushes + 1)) fi fi - - done < /tmp/modules_to_tag.txt - + done + echo "" echo "📊 Push summary:" echo " Pushed: $pushed_tags" echo " Failed: $failed_pushes" echo "" - + if [ $pushed_tags -gt 0 ]; then echo "🎉 Successfully created and pushed $pushed_tags release tags!" echo "" @@ -237,55 +225,43 @@ create_and_push_tags() { echo " - Monitor the registry website for updates" echo " - Check GitHub releases for any issues" fi - - rm -f /tmp/modules_to_tag.txt - return 0 } main() { - if [ $# -gt 0 ]; then - usage - fi - + [ $# -gt 0 ] && usage + echo "🚀 Coder Registry Tag Release Script" echo "Operating on commit: $(git rev-parse HEAD)" echo "" - - if ! git rev-parse --git-dir >/dev/null 2>&1; then + if ! git rev-parse --git-dir > /dev/null 2>&1; then echo "❌ Not in a git repository" exit 1 fi - - if ! detect_modules_needing_tags; then - exit 1 - fi - + detect_modules_needing_tags || exit 1 - if [ ! -f /tmp/modules_to_tag.txt ] || [ ! -s /tmp/modules_to_tag.txt ]; then + [ ${#MODULES_TO_TAG[@]} -eq 0 ] && { echo "✨ No modules need tagging. All done!" exit 0 - fi - + } echo "" echo "❓ Do you want to proceed with creating and pushing these release tags?" echo " This will create git tags and push them to the remote repository." echo "" read -p "Continue? [y/N]: " -r response - + case "$response" in - [yY]|[yY][eE][sS]) + [yY] | [yY][eE][sS]) echo "" create_and_push_tags ;; *) echo "" echo "🚫 Operation cancelled by user" - rm -f /tmp/modules_to_tag.txt exit 0 ;; esac From bd07fa2bb85ed2d5bc9e0b483bbaf5e081905cd3 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 23 Jul 2025 01:17:50 +0000 Subject: [PATCH 3/5] fix(tag_release): correct module path detection in tag_release script --- .github/scripts/tag_release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/tag_release.sh b/.github/scripts/tag_release.sh index 921b3af1..277f65a9 100755 --- a/.github/scripts/tag_release.sh +++ b/.github/scripts/tag_release.sh @@ -84,7 +84,7 @@ detect_modules_needing_tags() { echo "" local all_modules - all_modules=$(find registry -type d -path "*/modules/*" -mindepth 3 -maxdepth 3 | sort -u || echo "") + all_modules=$(find registry -mindepth 3 -maxdepth 3 -type d -path "*/modules/*" | sort -u || echo "") [ -z "$all_modules" ] && { echo "❌ No modules found to check" From bfe65cd9beaf3f7da46863f31b41359e61944c8a Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 23 Jul 2025 01:50:04 +0000 Subject: [PATCH 4/5] refactor(tag_release): consolidate tag pushing since there are no contraints that would effect our registry size for pushing in a single line. this also changes the tagging process to use the atomic option to make the tag script an all or nothing success or fail for tagging. --- .github/scripts/tag_release.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/scripts/tag_release.sh b/.github/scripts/tag_release.sh index 277f65a9..b5945b0a 100755 --- a/.github/scripts/tag_release.sh +++ b/.github/scripts/tag_release.sh @@ -191,26 +191,31 @@ create_and_push_tags() { echo "🚀 Pushing tags to origin..." - local pushed_tags=0 - local failed_pushes=0 - + local tags_to_push=() for module_info in "${MODULES_TO_TAG[@]}"; do IFS=':' read -r module_path namespace module_name version <<< "$module_info" - local tag_name="release/$namespace/$module_name/v$version" - + if git rev-parse --verify "$tag_name" > /dev/null 2>&1; then - echo "Pushing: $tag_name" - if git push origin "$tag_name"; then - echo "✅ Pushed: $tag_name" - pushed_tags=$((pushed_tags + 1)) - else - echo "❌ Failed to push: $tag_name" - failed_pushes=$((failed_pushes + 1)) - fi + tags_to_push+=("$tag_name") fi done + local pushed_tags=0 + local failed_pushes=0 + + if [ ${#tags_to_push[@]} -eq 0 ]; then + echo "❌ No valid tags found to push" + else + if git push --atomic origin "${tags_to_push[@]}"; then + echo "✅ Successfully pushed all ${#tags_to_push[@]} tags" + pushed_tags=${#tags_to_push[@]} + else + echo "❌ Failed to push tags" + failed_pushes=${#tags_to_push[@]} + fi + fi + echo "" echo "📊 Push summary:" echo " Pushed: $pushed_tags" From 89b592de7cb36ef69982c029f113cd3ae2fb081e Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 23 Jul 2025 01:51:40 +0000 Subject: [PATCH 5/5] chore: bun fmt --- .github/scripts/tag_release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/tag_release.sh b/.github/scripts/tag_release.sh index b5945b0a..258c2ea6 100755 --- a/.github/scripts/tag_release.sh +++ b/.github/scripts/tag_release.sh @@ -195,7 +195,7 @@ create_and_push_tags() { for module_info in "${MODULES_TO_TAG[@]}"; do IFS=':' read -r module_path namespace module_name version <<< "$module_info" local tag_name="release/$namespace/$module_name/v$version" - + if git rev-parse --verify "$tag_name" > /dev/null 2>&1; then tags_to_push+=("$tag_name") fi