Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify Pull Always Failed in Xcode Run Script #3332

Closed
2 tasks done
bevanchristian opened this issue Jul 9, 2023 · 16 comments
Closed
2 tasks done

Amplify Pull Always Failed in Xcode Run Script #3332

bevanchristian opened this issue Jul 9, 2023 · 16 comments
Labels
build Issues related to build and CI/CD pending-triage Issue is pending triage transferred This issue was transferred from another Amplify project

Comments

@bevanchristian
Copy link

bevanchristian commented Jul 9, 2023

How did you install the Amplify CLI?

curl -sL https://aws-amplify.github.io/amplify-cli/install | bash

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

v18.16.0

Amplify CLI Version

12.1.1

What operating system are you using?

Mac

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

no i use default model (todo)

Describe the bug

I have an Xcode project that will implement Amplify GraphQL, and I intend to pull the schema and regenerate the queries every time the application is built to obtain the latest schema. And this script works as desired when run in a regular terminal. However, when I run it as an Xcode run script, I always encounter errors. Here is the bash.script

And I found that the amplify pull command is causing the error, while the amplify codegen command runs normally when I comment out amplify pull.

set -e
cd ${PROJECT_DIR}
# Run Amplify commands
amplify="/Users/.amplify/bin/amplify"
IFS='|'

# Check if Amplify CLI is installed
if ! command -v "$amplify" &>/dev/null; then
    echo "Amplify CLI not found. Installing..."
    if ! curl -sL https://aws-amplify.github.io/amplify-cli/install | bash; then
        echo "Failed to install Amplify CLI."
    fi
else
    echo "Amplify CLI found."
fi


CODEGEN="{\
\"generateCode\":true,\
\"codeLanguage\":\"swift\",\
\”fileNamePattern\”:\”graphql/**/*.graphql\”,\
\"generatedFileName\":\"API\",\
\"generateDocs\":true\,
\”maxDepth\”:2\
}"

SWIFTCONFIG="{\
\"SourceDir\":\"src\",\
\"XcodeProject\":\"MyProject.xcodeproj\",\
\"BuildCommand\":\"xcodebuild\",\
\"StartCommand\":\"swift run\"\
}"

AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":false,\
\"profileName\":\"default\",\
\"accessKeyId\":\"xxxxx\",\
\"secretAccessKey\":\"xxxxxxxx+\",\
\"region\":\"us-east-1\"\
}"
AMPLIFY="{\
\"projectName\":\"xxxx\",\
\"appId\":\"xxxxx\",\
\"envName\":\"dev\",\
\"defaultEditor\":\"xcode\"\
}"

FRONTEND="{\
\"frontend\":\"ios\"
}"

PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"
# Run Amplify pull command
environment=""

# Set the environment based on the CONFIGURATION variable
if [ "$CONFIGURATION" == "Production" ]; then
  environment="dev"
  echo "Current environment: Production"
elif [ "$CONFIGURATION" == "Staging" ]; then
  environment="dev"
  echo "Current environment: Staging"
else
  environment="dev"
  echo "Invalid environment. Exiting."
  exit 1
fi


echo "Fetching changes from backend..."
"$amplify" pull \
  --yes \
  --debug \
  --restore \
  --amplify "$AMPLIFY" \
  --frontend "$FRONTEND" \
  --providers "$PROVIDERS"



# Check if Amplify pull succeeded
if [ $? -eq 0 ]; then
  echo "Amplify pull succeeded."
else
  echo "Amplify pull failed. Check the error logs for more information."
  exit 1
fi

# ReGenerate code model, schema, and query
"$amplify" codegen \
  --config "$CODEGEN" \
  --statements \
  --model \
  --yes

# Check if code generation succeeded
if [ $? -eq 0 ]; then
  echo "Code generation succeeded."
else
  echo "Code generation failed. Check the error logs for more information."
  exit 1
fi

echo "Amplify project configured for iOS."

This is the error
Screen Shot 2023-07-09 at 18 32 36

