aws-amplify / aws-amplify/amplify-cli
init --forcePush runs pre-push hooks before init
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
v16.20.0
### Amplify CLI Version
12.0.0
### What operating system are you using?
Linux
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made.
### Describe the bug
When amplify init is run with --forcePush the pre-push hook is run before init instead of before push.
### Expected behavior
I expect the pre-push hook to run consistently before a push to an initialized environment.
### Reproduction steps
1. Run the steps in https://github.com/aws-amplify/amplify-cli/issues/12644
2. Note during the branch build that the pre-push hook will run prior to a forced init/add of the environment.
### Project Identifier
_No response_
### Log output
```
# Put your logs below this line
```
### Additional information
I thought downgrading to <12 should fix the issue thinking it runs the hooks during the init and the push of a --forcePush per #12512 but that only applies to post-push hook.
The hooks might be somewhat correct/somewhat bugged in the instance of a init --forcePush because it's really two different actions: amplify env add + amplify push. init creates all the resources that normally would come with an amplify env add. I've seen that the [CLI populates different push parameters in a clean init --forcePush](https://github.com/aws-amplify/amplify-cli/issues/12640#issuecomment-1553059250). It wouldn't matter as much for people if the pre-push would run twice but it doesn't I guess. Moving the pre-push to post init would avoided situations where stuff like #12640 occurs, ie on the forcePush --init, the cloudformation name isn't know for the hook.
Now with #12512 in, I think pre-push hooks running during the adding of the env is a bug and they should run after the init/add of the env.
### Before submitting, please confirm:
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
Contributor guide
Research direction
Start by tracing the amplify init --forcePush command and its pre-push hook lifecycle, then compare it with the separate environment-add and push actions described in the issue. Use issues #12644, #12640, and #12512 for context; done means the pre-push hook runs at the intended point before a push to an initialized environment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100