diff --git a/README.md b/README.md index 4a85a46..fcf4c6e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ For help getting started with Flutter development, view the [online documentation](https://docs.flutter.dev/), which offers tutorials, samples, guidance on mobile development, and a full API reference. - ## flutter_launcher_icons Icon launcher generator @@ -40,3 +39,11 @@ dart run build_runner build --delete-conflicting-outputs ```batch dart pub global activate dependency_validator && dart pub run dependency_validator ``` + +## Increment version and generate changelog + +Run this script in project root to create apk + +```batch +Usage: ./scripts/version_and_changelog.sh +``` diff --git a/scripts/build_app.sh b/scripts/build_app.sh new file mode 100755 index 0000000..2f84d50 --- /dev/null +++ b/scripts/build_app.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# Get the project name from pubspec.yaml +PROJECT_NAME=$(grep 'name:' pubspec.yaml | awk -F ': ' '{print $2}') + +# Set the path to your Flutter project +PROJECT_PATH="." + +# Navigate to the project directory +cd "$PROJECT_PATH" + +# Clean the project +flutter clean + +# Get the latest dependencies +flutter pub get + +# Get the current version from pubspec.yaml +VERSION=$(grep 'version:' pubspec.yaml | awk -F ': ' '{print $2}') +VERSION_NUMBER=$(echo $VERSION | awk -F '+' '{print $1}') +BUILD_NUMBER=$(echo $VERSION | awk -F '+' '{print $2}') + +# Update the version in pubspec.yaml +NEW_VERSION="$VERSION_NUMBER+$BUILD_NUMBER" +sed -i '' "s/version: $VERSION/version: $NEW_VERSION/" pubspec.yaml + +# Build and rename function for APK +build_and_rename_apk() { + local flavor="$1" + flutter build apk --no-tree-shake-icons + + # Determine the output directory based on the flavor + OUTPUT_DIR="$PROJECT_PATH/build/app/outputs/flutter-apk" + + # Rename the output APK file with the version + APK_FILE="$OUTPUT_DIR/app-release.apk" + NEW_APK_NAME="$OUTPUT_DIR/${flavor}_v$NEW_VERSION.apk" + mv "$APK_FILE" "$NEW_APK_NAME" + + echo "Build completed and APK for $flavor renamed to $NEW_APK_NAME" +} + +# Build and rename function for IPA +build_and_rename_ipa() { + local flavor="$1" + flutter build ipa + + # Determine the output directory for the IPA file + OUTPUT_DIR="$PROJECT_PATH/build/ios/ipa" + + # Rename the output IPA file with the version + IPA_FILE="$OUTPUT_DIR/app.ipa" + NEW_IPA_NAME="$OUTPUT_DIR/${flavor}_v$NEW_VERSION.ipa" + mv "$IPA_FILE" "$NEW_IPA_NAME" + + echo "Build completed and IPA for $flavor renamed to $NEW_IPA_NAME" +} + +# Function to display usage instructions +show_usage() { + echo "Usage: $0 [android|ios|both]" + echo " android - Build only the Android APK" + echo " ios - Build only the iOS IPA (macOS only)" + echo " both - Build both Android APK and iOS IPA (macOS only)" +} + +# Check for user input +if [ -z "$1" ]; then + show_usage + exit 1 +fi + +# Process the user's choice +case "$1" in + android) + echo "Building APK for Android..." + build_and_rename_apk $PROJECT_NAME + ;; + ios) + if [[ "$OSTYPE" == "darwin"* ]]; then + echo "Building IPA for iOS..." + build_and_rename_ipa $PROJECT_NAME + else + echo "Skipping IPA build; not running on macOS." + fi + ;; + both) + echo "Building APK for Android..." + build_and_rename_apk $PROJECT_NAME + if [[ "$OSTYPE" == "darwin"* ]]; then + echo "Building IPA for iOS..." + build_and_rename_ipa $PROJECT_NAME + else + echo "Skipping IPA build; not running on macOS." + fi + ;; + *) + echo "Invalid option: $1" + show_usage + exit 1 + ;; +esac \ No newline at end of file diff --git a/scripts/generate_changelog.sh b/scripts/generate_changelog.sh new file mode 100644 index 0000000..024d1d2 --- /dev/null +++ b/scripts/generate_changelog.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Set the output file for the changelog +OUTPUT_FILE="CHANGELOG.md" +TEMP_FILE="CHANGELOG_TEMP.md" +VERSION="" + +# Check if Git and pubspec.yaml are available +if ! command -v git &> /dev/null; then + echo "Git is not installed. Please install Git and try again." + exit 1 +fi + +if [ ! -f "pubspec.yaml" ]; then + echo "pubspec.yaml not found. Please ensure this script is run in the root of a Flutter project." + exit 1 +fi + +# Get the current version from pubspec.yaml +VERSION=$(grep 'version:' pubspec.yaml | awk -F ': ' '{print $2}' | awk -F '+' '{print $1}') + +if [ -z "$VERSION" ]; then + echo "Failed to extract version from pubspec.yaml." + exit 1 +fi + +# Check if OUTPUT_FILE exists, if not create it +if [ ! -f "$OUTPUT_FILE" ]; then + echo "# Changelog" > "$OUTPUT_FILE" + echo "" >> "$OUTPUT_FILE" + echo "All notable changes to this project are documented below." >> "$OUTPUT_FILE" + echo "" >> "$OUTPUT_FILE" +fi + +# Write the new version at the top +echo "## $VERSION" > "$TEMP_FILE" + +# Generate sections based on commit types +echo "Generating changelog for version $VERSION..." + +# Features +echo "### Features" >> "$TEMP_FILE" +git log --no-merges --pretty=format:"- %s" | grep "feat:" >> "$TEMP_FILE" || echo "No features found." >> "$TEMP_FILE" +echo "" >> "$TEMP_FILE" + +# Bug Fixes +echo "### Bug Fixes" >> "$TEMP_FILE" +git log --no-merges --pretty=format:"- %s" | grep "fix:" >> "$TEMP_FILE" || echo "No bug fixes found." >> "$TEMP_FILE" +echo "" >> "$TEMP_FILE" + +# Chores +echo "### Chores" >> "$TEMP_FILE" +git log --no-merges --pretty=format:"- %s" | grep "chore:" >> "$TEMP_FILE" || echo "No chores found." >> "$TEMP_FILE" +echo "" >> "$TEMP_FILE" + +# Miscellaneous +echo "### Miscellaneous" >> "$TEMP_FILE" +git log --no-merges --pretty=format:"- %s" | grep -v -E "feat:|fix:|chore:" >> "$TEMP_FILE" || echo "No miscellaneous changes found." >> "$TEMP_FILE" +echo "" >> "$TEMP_FILE" + +# Append the existing changelog to the temporary file +cat "$OUTPUT_FILE" >> "$TEMP_FILE" + +# Replace the old changelog with the new one +mv "$TEMP_FILE" "$OUTPUT_FILE" + +# Notify user +echo "Changelog updated successfully: $OUTPUT_FILE" \ No newline at end of file diff --git a/scripts/increment_version_from_commit.sh b/scripts/increment_version_from_commit.sh new file mode 100644 index 0000000..130bb1e --- /dev/null +++ b/scripts/increment_version_from_commit.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# File path +PUBSPEC_FILE="pubspec.yaml" + +# Function to increment version +increment_version() { + local version=$1 + local index=$2 + IFS='.' read -r -a parts <<< "$version" + + # Incremente la version en fonction de l'index et remet les autres à 0 + parts[$index]=$((parts[$index] + 1)) + + # Remet les parties suivantes à 0 + for ((i = index + 1; i < ${#parts[@]}; i++)); do + parts[$i]=0 + done + + echo "${parts[*]}" | tr ' ' '.' +} + +# Check if pubspec.yaml exists +if [ ! -f "$PUBSPEC_FILE" ]; then + echo "Error: $PUBSPEC_FILE not found in the current directory." + exit 1 +fi + +# Extract the current version and build number +CURRENT_VERSION=$(grep 'version:' $PUBSPEC_FILE | awk -F ': ' '{print $2}') +VERSION=$(echo "$CURRENT_VERSION" | cut -d'+' -f1) +BUILD=$(echo "$CURRENT_VERSION" | cut -d'+' -f2) + +if [ -z "$VERSION" ] || [ -z "$BUILD" ]; then + echo "Error: Could not extract version and build number from pubspec.yaml." + exit 1 +fi + +# Get commit types from the latest changes +LATEST_COMMITS=$(git log --oneline -10) +echo "Analyzing latest commits..." +echo "$LATEST_COMMITS" + +if echo "$LATEST_COMMITS" | grep -iq "breaking"; then + INCREMENT_TYPE="major" +elif echo "$LATEST_COMMITS" | grep -iq "feat"; then + INCREMENT_TYPE="minor" +elif echo "$LATEST_COMMITS" | grep -iq "fix"; then + INCREMENT_TYPE="patch" +else + INCREMENT_TYPE="build" +fi + +echo "Detected increment type: $INCREMENT_TYPE" + +# Determine new version and build number +case $INCREMENT_TYPE in +major) + NEW_VERSION=$(increment_version "$VERSION" 0) + NEW_BUILD=1 + ;; +minor) + NEW_VERSION=$(increment_version "$VERSION" 1) + NEW_BUILD=1 + ;; +patch) + NEW_VERSION=$(increment_version "$VERSION" 2) + NEW_BUILD=1 + ;; +build) + NEW_VERSION=$VERSION + NEW_BUILD=$((BUILD + 1)) + ;; +*) + echo "Error: Unknown increment type." + exit 1 + ;; +esac + +# Update the version in pubspec.yaml +sed -i.bak "s/^version: .*/version: $NEW_VERSION+$NEW_BUILD/" $PUBSPEC_FILE + +echo "Version updated to $NEW_VERSION+$NEW_BUILD in $PUBSPEC_FILE" \ No newline at end of file diff --git a/scripts/version_and_changelog.sh b/scripts/version_and_changelog.sh new file mode 100755 index 0000000..edd06f6 --- /dev/null +++ b/scripts/version_and_changelog.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +# File paths +PUBSPEC_FILE="pubspec.yaml" +CHANGELOG_FILE="CHANGELOG.md" + +# Check if pubspec.yaml exists +if [ ! -f "$PUBSPEC_FILE" ]; then + echo "Error: $PUBSPEC_FILE not found in the current directory." + exit 1 +fi + +# Extract the current version and build number +CURRENT_VERSION=$(grep 'version:' $PUBSPEC_FILE | awk -F ': ' '{print $2}') +VERSION=$(echo "$CURRENT_VERSION" | cut -d'+' -f1) +BUILD=$(echo "$CURRENT_VERSION" | cut -d'+' -f2) + +if [ -z "$VERSION" ] || [ -z "$BUILD" ]; then + echo "Error: Could not extract version and build number from pubspec.yaml." + exit 1 +fi + +echo "Current version: $VERSION+$BUILD" + +# Function to increment version +increment_version() { + local version=$1 + local index=$2 + IFS='.' read -r -a parts <<< "$version" + parts[$index]=$((parts[$index] + 1)) + for ((i = index + 1; i < ${#parts[@]}; i++)); do + parts[$i]=0 + done + echo "${parts[*]}" | tr ' ' '.' +} + +# Get the hash of the last commit containing "chore: increment version" +LAST_BOT_COMMIT_HASH=$(git log --oneline --grep="chore: increment version" -n 1 | cut -d ' ' -f1 || echo "NONE") + +# Get commits after the bot commit to analyze changes +if [ "$LAST_BOT_COMMIT_HASH" == "NONE" ]; then + LATEST_COMMITS=$(git log --oneline --no-merges) +else + LATEST_COMMITS=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD) +fi + +echo "Analyzing latest commits..." +echo "$LATEST_COMMITS" + +# Determine increment type based on commit messages +if echo "$LATEST_COMMITS" | grep -iq "breaking:"; then + INCREMENT_TYPE="major" +elif echo "$LATEST_COMMITS" | grep -iq "feat:"; then + INCREMENT_TYPE="minor" +elif echo "$LATEST_COMMITS" | grep -iq "fix:"; then + INCREMENT_TYPE="patch" +elif echo "$LATEST_COMMITS" | grep -iq "chore:"; then + INCREMENT_TYPE="patch" +elif echo "$LATEST_COMMITS" | grep -iq "build:"; then + INCREMENT_TYPE="build" +else + INCREMENT_TYPE="patch" +fi + +echo "Detected increment type: $INCREMENT_TYPE" + +# Determine new version and build number based on the increment type +NEW_BUILD=$(($BUILD + 1)) + +case $INCREMENT_TYPE in +major) + NEW_VERSION=$(increment_version "$VERSION" 0) + ;; +minor) + NEW_VERSION=$(increment_version "$VERSION" 1) + ;; +patch) + NEW_VERSION=$(increment_version "$VERSION" 2) + ;; +*) + echo "Error: Unknown increment type." + exit 1 + ;; +esac + +# Update the version in pubspec.yaml +sed -i.bak "s/^version: .*/version: $NEW_VERSION+$NEW_BUILD/" $PUBSPEC_FILE +echo "Version updated to $NEW_VERSION+$NEW_BUILD in $PUBSPEC_FILE" + +# Ensure the changelog file exists +if [ ! -f "$CHANGELOG_FILE" ]; then + echo "# Changelog" > "$CHANGELOG_FILE" + echo "" >> "$CHANGELOG_FILE" +fi + +# Start building the changelog for the current version +TEMP_CHANGELOG="CHANGELOG_TEMP.md" +DATE=$(date +"%Y-%m-%d") +{ + echo "## $NEW_VERSION+$NEW_BUILD ($DATE)" + echo "" + echo "### Breaking Changes" + BREAKING=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD | grep "breaking:" | sed -E 's/^([a-f0-9]+) breaking: /- (#\1) /g') + echo "${BREAKING:-No breaking changes found.}" + echo "" + echo "### Features" + FEATURES=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD | grep "feat:" | sed -E 's/^([a-f0-9]+) feat: /- (#\1) /g') + echo "${FEATURES:-No features found.}" + echo "" + echo "### Bug Fixes" + BUG_FIXES=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD | grep "fix:" | sed -E 's/^([a-f0-9]+) fix: /- (#\1) /g') + echo "${BUG_FIXES:-No bug fixes found.}" + echo "" + echo "### Chores" + CHORES=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD | grep "chore:" | sed -E 's/^([a-f0-9]+) chore: /- (#\1) /g') + echo "${CHORES:-No chores found.}" + echo "" + echo "### Refactors" + CHORES=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD | grep "refactor:" | sed -E 's/^([a-f0-9]+) refactor: /- (#\1) /g') + echo "${CHORES:-No refactors found.}" + echo "" + echo "### Style Changes" + CHORES=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD | grep "style:" | sed -E 's/^([a-f0-9]+) style: /- (#\1) /g') + echo "${CHORES:-No style Changes found.}" + echo "" + echo "### Miscellaneous" + MISC=$(git log --oneline --no-merges "$LAST_BOT_COMMIT_HASH"..HEAD | grep -v -E "breaking:|feat:|fix:|chore:" | sed -E 's/^([a-f0-9]+) /- (#\1) /g') + echo "${MISC:-No miscellaneous changes found.}" + echo "" + cat "$CHANGELOG_FILE" +} > "$TEMP_CHANGELOG" + +mv "$TEMP_CHANGELOG" "$CHANGELOG_FILE" +echo "Changelog updated successfully." + +# # Commit version and changelog update +git config --global user.email "your-email@example.com" +git config --global user.name "your-name" +git add pubspec.yaml CHANGELOG.md +git commit -m "chore: increment version $NEW_VERSION+$NEW_BUILD and update changelog" +# git push \ No newline at end of file