cli icon indicating copy to clipboard operation
cli copied to clipboard

Add Windows build to Travis CI

Open lassik opened this issue 7 years ago • 19 comments

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.

lassik avatar Oct 24 '18 08:10 lassik

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.

lassik avatar Oct 24 '18 08:10 lassik

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.

lassik avatar Oct 24 '18 09:10 lassik

It shouldn't bee that complex of a file. https://github.com/Unibeautify/beautifier-eslint/blob/master/.travis.yml

stevenzeck avatar Oct 24 '18 19:10 stevenzeck

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.

lassik avatar Oct 24 '18 19:10 lassik

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).

stevenzeck avatar Oct 25 '18 19:10 stevenzeck

Add Windows to this and I'll merge.

stevenzeck avatar Oct 25 '18 23:10 stevenzeck

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?

lassik avatar Oct 26 '18 12:10 lassik

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.

stevenzeck avatar Oct 26 '18 21:10 stevenzeck

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.

lassik avatar Oct 26 '18 21:10 lassik

We can, but you'll have to rebase and manually merge this PR locally anyways.

stevenzeck avatar Oct 26 '18 21:10 stevenzeck

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...

lassik avatar Oct 26 '18 21:10 lassik

Sorry I meant you'll have to rebase and manually merge after I merge #95. #95 build is failing still anyways.

stevenzeck avatar Oct 26 '18 21:10 stevenzeck

Continuing from #95 which we considered too messy at this point.

lassik avatar Oct 26 '18 22:10 lassik

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?

stevenzeck avatar Oct 26 '18 22:10 stevenzeck

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.

lassik avatar Oct 27 '18 07:10 lassik

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?

stevenzeck avatar Oct 27 '18 17:10 stevenzeck

Trying .gitattributes. Hope it works :)

If this still hangs at the end, I'll try adding some debug code as you suggest.

lassik avatar Oct 28 '18 07:10 lassik

Same problems as before... including the CRLF issue.

lassik avatar Oct 28 '18 13:10 lassik

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.

stevenzeck avatar Oct 29 '18 17:10 stevenzeck