8000 chore: add support for separate module versioning to CI by matifali · Pull Request #426 · coder/modules · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

chore: add support for separate module versioning to CI #426

Merged
merged 35 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7f130f2
Add support for separate module versioning
matifali Apr 10, 2025
b0069e2
Refactor: Combine version scripts into one versatile tool
matifali Apr 10, 2025
0611ef2
Update CI workflow to use new modules-version.sh tool
matifali Apr 10, 2025
2269e58
Improve CI version check for different workflows
matifali Apr 10, 2025
c6cffc8
Simplify CI version checking
matifali Apr 10, 2025
9bc5419
Remove check-version.sh as it's been replaced by modules-version.sh
matifali Apr 10, 2025
9b89ef4
Improve CI workflow for version checks
matifali Apr 10, 2025
038ef33
Refactor CI workflow for version checks
matifali Apr 10, 2025
0b7a602
Update CONTRIBUTING.md to clarify release process steps
matifali Apr 10, 2025
7d481e8
`fmt`
matifali Apr 10, 2025
d5ecb98
refactor: simplify modules-version script with dry-run and bump-only …
matifali Apr 14, 2025
7c95af8
chore: implement tag-first workflow with automated PRs
matifali Apr 14, 2025
324a383
feat: implement GitHub Action for automatic README updates when tags …
matifali Apr 14, 2025
96657d7
feat: add auto-approve and auto-merge for PR workflow
matifali Apr 14, 2025
1a1dd69
refactor: reuse modules-version.sh in GitHub Action
matifali Apr 14, 2025
4dbe948
feat: add --version parameter for setting exact versions
matifali Apr 14, 2025
bd1703b
refactor: remove environment variable support
matifali Apr 14, 2025
6f2fe83
docs: update release process documentation
matifali Apr 14, 2025
2998721
feat: split scripts into release.sh and update-version.sh
matifali Apr 14, 2025
d63b332
refactor: simplify scripts and workflows
matifali Apr 14, 2025
a6984fb
refactor: further simplify scripts to bare essentials
matifali Apr 14, 2025
0c4f954
feat: use GitHub CLI for PR management
matifali Apr 14, 2025
fb3ae6f
refactor: use cdrci as PR author and auto-approve action
matifali Apr 14, 2025
6d925ca
refactor: remove unnecessary comments and streamline code
matifali Apr 14, 2025
bdd8dba
docs: add helpful comments to scripts and workflow
matifali Apr 14, 2025
3f0615b
fmt
matifali Apr 14, 2025
8200f2d
Remove release script from package.json
matifali Apr 14, 2025
70e5da7
Remove trailing comma in package.json
matifali Apr 14, 2025
e4e5c73
Remove commented-out version check steps in CI
matifali Apr 14, 2025
57fc91f
Simplify and improve GitHub workflow and release scripts
matifali Apr 15, 2025
68f5396
Rename update-version.sh to update_version.sh and improve docs
matifali Apr 15, 2025
8aa9154
Review: refactor scripts
mafredri Apr 17, 2025
974f3f6
Delete .github/workflows/update-readme-version.yaml
matifali Apr 22, 2025
2086134
Update CONTRIBUTING.md
matifali Apr 22, 2025
6b1b617
Merge branch 'main' into separate-versioning
matifali Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review: refactor scripts
  • Loading branch information
mafredri committed Apr 22, 2025
commit 8aa9154bdba5cfe7539d85541caf1472831e4224
273 changes: 167 additions & 106 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,135 +1,196 @@
#!/usr/bin/env bash
#
# release.sh - Creates annotated tags for module releases
#
# This script is used by maintainers to create annotated tags for module releases.
# It supports three main modes:
# 1. Creating a new tag for a module: ./release.sh module-name X.Y.Z
# 2. Creating and pushing a new tag for a module: ./release.sh module-name X.Y.Z --push
# 3. Listing all modules with their versions: ./release.sh --list
#
# When a tag is pushed, it triggers a GitHub workflow that updates README versions.

set -euo pipefail