Expected behavior

  • amplify pull works pefectly fine in run script

Reproduction steps

  • add script to build phase, before compile sources
  • add this code
Screen Shot 2023-07-09 at 18 36 43
  • and build will failed

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@bevanchristian bevanchristian added the pending-triage Issue is pending triage label Jul 9, 2023
@josefaidt
Copy link

Hey @bevanchristian 👋 thanks for raising this! Are you able to capture the error by chance? From the screenshots it was aborted, but I'm unsure if that means it timed out and your editor running the script exited.

@josefaidt josefaidt added the pending-community-response Issue is pending response from the issue requestor label Jul 10, 2023
@josefaidt josefaidt self-assigned this Jul 10, 2023
@bevanchristian
Copy link
Author

bevanchristian commented Jul 11, 2023

Hi, thanks for the response @josefaidt . I've been facing this problem for 3 days and I'm not getting any error message. As for the timeout, it doesn't seem possible because the fetch is fast, less than 10 seconds. However, I've noticed something new. Every time I regenerate the files in generated/model, whether it's after running "amplify pull" or "amplify codegen model", my build gets aborted or stops.

i also add new script like this
"$amplify" pull 2> amplify_pull_error.log

Screen Shot 2023-07-11 at 10 14 32

Screen Shot 2023-07-11 at 10 15 00

Moreover, when I run just "amplify codegen model", I encounter the same error.

Screen Shot 2023-07-11 at 10 38 12

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Jul 11, 2023
@bevanchristian
Copy link
Author

if i run in terminal its perfectly fine, only on xcode script

@josefaidt
Copy link

Hey @bevanchristian thanks for clarifying! Since this seems to be particular to amplify codegen models I'm going to transfer this to our API repo for better support and tracking purposes

@josefaidt josefaidt added the transferred This issue was transferred from another Amplify project label Jul 13, 2023
@josefaidt josefaidt transferred this issue from aws-amplify/amplify-cli Jul 13, 2023
@josefaidt josefaidt removed their assignment Jul 13, 2023
@alharris-at alharris-at transferred this issue from aws-amplify/amplify-category-api Jul 13, 2023
@alharris-at
Copy link

@josefaidt I don't think this is related to codegen, the error being thrown seems to be due to a SIGINT being trapped by the CLI during execution, and invoking the sigIntHandler https://github.com/aws-amplify/amplify-cli/blob/a3b139fb36bcb2c1c890403e5bd754beec5b7ff7/packages/amplify-cli/src/index.ts#L192-L205 based on the last log line ^Aborted!. I think for some reason this build script is being interrupted at the end of execution.

@alharris-at alharris-at transferred this issue from aws-amplify/amplify-codegen Jul 13, 2023
@bevanchristian
Copy link
Author

So what should i do right now?

@josefaidt
Copy link

Hey @bevanchristian are you able to execute the same commands outside of XCode's terminal/script runner?

@josefaidt josefaidt added the pending-community-response Issue is pending response from the issue requestor label Jul 17, 2023
@bevanchristian
Copy link
Author

yes its perfectly fine if i run in terminal

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Jul 18, 2023
@josefaidt
Copy link

Hey @bevanchristian can you try removing the codegen command from the script? amplify pull should generate this for you automatically after the project is successfully pulled

# ReGenerate code model, schema, and query
"$amplify" codegen \
  --config "$CODEGEN" \
  --statements \
  --model \
  --yes

@josefaidt josefaidt added the pending-community-response Issue is pending response from the issue requestor label Jul 18, 2023
@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Jul 20, 2023
@bevanchristian
Copy link
Author

so i run this without that code you specify in xcode and i got this error

Screen Shot 2023-07-20 at 16 50 08

but when i run in terminal it work fine

Screen Shot 2023-07-20 at 16 52 47

this is my latest code

ulimit -t 120
echo "Fetch GrapQL Shema From Backend"
set -e
# Run Amplify commands
amplify="/Users/xxxx/.amplify/bin/amplify"
IFS='|'

