From 490df640b47cb252636a9476552d7ecea01a11e7 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Tue, 25 May 2021 07:10:16 +0530 Subject: Skip building in the 'script' stage of travis if no changes found. --- .travis.yml | 60 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to '.travis.yml') diff --git a/.travis.yml b/.travis.yml index ae29f3b4c..aefeedfc7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,42 +45,56 @@ before_install: git remote add source https://${GH_TOKEN}@github.com/getferdi/ferdi.git > /dev/null 2>&1 git fetch source git merge --no-ff --commit -m "Merge remote-tracking branch 'source/develop' into HEAD [skip ci]" source/develop - CHANGES_COUNT=$(git diff --stat HEAD origin/nightly | wc -l) + CHANGES_COUNT=$(git diff --shortstat HEAD origin/$TRAVIS_BRANCH | wc -l) echo "Travis event type: $TRAVIS_EVENT_TYPE" echo "Number of changes: $CHANGES_COUNT" if [ $CHANGES_COUNT -eq 0 -a $TRAVIS_EVENT_TYPE == "cron" ]; then - echo "Terminating the build since there are no changes in a cron-triggered build" - travis_terminate 0 + export SHOULD_CONTINUE_BUILD="false" + echo "Exporting SHOULD_CONTINUE_BUILD to false for future stages" else echo "Found changes, proceeding with submodule updates" git submodule update --remote --force - git commit -am "Update submodules [skip ci]" --no-verify || true + git commit -am "Update submodules [skip ci]" --no-verify + echo "Completed merging from develop branch and upgrading submodules" fi - echo "Completed merging from develop branch and upgrading submodules" fi install: - - travis_retry npm cache clean -f || travis_terminate 1 - - travis_retry npm uninstall node-gyp || travis_terminate 1 - - travis_retry npm i -g node-gyp@8.0.0 || travis_terminate 1 - - cd recipes && npm i && npm run package && cd .. || travis_terminate 1 - - travis_retry npx lerna bootstrap || travis_terminate 1 + - | + if [ "$SHOULD_CONTINUE_BUILD" == "false" ]; then + echo "Skipping install stage since SHOULD_CONTINUE_BUILD: $SHOULD_CONTINUE_BUILD" + else + travis_retry npm cache clean -f || travis_terminate 1 + travis_retry npm uninstall node-gyp || travis_terminate 1 + travis_retry npm i -g node-gyp@8.0.0 || travis_terminate 1 + cd recipes && npm i && npm run package && cd .. || travis_terminate 1 + travis_retry npx lerna bootstrap || travis_terminate 1 + fi before_script: - - npm run lint && npm run test || travis_terminate 1 + - | + if [ "$SHOULD_CONTINUE_BUILD" == "false" ]; then + echo "Skipping before_script stage since SHOULD_CONTINUE_BUILD: $SHOULD_CONTINUE_BUILD" + else + npm run lint && npm run test || travis_terminate 1 + fi script: - | - echo "Building for branch: $TRAVIS_BRANCH" - if [ $TRAVIS_BRANCH == "release" ]; then - travis_retry travis_wait 100 npm run build -- --publish always -c.publish.provider=github -c.publish.owner=getferdi -c.publish.repo=ferdi -c.mac.identity=null || travis_terminate 1 - elif [ $TRAVIS_BRANCH == "nightly" ]; then - git commit -am "Apply linter fixes [skip ci]" --no-verify - npm version prerelease --preid=nightly -m "%s and trigger AppVeyor nightly build [skip travisci]" || travis_terminate 1 - if [ $TRAVIS_OS_NAME == "osx" ]; then - git remote add nightly https://${GH_TOKEN}@github.com/getferdi/ferdi.git > /dev/null 2>&1 - git push -qu nightly HEAD:nightly --no-verify >/dev/null 2>&1 - fi - travis_retry travis_wait 100 npm run build -- --publish always -c.publish.provider=github -c.publish.owner=getferdi -c.publish.repo=nightlies || travis_terminate 1 + if [ "$SHOULD_CONTINUE_BUILD" == "false" ]; then + echo "Terminating the build since there are no changes in a cron-triggered build" + travis_terminate 0 + exit 0 # Note: Bug fix since 'travis_terminate' doesn't seem to exit immediately else - if [ $TRAVIS_PULL_REQUEST_BRANCH != "i18n" ]; then + echo "Building for branch: $TRAVIS_BRANCH" + if [ $TRAVIS_BRANCH == "release" ]; then + travis_retry travis_wait 100 npm run build -- --publish always -c.publish.provider=github -c.publish.owner=getferdi -c.publish.repo=ferdi -c.mac.identity=null || travis_terminate 1 + elif [ $TRAVIS_BRANCH == "nightly" ]; then + git commit -am "Apply linter fixes [skip ci]" --no-verify + npm version prerelease --preid=nightly -m "%s and trigger AppVeyor nightly build [skip travisci]" || travis_terminate 1 + if [ $TRAVIS_OS_NAME == "osx" ]; then + git remote add source https://${GH_TOKEN}@github.com/getferdi/ferdi.git > /dev/null 2>&1 + git push -qu source HEAD:$TRAVIS_BRANCH --no-verify >/dev/null 2>&1 + fi + travis_retry travis_wait 100 npm run build -- --publish always -c.publish.provider=github -c.publish.owner=getferdi -c.publish.repo=nightlies || travis_terminate 1 + elif [ $TRAVIS_PULL_REQUEST_BRANCH != "i18n" ]; then travis_retry travis_wait 100 npm run build || travis_terminate 1 fi fi -- cgit v1.2.3-70-g09d2