aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
452 stars 113 forks source link

cancelled - no diff detected from previous commit #973

Closed CurtisHumphrey closed 3 years ago

CurtisHumphrey commented 4 years ago

Please describe which feature you have a question about? When doing automatic branch building from a GitHub repo sometimes we get this message "cancelled - no diff detected from previous commit"

Provide additional details We think it is related to our mono repo structure. Sometimes we do not change anything directly in the AppSync package folder but the related lambda's that are in other package folders that we also build via Amplify's CD pipeline.

amplify.yml

version: 1
applications:
  - appRoot: packages/hr_api
    backend:
      phases:
        preBuild:
          commands:
            - COMMIT_MESSAGE=$(git log -1 --pretty=%B | cat)
            - if [ "${AWS_BRANCH}" = "master" ] && [[ $COMMIT_MESSAGE != chore\(release\):* ]]; then echo "a non release commit on master" && exit 1; fi;
            - yarn install
        build:
          commands:
            - yarn run use_real_graphql
            - amplifyPush --simple
            - export sls_stage=$(echo $AWS_BACKEND_ENVIRONMENT_ARN | cut -d '/' -f 4)
            - export sls_version=$(yarn run sls --version | grep 'Framework Core' | cut -d ' ' -f 3)
            - if [ "${AWS_BRANCH}" = "master" ]; then export sls_logRetentionInDays=400; else export sls_logRetentionInDays=14; fi;
            - export appsync_graphqlEndpoint=$(cat src/aws-exports.js | grep aws_appsync_graphqlEndpoint | cut -d \" -f 4)
            - export appsync_user_pools_id=$(cat src/aws-exports.js | grep aws_user_pools_id | cut -d \" -f 4)
            - export appsync_user_pools_web_client_id=$(cat src/aws-exports.js | grep aws_user_pools_web_client_id | cut -d \" -f 4)
            - yarn workspace ceridian_functions run deploy
            - yarn workspace qualtrics_functions run deploy
        cache:
          paths:
            - ../../node_modules/**/*
            - ~/.cache/yarn/**/*
    frontend:
      phases:
        preBuild:
          commands: []
        build:
          commands: []
      artifacts:
        baseDirectory: /publish
        files:
          - '**/*'
      cache:
        paths: []
cslogan-red commented 4 years ago

Thanks for reporting @CurtisHumphrey , this is correct in that monorepo support currently checks to see if there are any git differences for the provided appRoot folder and the previous commit to avoid triggering builds for other appRoot's tied to the same monorepo...this functionality does not currently support detecting differences in nested monorepo child folders, in order to trigger a commit for that monorepo appRoot at present, you would need to push a commit at the root level when the nested folder contents change. I've added this to our backlog as a feature request for prioritization.

ijunaid8989 commented 4 years ago

@CurtisHumphrey is it possible to use commit message further to do something?

I have this file

version: 0.1
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn build
        - yarn export
    postBuild:
        commands:
        - COMMIT_MESSAGE=$(git log -1 --pretty=%B | cat)
        - "curl -s --user 'api:key-' https://api.mailgun.net/v3/evercam.io/messages -F from='noreply <support@evercam.io>' -F to=junaid@evercam.io -F subject='Evercam Admin New Deploy'  --form-string html='<html>Branch '${AWS_BRANCH}'<br/> Commit '${COMMIT_MESSAGE}' </html>'"
  artifacts:
    baseDirectory: /dist
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

I want to use commit message to send an email. but right now email is being sent but only the first word of commit message and then it fails, email still sent but with only the first word of the commit message.

jwoehrle commented 4 years ago

when using the monorepo approach this also happens when the amplify.yml is changed in the root of the project folder. I'd consider changing the amplify.yml an event which should trigger the build. What do you think?

CurtisHumphrey commented 3 years ago

I have this code that runs on a pre-commit hook so that on every change a file in the monorepo package for appsync is changed so that all pushes cause a rebuilding. Would be better to have a flag in the CI/CD tool but this works.

const path = require('path')
const fs = require('fs')

const parts = require('child_process').execSync('git describe --tags --long').toString().split('-')
const tag = parts[0][0] === 'v' ? parts[0].slice(1) : parts[0]
const since_tag = parts[1][0]

fs.writeFileSync(
  path.join(__dirname, 'packages/hr_api/VERSION.md'),
  `version is ${tag}-${since_tag} at ${new Date().toUTCString()}`,
)
cslogan-red commented 3 years ago

@CurtisHumphrey @jwoehrle @ijunaid8989 We've updated the (previously not very accurate) diff logic that was running only for monorepo apps to be opt-in by default so that it doesn't block your builds if it fails to detect changes.

If you'd like to enable diffing for your frontend build, test, and deploy (regardless of whether your app uses a monorepo or not), you can now optionally set the AMPLIFY_DIFF_DEPLOY environment variable to true, and it will run a diff on your monorepo's appRoot by default, if there are no changes in the most recent commit in this folder (or any nested sub-folder or file of your appRoot), the frontend build, test, and deploy steps will be skipped. (We have a fast-follow already coming shortly on this that supports diffing all commits since your most recent deploy for changes instead of just the most recent commit) Again, to keep the diff logic non-blocking, it is now opt-in via this environment variable, and you can remove the variable or set its value to false to bypass the diff logic at any time. See more details in the docs.

Closing issue as diff is now opt-in by default, overridable via env variable, and when enabled, supports detecting changes in nested files and folders of your appRoot.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.