|
| 1 | +# !/bin/bash (This is not used as the script is executed with bash command without execution permission) |
| 2 | +# Set strict mode |
| 3 | +set -eu |
| 4 | + |
| 5 | +# Check if in dry run mode |
| 6 | +if [[ "$DRY_RUN" == "true" ]]; then |
| 7 | + echo "::notice::Running in dry run mode. No actual changes will be made." |
| 8 | +fi |
| 9 | + |
| 10 | +# Use the BRANCH_NAME environment variable passed from the workflow |
| 11 | +# Verify that BRANCH_NAME is set |
| 12 | +if [[ -z "${BRANCH_NAME:-}" ]]; then |
| 13 | + echo "::error::BRANCH_NAME environment variable is not set. This should be set by the workflow." |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +echo "Using branch name: $BRANCH_NAME" |
| 18 | + |
| 19 | +if [[ "$DRY_RUN" != "true" ]]; then |
| 20 | + git config --global user.name 'github-actions[bot]' |
| 21 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 22 | + git checkout -b $BRANCH_NAME |
| 23 | +else |
| 24 | + echo "dry run: git checkout -b $BRANCH_NAME" |
| 25 | +fi |
| 26 | + |
| 27 | +# Initialize PR body |
| 28 | +PR_TEMPLATE=$(cat .github/check-new-release/templates/pr.md) |
| 29 | +PR_BODY="" |
| 30 | + |
| 31 | +# Version update function |
| 32 | +update_version() { |
| 33 | + local type=$1 |
| 34 | + local current_version=$2 |
| 35 | + local new_version=$3 |
| 36 | + local major_version=$(echo "$new_version" | cut -d. -f1) |
| 37 | + local minor_version=$(echo "$new_version" | cut -d. -f2) |
| 38 | + local short_version="${major_version}.${minor_version}" |
| 39 | + |
| 40 | + echo "Updating $type to $new_version (major.minor: $short_version)..." |
| 41 | + |
| 42 | + # Update Dockerfile |
| 43 | + if [[ "$DRY_RUN" != "true" ]]; then |
| 44 | + if ! sed -i "s/^ARG MYSQL_SHELL_VERSION=.*/ARG MYSQL_SHELL_VERSION=$new_version/" docker/$type/Dockerfile; then |
| 45 | + echo "::error::Failed to update version in docker/$type/Dockerfile" |
| 46 | + echo "This is a critical error while updating an important file. Aborting." |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + |
| 50 | + # Verify the update was successful |
| 51 | + if ! grep -q "ARG MYSQL_SHELL_VERSION=$new_version" docker/$type/Dockerfile; then |
| 52 | + echo "::error::Version update in docker/$type/Dockerfile could not be verified" |
| 53 | + echo "Cannot verify Dockerfile update. Aborting." |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + else |
| 57 | + # Show more detailed information in dry run mode |
| 58 | + echo "dry run: Command to execute: sed -i \"s/^ARG MYSQL_SHELL_VERSION=.*/ARG MYSQL_SHELL_VERSION=$new_version/\" docker/$type/Dockerfile" |
| 59 | + echo "dry run: Update ARG MYSQL_SHELL_VERSION=$current_version to $new_version in docker/$type/Dockerfile" |
| 60 | + fi |
| 61 | + |
| 62 | + # Update README.md |
| 63 | + if [[ "$type" == "innovation" ]]; then |
| 64 | + local match_pattern="Innovation Series ([0-9]\\.[0-9]\\.[x0-9])" |
| 65 | + local replace_value="Innovation Series (${major_version}.${minor_version}.x)" |
| 66 | + local tag_pattern="snickerjp\/docker-mysql-shell:${major_version}\\.[0-9]" |
| 67 | + local tag_replace="snickerjp\/docker-mysql-shell:${short_version}" |
| 68 | + |
| 69 | + if [[ "$DRY_RUN" != "true" ]]; then |
| 70 | + # README updates are important but we continue even if they fail |
| 71 | + sed -i "s/$match_pattern/$replace_value/g" README.md |
| 72 | + if [ $? -ne 0 ]; then |
| 73 | + echo "::warning::Failed to update Innovation Series version in README.md" |
| 74 | + echo "Failed to update README.md but will continue with the process." |
| 75 | + fi |
| 76 | + |
| 77 | + sed -i "s/$tag_pattern/$tag_replace/g" README.md |
| 78 | + if [ $? -ne 0 ]; then |
| 79 | + echo "::warning::Failed to update Innovation image tag in README.md" |
| 80 | + echo "Failed to update tag in README.md but will continue with the process." |
| 81 | + fi |
| 82 | + else |
| 83 | + # Show more detailed information in dry run mode |
| 84 | + echo "dry run: Command to execute: sed -i \"s/$match_pattern/$replace_value/g\" README.md" |
| 85 | + echo "dry run: Command to execute: sed -i \"s/$tag_pattern/$tag_replace/g\" README.md" |
| 86 | + echo "dry run: Update '$match_pattern' to '$replace_value' in README.md" |
| 87 | + echo "dry run: Update '$tag_pattern' to '$tag_replace' in README.md" |
| 88 | + fi |
| 89 | + else |
| 90 | + local match_pattern="LTS Series ([0-9]\\.[0-9]\\.[x0-9])" |
| 91 | + local replace_value="LTS Series (${major_version}.${minor_version}.x)" |
| 92 | + local tag_pattern="snickerjp\/docker-mysql-shell:${major_version}\\.[0-9]" |
| 93 | + local tag_replace="snickerjp\/docker-mysql-shell:${short_version}" |
| 94 | + |
| 95 | + if [[ "$DRY_RUN" != "true" ]]; then |
| 96 | + sed -i "s/$match_pattern/$replace_value/g" README.md |
| 97 | + if [ $? -ne 0 ]; then |
| 98 | + echo "::warning::Failed to update LTS Series version in README.md" |
| 99 | + echo "Failed to update README.md but will continue with the process." |
| 100 | + fi |
| 101 | + |
| 102 | + sed -i "s/$tag_pattern/$tag_replace/g" README.md |
| 103 | + if [ $? -ne 0 ]; then |
| 104 | + echo "::warning::Failed to update LTS image tag in README.md" |
| 105 | + echo "Failed to update tag in README.md but will continue with the process." |
| 106 | + fi |
| 107 | + else |
| 108 | + # Show more detailed information in dry run mode |
| 109 | + echo "dry run: Command to execute: sed -i \"s/$match_pattern/$replace_value/g\" README.md" |
| 110 | + echo "dry run: Command to execute: sed -i \"s/$tag_pattern/$tag_replace/g\" README.md" |
| 111 | + echo "dry run: Update '$match_pattern' to '$replace_value' in README.md" |
| 112 | + echo "dry run: Update '$tag_pattern' to '$tag_replace' in README.md" |
| 113 | + fi |
| 114 | + fi |
| 115 | + |
| 116 | + # Automatically update workflow files |
| 117 | + local workflow_files=$(find .github/workflows -name "docker-*.yml" 2>/dev/null || echo "") |
| 118 | + if [[ -n "$workflow_files" ]]; then |
| 119 | + echo "Automatically updating workflow files..." |
| 120 | + |
| 121 | + local version_pattern="version: ${major_version}\\.x" |
| 122 | + local version_replace="version: ${short_version}" |
| 123 | + |
| 124 | + if [[ "$DRY_RUN" != "true" ]]; then |
| 125 | + # Execute for each file |
| 126 | + for workflow_file in $workflow_files; do |
| 127 | + if grep -q "$version_pattern" "$workflow_file"; then |
| 128 | + echo "Updating: $workflow_file" |
| 129 | + sed -i "s/$version_pattern/$version_replace/g" "$workflow_file" |
| 130 | + if [ $? -ne 0 ]; then |
| 131 | + echo "::warning::Failed to update version in $workflow_file" |
| 132 | + echo "Failed to update workflow file $workflow_file but will continue with the process." |
| 133 | + fi |
| 134 | + else |
| 135 | + echo "::info::No matching pattern found, no update needed: $workflow_file" |
| 136 | + fi |
| 137 | + done |
| 138 | + else |
| 139 | + echo "dry run: Files to be updated:" |
| 140 | + for workflow_file in $workflow_files; do |
| 141 | + if grep -q "$version_pattern" "$workflow_file"; then |
| 142 | + echo "dry run: Update '$version_pattern' to '$version_replace' in $workflow_file" |
| 143 | + echo "dry run: Command to execute: sed -i \"s/$version_pattern/$version_replace/g\" \"$workflow_file\"" |
| 144 | + fi |
| 145 | + done |
| 146 | + fi |
| 147 | + |
| 148 | + # Add workflow file update note to PR description |
| 149 | + PR_BODY="${PR_BODY} (Workflow files were automatically updated)" |
| 150 | + else |
| 151 | + echo "::warning::No workflow files found." |
| 152 | + fi |
| 153 | + |
| 154 | + # Add version update details to PR body (formatted) |
| 155 | + PR_BODY="${PR_BODY} |
| 156 | +
|
| 157 | +### ${type^} Version Update |
| 158 | +* **${current_version}** → **${new_version}**" |
| 159 | + |
| 160 | + # Success log |
| 161 | + echo "✅ $type version update completed" |
| 162 | +} |
| 163 | + |
| 164 | +# Update Innovation |
| 165 | +if [[ "$INNOVATION_UPDATE_NEEDED" == "true" ]]; then |
| 166 | + update_version "innovation" "$CURRENT_INNOVATION" "$LATEST_INNOVATION" |
| 167 | +fi |
| 168 | + |
| 169 | +# Update LTS |
| 170 | +if [[ "$LTS_UPDATE_NEEDED" == "true" ]]; then |
| 171 | + update_version "lts" "$CURRENT_LTS" "$LATEST_LTS" |
| 172 | +fi |
| 173 | + |
| 174 | +# Add necessary steps to PR body |
| 175 | +PR_BODY="${PR_BODY} |
| 176 | +
|
| 177 | +## Update Content |
| 178 | +- Updated version numbers in Dockerfiles |
| 179 | +- Updated version references in README.md |
| 180 | +- Automatically updated workflow files |
| 181 | +
|
| 182 | +## ⚠️ Notes |
| 183 | +1. If workflow files were not automatically updated, please update them manually |
| 184 | +2. Please verify all file changes before merging" |
| 185 | + |
| 186 | +# Commit and push changes |
| 187 | +changed_files=$(git status --porcelain | awk '{print $2}') |
| 188 | +if [[ -z "$changed_files" ]]; then |
| 189 | + echo "No changes to commit." |
| 190 | + exit 0 |
| 191 | +fi |
| 192 | + |
| 193 | +# Check changed files |
| 194 | +echo "Changed files:" |
| 195 | +for file in $changed_files; do |
| 196 | + echo "- $file" |
| 197 | +done |
| 198 | + |
| 199 | +# Stage all changes |
| 200 | +if [[ "$DRY_RUN" != "true" ]]; then |
| 201 | + git add $changed_files |
| 202 | + git commit -m "Update MySQL Shell versions (Innovation: $LATEST_INNOVATION, LTS: $LATEST_LTS)" |
| 203 | + |
| 204 | + # Push with error handling |
| 205 | + if ! git push origin $BRANCH_NAME; then |
| 206 | + echo "::error::Failed to push changes to GitHub" |
| 207 | + exit 1 |
| 208 | + fi |
| 209 | + |
| 210 | + # Create pull request |
| 211 | + if ! gh pr create \ |
| 212 | + --base develop \ |
| 213 | + --head $BRANCH_NAME \ |
| 214 | + --title "Update MySQL Shell versions (Innovation: $LATEST_INNOVATION, LTS: $LATEST_LTS)" \ |
| 215 | + --body "$PR_BODY"; then |
| 216 | + echo "::error::Failed to create Pull Request" |
| 217 | + exit 1 |
| 218 | + fi |
| 219 | + |
| 220 | + echo "Pull request created successfully!" |
| 221 | +else |
| 222 | + echo "dry run: The following files would be changed:" |
| 223 | + for file in $changed_files; do |
| 224 | + echo "- $file" |
| 225 | + done |
| 226 | + echo "dry run: Commit message: Update MySQL Shell versions (Innovation: $LATEST_INNOVATION, LTS: $LATEST_LTS)" |
| 227 | + echo "dry run: PR creation: Title: Update MySQL Shell versions (Innovation: $LATEST_INNOVATION, LTS: $LATEST_LTS)" |
| 228 | + echo "dry run: PR body:" |
| 229 | + echo -e "$PR_BODY" |
| 230 | + echo "dry run completed: No actual changes were made." |
| 231 | +fi |
0 commit comments