# Function to extract version from README
extract_version() {
grep -o 'version *= *"[0-9]\+\.[0-9]\+\.[0-9]\+"' "$1" | head -1 | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || echo "0.0.0"
usage() {
cat <<EOF
Usage: $0 [OPTIONS] [<MODULE> <VERSION>]

Create annotated git tags for module releases.

This script is used by maintainers to create annotated tags for module
releases. When a tag is pushed, it triggers a GitHub workflow that
updates README versions.

Options:
-l, --list List all modules with their versions
-n, --dry-run Show what would be done without making changes
-p, --push Push the created tag to the remote repository
-h, --help Show this help message

Examples:
$0 --list
$0 nodejs 1.2.3
$0 nodejs 1.2.3 --push
$0 --dry-run nodejs 1.2.3
EOF
exit "${1:-0}"
}

# Parse command line options
LIST=false
DRY_RUN=false
PUSH=false
TEMP=$(getopt -o 'ldp' --long 'list,dry-run,push' -n 'release.sh' -- "$@")
eval set -- "$TEMP"

while true; do
case "$1" in
-l | --list)
LIST=true
shift
;;
-d | --dry-run)
DRY_RUN=true
shift
;;
-p | --push)
PUSH=true
shift
;;
--)
shift
break
;;
*)
echo "Internal error!"
check_getopt() {
# Check if we have GNU or BSD getopt.
if getopt --test >/dev/null 2>&1; then
# Exit status 4 means GNU getopt is available.
if [[ $? -ne 4 ]]; then
echo "Error: GNU getopt is not available." >&2
echo "On macOS, you can install GNU getopt and add it to your PATH:" >&2
echo
echo $'\tbrew install gnu-getopt' >&2
echo $'\texport PATH="$(brew --prefix gnu-getopt)/bin:$PATH"' >&2
exit 1
;;
esac
done
fi
fi
}

maybe_dry_run() {
if [[ $dry_run == true ]]; then
echo "[DRY RUN] $*"
return 0
fi
"$@"
}

get_readme_version() {
grep -o 'version *= *"[0-9]\+\.[0-9]\+\.[0-9]\+"' "$1" |
head -1 |
grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' ||
echo "0.0.0"
}

# Handle listing all modules and their versions
if [[ "$LIST" == "true" ]]; then
# Display header for module listing
echo "Listing all modules and their latest versions:"
echo "----------------------------------------------------------"
printf "%-30s %-15s %s\n" "MODULE" "README VERSION" "LATEST TAG"
echo "----------------------------------------------------------"
list_modules() {
printf "\nListing all modules and their latest versions:\n"
printf "%s\n" "--------------------------------------------------------------"
printf "%-30s %-15s %-15s\n" "MODULE" "README VERSION" "LATEST TAG"
printf "%s\n" "--------------------------------------------------------------"

# Loop through all module directories
# Process each module directory.
for dir in */; do
if [[ -d "$dir" && -f "${dir}README.md" && "$dir" != ".git/" ]]; then
module_name="${dir%/}"
# Skip non-module directories.
[[ ! -d $dir || ! -f ${dir}README.md || $dir == ".git/" ]] && continue

module="${dir%/}"
readme_version=$(get_readme_version "${dir}README.md")
latest_tag=$(git tag -l "release/${module}/v*" | sort -V | tail -n 1)
tag_version="none"
if [[ -n $latest_tag ]]; then
tag_version="${latest_tag#"release/${module}/v"}"
fi

# Get README version
readme_version=$(extract_version "${dir}README.md")
printf "%-30s %-15s %-15s\n" "$module" "$readme_version" "$tag_version"
done

# Get latest tag for this module
latest_tag=$(git tag -l "release/${module_name}/v*" | sort -V | tail -n 1)
printf "%s\n" "--------------------------------------------------------------"
}