# Check if Amplify CLI is installed
if ! command -v "$amplify" &>/dev/null; then
    echo "Amplify CLI not found. Installing..."
    if ! curl -sL https://aws-amplify.github.io/amplify-cli/install | bash; then
        echo "Failed to install Amplify CLI."
    fi
else
    echo "Amplify CLI found."
fi


# Run Amplify pull command
environment="dev"

# Set the environment based on the CONFIGURATION variable
if [ $# -eq 1 ]; then
  environment="$1"
fi

CODEGEN="{\
\"generateCode\":true,\
\"codeLanguage\":\"swift\",\
\”fileNamePattern\”:\”graphql/**/*.graphql\”,\
\"generatedFileName\":\"API\",\
\"generateDocs\":true\,
\”maxDepth\”:2\
}"

AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":false,\
\"profileName\":\"default\",\
\"accessKeyId\":\"xxxx\",\
\"secretAccessKey\":\"xxxx\",\
\"region\":\"us-east-1\"\
}"

AMPLIFY="{\
\"projectName\":\"xxx\",\
\"appId\":\"xxxx\",\
\"envName\":\"$environment\",\
\"defaultEditor\":\"Xcode\"\
}"

FRONTEND="{\
\"frontend\":\"ios\"
}"

PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"


echo "Fetching changes from backend..."
"$amplify" pull \
  --envName "$environment" \
  --amplify "$AMPLIFY" \
  --frontend "$FRONTEND" \
  --providers "$PROVIDERS" \
  --yes \
  --debug


echo "Codegen model"
# ReGenerate code model, schema, and query
"$amplify" codegen model


@josefaidt
Copy link

Hey @bevanchristian upon further investigation there is an XCode-specific Amplify script that will execute behind the scenes when you run amplify commands in an XCode project. This script will update project files, and I believe it is clashing with the amplify commands executed from within your script that is then run by XCode.

For the mean time, please run this script outside of XCode. What is the workflow or use case you're looking to accomplish?

@josefaidt josefaidt added the pending-community-response Issue is pending response from the issue requestor label Jul 24, 2023
@bevanchristian
Copy link
Author

oh i see, ok then i'll move the script out of the xcode run script. The workflow that I want is the same as Apollo GraphQL, where every time we build XCode, the schema will be automatically fetched. it would be great if amplify could implement an automatic schema fetch without having to manually type in the command line.

the main reason is because I work with a large team, and each team handles certain features. and it would be a difficult if they had to learn the command line amplify so that the schema was generated, because I entered some of the folders into gitignore. btw thanks for the investigation @josefaidt

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Jul 25, 2023
@josefaidt
Copy link

Hey @bevanchristian out of curiosity what version of XCode are you currently using?

@josefaidt josefaidt added the pending-community-response Issue is pending response from the issue requestor label Jul 25, 2023
@bevanchristian
Copy link
Author

i use xcode 14.2 @josefaidt

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Jul 27, 2023
@josefaidt
Copy link

Hey @bevanchristian apologies for the delay, but I'm going to transfer this over to our Amplify Swift repo for better assistance with debugging the Amplify CLI + XCode issue

@josefaidt josefaidt transferred this issue from aws-amplify/amplify-cli Oct 26, 2023
@phantumcode phantumcode added the build Issues related to build and CI/CD label Oct 27, 2023
@phantumcode
Copy link
Contributor

@bevanchristian Are you able to unblock yourself once your script is moved out of the Xcode build phase?

@phantumcode phantumcode added the pending-community-response Issue is pending response from the issue requestor label Oct 27, 2023
@atierian atierian added the closing soon This issue will be closed in 7 days unless further comments are made. label Dec 6, 2023
@github-actions github-actions bot removed pending-community-response Issue is pending response from the issue requestor closing soon This issue will be closed in 7 days unless further comments are made. labels Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues related to build and CI/CD pending-triage Issue is pending triage transferred This issue was transferred from another Amplify project
Projects
None yet
Development

No branches or pull requests

5 participants