|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Colors for output |
| 4 | +GREEN='\033[0;32m' |
| 5 | +RED='\033[0;31m' |
| 6 | +YELLOW='\033[1;33m' |
| 7 | +NC='\033[0m' # No Color |
| 8 | + |
| 9 | +# Function for success message |
| 10 | +success() { |
| 11 | + echo -e "${GREEN}OK${NC}" |
| 12 | +} |
| 13 | + |
| 14 | +# Function for error message and exit |
| 15 | +error() { |
| 16 | + echo -e "${RED}ERROR${NC}" |
| 17 | + echo -e "${RED}$1${NC}" |
| 18 | + exit 1 |
| 19 | +} |
| 20 | + |
| 21 | +# Function to execute a command with prompts and status |
| 22 | +execute_step() { |
| 23 | + local message="$1" |
| 24 | + local command="$2" |
| 25 | + |
| 26 | + echo -e "${YELLOW}$message${NC}" |
| 27 | + read -p "Press Enter to continue... " |
| 28 | + |
| 29 | + eval "$command" |
| 30 | + if [ $? -ne 0 ]; then |
| 31 | + error "Command failed: $command" |
| 32 | + else |
| 33 | + success |
| 34 | + fi |
| 35 | +} |
| 36 | + |
| 37 | +# Check if the version argument is provided |
| 38 | +if [ -z "$1" ]; then |
| 39 | + echo "Usage: $0 <version>" |
| 40 | + echo "Please provide the new version number as an argument." |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +NEW_VERSION="$1" |
| 45 | +MAJOR_MINOR_VERSION="${NEW_VERSION%.*}" |
| 46 | +VERSION_LINK="${NEW_VERSION//./}" |
| 47 | +BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 48 | + |
| 49 | +if [ "$BRANCH" != "main" ]; then |
| 50 | + echo "Publish can only be used when checked out to \`main\` branch. You're currently checked out to \`$BRANCH\`." |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +execute_step "Updating changelog" "git cliff --tag \"$NEW_VERSION\" --prepend ./CHANGELOG.md --unreleased" |
| 55 | + |
| 56 | +execute_step "Updating Cargo.toml package version to $NEW_VERSION" "perl -i -pe \"s/^version = \\\".*\\\"/version = \\\"$NEW_VERSION\\\"/\" ./Cargo.toml" |
| 57 | + |
| 58 | +execute_step "Updating README.md version to $MAJOR_MINOR_VERSION" "perl -i -pe \"s/(kameo *= *\\\")[^\\\"]*(\\\".*)/$1$MAJOR_MINOR_VERSION$2/\" README.md" |
| 59 | + |
| 60 | +execute_step "Updating getting-started.mdx version to $MAJOR_MINOR_VERSION" "perl -i -pe \"s/(kameo *= *\\\")[^\\\"]*(\\\".*)/$1$MAJOR_MINOR_VERSION$2/\" ./docs/getting-started.mdx" |
| 61 | + |
| 62 | +execute_step "Publishing kameo version $NEW_VERSION" "cargo publish -p kameo --allow-dirty" |
| 63 | + |
| 64 | +execute_step "Creating bump git commit" "git add Cargo.toml CHANGELOG.md README.md docs/getting-started.mdx && git commit -m \"chore: bump kameo to version $NEW_VERSION\"" |
| 65 | + |
| 66 | +execute_step "Pushing changes to remote" "git push origin main" |
| 67 | + |
| 68 | +execute_step "Creating git tag v$NEW_VERSION" "git tag -a \"v$NEW_VERSION\" -m \"\"" |
| 69 | + |
| 70 | +execute_step "Pushing tag to remote" "git push origin \"v$NEW_VERSION\"" |
| 71 | + |
| 72 | +execute_step "Creating CHANGELOG-Release.md for release notes" "git cliff --tag \"$NEW_VERSION\" --output ./CHANGELOG-Release.md --current" |
| 73 | + |
| 74 | +# Extract the release date from the CHANGELOG-Release.md file |
| 75 | +RELEASE_DATE=$(grep '^## \['"$NEW_VERSION"'\] - ' CHANGELOG-Release.md | sed -E 's/.* - ([0-9]{4}-[0-9]{2}-[0-9]{2})$/\1/') |
| 76 | +if [ -z "$RELEASE_DATE" ]; then |
| 77 | + error "Failed to extract release date from changelog" |
| 78 | +fi |
| 79 | + |
| 80 | +execute_step "Processing release notes" "perl -i -ne 'print if /^### / .. eof' CHANGELOG-Release.md && perl -i -ne 'print unless /^\[.*\]:.*$/ .. eof' CHANGELOG-Release.md" |
| 81 | + |
| 82 | +# Append the footer with the extracted release date |
| 83 | +echo -e "---\n\nSee the full [CHANGELOG.md](https://github.com/tqwewe/kameo/blob/main/CHANGELOG.md#${VERSION_LINK}---${RELEASE_DATE})" >> CHANGELOG-Release.md |
| 84 | + |
| 85 | +execute_step "Creating GitHub release with changelog" "gh release create \"v$NEW_VERSION\" -F CHANGELOG-Release.md" |
| 86 | + |
| 87 | +# Clean up the temporary file |
| 88 | +rm CHANGELOG-Release.md |
| 89 | + |
| 90 | +echo -e "${GREEN}Release process completed successfully!${NC}" |
0 commit comments