# Set tag version with parameter expansion and default value
tag_version=${latest_tag:+${latest_tag#release/${module_name}/v}}
tag_version=${tag_version:-none}
is_valid_version() {
if ! [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format X.Y.Z (e.g., 1.2.3)" >&2
return 1
fi
}

# Display module info
printf "%-30s %-15s %s\n" "$module_name" "$readme_version" "$tag_version"
fi
done
get_tag_name() {
local module="$1"
local version="$2"
local tag_name="release/$module/v$version"
local readme_path="$module/README.md"

echo "----------------------------------------------------------"
exit 0
fi
if [[ ! -d $module || ! -f $readme_path ]]; then
echo "Error: Module '$module' not found or missing README.md" >&2
return 1
fi

# Validate arguments for module release
if [[ "$#" -ne 2 ]]; then
echo "Usage: ./release.sh [--dry-run] module-name X.Y.Z"
echo " or: ./release.sh --list"
exit 1
local readme_version
readme_version=$(get_readme_version "$readme_path")

{
echo "Module: $module"
echo "Current README version: $readme_version"
echo "New tag version: $version"
echo "Tag name: $tag_name"
} >&2

echo "$tag_name"
}

# Ensure getopt is available.
check_getopt

# Set defaults.
list=false
dry_run=false
push=false
module=
version=

# Parse command-line options.
if ! temp=$(getopt -o ldph --long list,dry-run,push,help -n "$0" -- "$@"); then
echo "Error: Failed to parse arguments" >&2
usage 1
fi
eval set -- "$temp"

while true; do
case "$1" in
-l | --list)
list=true
shift
;;
-d | --dry-run)
dry_run=true
shift
;;
-p | --push)
push=true
shift
;;
-h | --help)
usage
;;
--)
shift
break
;;
*)
echo "Error: Internal error!" >&2
exit 1
;;
esac
done

MODULE_NAME="$1"
VERSION="$2"
if [[ $list == true ]]; then
list_modules
exit 0
fi

# Validate version format
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format X.Y.Z"
exit 1
if [[ $# -ne 2 ]]; then
echo "Error: MODULE and VERSION are required when not using --list" >&2
usage 1
fi

# Check if module exists
if [[ ! -d "$MODULE_NAME" || ! -f "$MODULE_NAME/README.md" ]]; then
echo "Error: Module directory not found or missing README.md"
module="$1"
version="$2"

if ! is_valid_version "$version"; then
exit 1
fi

# Get current README version and construct tag name
README_VERSION=$(extract_version "$MODULE_NAME/README.md")
TAG_NAME="release/$MODULE_NAME/v$VERSION"

# Check if tag already exists
if git rev-parse -q --verify "refs/tags/$TAG_NAME" > /dev/null; then
echo "Error: Tag $TAG_NAME already exists"
if ! tag_name=$(get_tag_name "$module" "$version"); then
exit 1
fi

# Display release information
echo "Module: $MODULE_NAME"
echo "Current README version: $README_VERSION"
echo "New tag version: $VERSION"
echo "Tag name: $TAG_NAME"

# Create the tag (or simulate in dry-run mode)
if [[ "$DRY_RUN" == "false" ]]; then
# Create annotated tag
git tag -a "$TAG_NAME" -m "Release $MODULE_NAME v$VERSION"
echo "Tag '$TAG_NAME' created."
if [[ "$PUSH" == "true" ]]; then
git push origin "$TAG_NAME"
echo "Success! Tag '$TAG_NAME' pushed to remote."
fi
if git rev-parse -q --verify "refs/tags/$tag_name" >/dev/null 2>&1; then
echo "Notice: Tag '$tag_name' already exists" >&2
else
echo "[DRY RUN] Would create tag: $TAG_NAME"
maybe_dry_run git tag -a "$tag_name" -m "Release $module v$version"
if [[ $push == true ]]; then
maybe_dry_run echo "Tag '$tag_name' created."
else
maybe_dry_run echo "Tag '$tag_name' created locally. Use --push to push it to remote."
maybe_dry_run "ℹ️ Note: Remember to push the tag when ready."
fi
fi

exit 0
if [[ $push == true ]]; then
maybe_dry_run git push origin "$tag_name"
maybe_dry_run echo "Success! Tag '$tag_name' pushed to remote."
fi
Loading
0