aws-amplify / aws-amplify/amplify-hosting

CI backend build continues after pre-push hook fails

Open
#2,938 3 comments 0 reactions 0 assignees View on GitHub
backend-builds
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-cli/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-cli/blob/dev/CONTRIBUTING.md#bug-reports).
- [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.

### How did you install the Amplify CLI?

_No response_

### If applicable, what version of Node.js are you using?

_No response_

### Amplify CLI Version

9.2.1

### What operating system are you using?

CI Build

### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

### Amplify Categories

hosting

### Amplify Commands

push

### Describe the bug

I have a pre-push hook setup to do some pre-building for the lambda functions.

In the CLI, if the pre-push hook fails then the push aborts. In the CI build, it continues and then falls over later because the pre-building failed.

### Expected behavior

The CI build should abort if the pre-push hook exits with a non-zero error code.

### Reproduction steps

Add a `pre-push.sh` file to `amplify/hooks/` with the code
```bash
#!/bin/bash

# **** SETUP ****
# exit when any command fails
set -e
# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT

ls random
```

### GraphQL schema(s)

_No response_

### Project Identifier

_No response_

### Log output

```
2022-08-18T15:08:01.009Z [WARNING]: ✔ Successfully pulled backend environment dev from the cloud.
2022-08-18T15:08:01.120Z [INFO]: ✅
2022-08-18T15:08:02.420Z [INFO]:
2022-08-18T15:08:02.420Z [INFO]: ----- 🪝 pre-push execution start -----
2022-08-18T15:08:02.596Z [INFO]: > @x@0.0.1 build function
> ./build.sh
2022-08-18T15:08:02.602Z [INFO]: "ls random" command filed with exit code 2.
2022-08-18T15:08:02.617Z [INFO]: ----- 🪝 pre-push execution end -----

...

2022-08-18T15:08:10.227Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
2022-08-18T15:08:10.229Z [WARNING]: ✖ There was an error initializing your environment.
2022-08-18T15:08:10.232Z [INFO]: [0m[Error: ENOENT: no such file or directory, lstat '...'] {
errno: -2,
code: 'ENOENT',
syscall: 'lstat',
path: '...'
2022-08-18T15:08:10.250Z [ERROR]: !!! Build failed

```

### Additional information

Sorry in advance if there is a specific repo for CI build issues.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with the described amplify/hooks/pre-push.sh script and compare how the CLI and CI build handle its exit status. Trace the CI hook execution around the logged pre-push start and end messages; done means a non-zero hook exit aborts the CI build before the later resource-push error.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, git
Domain
ci-cd, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.