Created
November 18, 2023 15:49
-
-
Save Patrick-web/8e8add7317d2c32081debeed829b5fe8 to your computer and use it in GitHub Desktop.
A Bash script that interactively prompts users to select a branch and a commit message for updating an EAS project. It provides options to choose from available branches and recent commit messages, allowing confirmation before executing the 'eas update' command. Designed for convenience and ease of use in managing EAS project updates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Function to extract branches from eas.json under the build section | |
| get_branches() { | |
| branches=$(jq -r '.build | to_entries[] | [.key] | @tsv' eas.json) | |
| echo "$branches" | |
| } | |
| echo "Available branches:" | |
| available_branches=$(get_branches) | |
| # Display branches with numbering | |
| echo "$available_branches" | awk '{printf "%d. %s\n", NR, $1}' | |
| echo -n "Enter the number of the branch: " | |
| read branch_number | |
| # Validate the selected number | |
| if ! [[ "$branch_number" =~ ^[0-9]+$ ]]; then | |
| echo "Invalid input. Please enter a number." | |
| exit 1 | |
| fi | |
| selected_branch=$(echo "$available_branches" | sed "${branch_number}q;d" | awk '{print $1}') | |
| echo "Selected branch: $selected_branch" | |
| echo "Do you want to:" | |
| echo "1. Enter a custom message" | |
| echo "2. Choose from the latest 5 commit messages" | |
| read -p "Enter your choice (1 or 2): " message_option | |
| if [ "$message_option" == "1" ]; then | |
| echo "Enter the message: " | |
| read message | |
| elif [ "$message_option" == "2" ]; then | |
| echo "Fetching latest commit messages..." | |
| commit_messages=$(git log --format=%B -n 5 | sed '/^$/d') | |
| echo "Latest 5 commit messages:" | |
| echo "$commit_messages" | awk '{printf "%d. %s\n", NR, $0}' | |
| echo -n "Enter the number of the commit message to use: " | |
| read commit_number | |
| # Validate the selected commit number | |
| if ! [[ "$commit_number" =~ ^[0-9]+$ ]]; then | |
| echo "Invalid input. Please enter a number." | |
| exit 1 | |
| fi | |
| message=$(echo "$commit_messages" | sed "${commit_number}q;d") | |
| else | |
| echo "Invalid choice. Exiting." | |
| exit 1 | |
| fi | |
| echo "Summary:" | |
| echo "Branch: $selected_branch" | |
| echo "Message: $message" | |
| read -p "Proceed with the update? (y/n): " confirm | |
| if [ "$confirm" != "y" ]; then | |
| echo "Update canceled." | |
| exit 0 | |
| fi | |
| eas update --branch $selected_branch --message "$message" --platform android |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment