Skip to content
New issue

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

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

Already on GitHub? # to your account

[TRAVIS] EZEE-2236: Retry installation after Composer failure #2404

Merged
merged 1 commit into from
Aug 21, 2018
Merged

[TRAVIS] EZEE-2236: Retry installation after Composer failure #2404

merged 1 commit into from
Aug 21, 2018

Conversation

mnocon
Copy link
Member

@mnocon mnocon commented Jul 26, 2018

Question Answer
JIRA issue Done as part of https://jira.ez.no/browse/EZEE-2236
Bug/Improvement CI improvment
New feature no
Target version 6.7, 6.13, 7.2, master
BC breaks no
Tests pass no
Doc needed no

Sometimes composer install fails because of network connection problems, for example:

```[37;41m                                                                               [39;49m
[37;41m  [Composer\Downloader\TransportException]                                     [39;49m
[37;41m  The "http://packagist.org/p/ezsystems/ezpublish%24668516c3c81fe7235019645bb  [39;49m
[37;41m  ea5df277a1823a31351e9a2b6dd701bbfbb404e.json" file could not be downloaded   [39;49m
[37;41m  (HTTP/1.1 404 Not Found)                                                     [39;49m
[37;41m                                                                               [39;49m```

Adding travis_retry should help avoid this (and improve stability).

TODO:

  • Implement feature / fix a bug.
  • Ask for Code Review.

@mnocon mnocon requested a review from alongosz July 26, 2018 08:30
@mnocon mnocon changed the title [WIP] [TRAVIS] EZEE-2236: Retry installation after Composer failure [TRAVIS] EZEE-2236: Retry installation after Composer failure Jul 26, 2018
.travis.yml Outdated
@@ -67,7 +67,7 @@ before_script:
- if [ "$REDIS_ENABLE_IGBINARY" = true ] ; then pecl install igbinary ; fi
- if [ "$REDIS_ENABLE_LZF" = true ] ; then printf "no\n" | pecl install lzf ; fi
# Prepare system
- if [ "$TEST_CONFIG" != "" ] ; then ./bin/.travis/prepare_unittest.sh ; fi
- if [ "$TEST_CONFIG" != "" ] ; then travis_retry ./bin/.travis/prepare_unittest.sh ; fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is going to work? It depends on script return code, and prepare_unittest.sh will always return 0, even if there are errors in subcommands. Error code from subcommand is not propagated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I forgot about the "exit code is the code of last executed command" bit 😞

As I see it, there are two options here:

  1. use set -e in prepare_unittest.sh
  2. check the return value of each composer command and exit with it if it's non-0.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUT, several things in that script should ideally not be done several times. So this might cause some super strange issues down the line...

@alongosz alongosz requested a review from andrerom July 27, 2018 11:25
@alongosz
Copy link
Member

BUT, several things in that script should ideally not be done several times. So this might cause some super strange issues down the line...

That's a good point. So we should use it directly for composer install/update

@mnocon investigated it further and it looks like we cannot use travis_retry inside a script.

I think we need to refactor prepare_unittest.sh and move composer install/update outside, directly to install section of .travis.yml. Then we would be able to use travis_retry.

@mnocon
Copy link
Member Author

mnocon commented Jul 27, 2018

Good catch Andre, I haven't thought about it.

I'll try the travis_retry inside the script approach (my knowledge is based on https://twitter.com/plexus/status/499194992632811520 - I haven't found anything about both supporting and not supporting it in scripts in official doc, so it's fastest way to check).

If it fails I will do the refactoring with moving the composer bits (and the ones after it) into the .travis.yml file.

@mnocon mnocon changed the title [TRAVIS] EZEE-2236: Retry installation after Composer failure [WIP] [TRAVIS] EZEE-2236: Retry installation after Composer failure Jul 27, 2018
@andrerom
Copy link
Contributor

andrerom commented Jul 30, 2018

I can confirm it does not work inside scripts like @alongosz says, might be a way, but I'm in favor of refactoring it to do it outside, slight problem becomes the install vs update problem, but if we are sure we never have a lock (script can remove it if it is there in case update is needed for instance) then we can always run install.

@andrerom andrerom removed their request for review July 31, 2018 12:56
@mnocon
Copy link
Member Author

mnocon commented Aug 6, 2018

@alongosz I've pushed another changes. I've decided to add the travis_retry function and use it directly in the script.

I know we've talked about extracting the composer parts - I tried this approach and I didn't like it.

This approach is much clearer IMHO - the whole logic of setting up unit tests is still in one place. Script prepare_unittest sets two variables: COMPOSER_UPDATE and COMPOSER_ROOT_VERSION, which are not available in .travis.yml. I'd have to copy the logic from the script to the Travis file to determine their value again (all of this must be combined together with conditions that make sure we're setting unit tests, not running Behat), it's not readable to me.

I feel like extracting it just for the purpose of using travis_retry is an overkill (maybe there are other reasons to refactor, but I'm not seeing them) and this new approach is better.

What do you think?

@mnocon mnocon changed the title [WIP] [TRAVIS] EZEE-2236: Retry installation after Composer failure [TRAVIS] EZEE-2236: Retry installation after Composer failure Aug 6, 2018
Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to maintain travis_retry ;)

Current changes with more logic moved to .travis.yml, while maybe make it a little bit "packed", but seem to me like a good approach.

@mnocon
Copy link
Member Author

mnocon commented Aug 17, 2018

@alongosz do you think we can merge this one? We've decided to wait because of temporary Travis issues, but it's green now

@alongosz
Copy link
Member

Fine by me. Final review ping @andrerom

Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides nitpic on possible simpliciation, +1

.travis.yml Outdated
@@ -74,6 +74,14 @@ before_script:
- TEST_TIMEZONES=("America/New_York" "Asia/Calcutta" "UTC")
- TEST_TIMEZONE=${TEST_TIMEZONES["`shuf -i 0-2 -n 1`"]}

install:
# Because of either some changes in travis, composer or git, composer is not able to pick version for "self" on inclusion of solr anymore, so we force it:
- if [ "$TEST_CONFIG" != "" ] ; then export COMPOSER_ROOT_VERSION=`php -r 'echo json_decode(file_get_contents("./composer.json"), true)["extra"]["branch-alias"]["dev-tmp_ci_branch"];'` ; fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try without this?
Afaik this has since been resolved, so cool if you can try removing those two lines in a commit and see if all jobs still pass.

@mnocon
Copy link
Member Author

mnocon commented Aug 20, 2018

Thanks @andrerom , it works without it 🎉
I've squashed all commits into one, as it became a mess over time.

Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks even better!

@andrerom andrerom merged commit 0a350a3 into ezsystems:6.7 Aug 21, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants