cli
cli copied to clipboard
Add Windows build to Travis CI
Invoke Code Climate in its own shell script
We are adding Windows as a third OS to Travis CI, and the Code Climate reporter cannot run on Windows. With this extra consideration, the logic gets so complex that keeping it all in .travis.yml would make that file messy. The solution recommended by Travis is to spin it off into a separate shell script.
The shell script is formatted with shfmt and checked with shellcheck.
This refactoring came up with the Windows work, but I decided to make a separate PR about this. That way we get a clean PR and commit about this cross-platform part, and the Windows PR can be rebased on top of this stuff.
The shell script is called .travis-codeclimate.sh with a leading dot because .travis.yml also starts with a dot. Should it be called just travis-codeclimate.sh without a dot? Looks kind of ugly when it's invoked as ./.travis-codeclimate.sh.
It shouldn't bee that complex of a file. https://github.com/Unibeautify/beautifier-eslint/blob/master/.travis.yml
Removing all the error checking and clarifications (well, they were clarifications to me anyway 😄 ) it would look like this:
#!/bin/bash
os=$(uname | tr '[:upper:]' '[:lower:]')
[[ $os =~ (darwin|linux) ]] || exit 0
if [[ "$*" == before ]]; then
curl -L "https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${os}-amd64" >./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
else
./cc-test-reporter after-build --exit-code "$TRAVIS_TEST_RESULT"
fi
IMHO, no matter what you do in shell, it gets ugly when you go above 2-3 lines of code... That's why I would prefer to have it in a separate file. Your .travis.yml is not too bad but when it gets to the point that if-statements are added to YAML, I'd spin it out to a separate file. What's your opinion on that? I think no solution is ideal here.
I generally go by the number of lines and embedded if statements in deciding whether it's a mess or not (like the old atom-beautify Travis file).
Add Windows to this and I'll merge.
Thanks :) Maybe we should get a third opinion from @Glavin001. I took Windows into account - the line [[ $os =~ (darwin|linux) ]] || exit 0 exits right away if we are not on Mac or Linux. Should it be clarified?
windows should be added to the os list in .travis.yml though. The only things that should not happen for Windows is curl'ing the CodeClimate test reporter and reporting the results themselves (basically everything you have in .travis-codeclimate.sh.
Ah, you meant adding Windows to .travis.yml rather than the shell script. I thought I'd do that in the original Windows PR #95 and just spin off this one to do the Code Climate refactoring which is platform-independent.
We can, but you'll have to rebase and manually merge this PR locally anyways.
OK, rebased. The main reason I'd like to gather all the Windows porting work in the Windows PR is to keep the log of all errors encountered in one PR's discussion. Usually when you port to a new platform a bunch of unexpected problems come up...
Sorry I meant you'll have to rebase and manually merge after I merge #95. #95 build is failing still anyways.
Continuing from #95 which we considered too messy at this point.
Might have to adjust the Unibeautify config in the tests to not add a newline at the end, one of the tests looks for an \n as apart of the match, where in Windows it will be a CRLF.
Separately the Windows builds are still going even after ./.travis-codeclimate.sh after. Is it trying to send a test result to CodeClimate in the after script?
We could .replace("\r\n", "\n") in the test. But this would be a good time to think about how we encode the files in our repos. I guess we are using autocrlf in Git so the test fixture file gets CR LF (\r\n) newlines on Windows and LF (\n) newlines on Unix.
I don't see how it could be stuck in ./.travis-codeclimate.sh after since the Travis GUI shows a duration for that command (0.10 and 0.18 seconds in the two Windows builds - in the Linux build it takes 0.50 seconds). And it would have to cause some kind of error since it tries to use the codeclimate binary which it hasn't downloaded. But there's no clear explanation either.
We could just add a .gitattributes file like in ESLint.
Can you try adding conditions to not do CodeClimate scripts if it's on Windows just to see if that fixes the issue or not?
Trying .gitattributes. Hope it works :)
If this still hangs at the end, I'll try adding some debug code as you suggest.
Same problems as before... including the CRLF issue.
It doesn't seem to finish if there is an error. Let's remove newlines from the equation for that test: Update .unibeautifyrc.yml, BeautifyCommand.spec.ts and the snapshots. That seems to fix it.