Skip to content

Check first for existing branches before creating them#18

Open
wrandall22 wants to merge 2 commits intoyinlinchen:masterfrom
CruGlobal:handle-existing-branches
Open

Check first for existing branches before creating them#18
wrandall22 wants to merge 2 commits intoyinlinchen:masterfrom
CruGlobal:handle-existing-branches

Conversation

@wrandall22
Copy link

This PR is another attempt at fixing issue #10 after the reversion in #12. I found the echo lines to be helpful, but we can delete them if desired.

@wrandall22
Copy link
Author

This needs more work still, unfortunately, GetBranch fails with an exception instead of returning an empty object when the branch does not exist, so this needs some error handling.

@wrandall22 wrandall22 marked this pull request as draft April 26, 2024 20:11
@wrandall22 wrandall22 force-pushed the handle-existing-branches branch 2 times, most recently from 103f05a to 97414c2 Compare April 26, 2024 20:55
@wrandall22 wrandall22 force-pushed the handle-existing-branches branch from dca3e4d to 3484068 Compare April 29, 2024 13:23
@wrandall22
Copy link
Author

I believe this is working now (tested on a non-existing and existing branch). However, there is a side effect of a log in the console: sh: "branch":: unknown operand that shows up when the branch does exist.

@wrandall22 wrandall22 marked this pull request as ready for review April 29, 2024 14:01
@coelhucas
Copy link

Is there anything else missing we could do to merge this one? cc @yinlinchen @wrandall22

I'd be glad to help if needed, these errors for existing branches are bothering us a lot here 😅

@yinlinchen yinlinchen requested a review from Copilot June 10, 2025 15:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that a new Amplify branch is only created when it does not already exist, addressing issue #10. Key changes include:

  • Adding a branch existence check using aws amplify get-branch.
  • Conditional branch creation with appropriate echo statements.
  • Maintaining debug logging for deployment feedback.
Comments suppressed due to low confidence (1)

entrypoint.sh:59

  • Similarly, in the create-branch command, wrapping the variables in quotes can help ensure robust parsing of parameters.
sh -c "aws amplify create-branch --app-id=${AmplifyAppId} --branch-name=$BRANCH_NAME  \

sleep 10
echo "deploying"

if [[ -z $(aws amplify get-branch --app-id=${AmplifyAppId} --branch-name=$BRANCH_NAME --region=${AWS_REGION} 2> /dev/null) ]]; then
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid potential issues with word splitting or globbing, consider quoting the variables (e.g., "${AmplifyAppId}", "$BRANCH_NAME", "${AWS_REGION}") in the shell command.

Copilot uses AI. Check for mistakes.
@wrandall22
Copy link
Author

Is there anything else missing we could do to merge this one?

We have been using it in production for over a year with our fork. Haven't seen any issues with it that I'm aware of. We also made another change here later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants