-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shellcheck to the build #3476
Conversation
.travis.yml
Outdated
@@ -49,4 +46,4 @@ notifications: | |||
- https://webhooks.gitter.im/e/1ac7fc698195981a9227 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but we don't use gitter anymore. We can probably shut this down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the whole section as it looked like it was only for gitter.
.travis/before_script.sh
Outdated
|
||
export CMAKE_FLAGS="-DWANT_QT5=$QT5 -DUSE_WERROR=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo" | ||
|
||
if [ -z "$TRAVIS_TAG" ]; then export CMAKE_FLAGS="$CMAKE_FLAGS -DUSE_CCACHE=ON"; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was likely kept a one-liner to keep the .yml
clean reading. Please break this out now that it's in a shell script. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.travis/install.sh
Outdated
#!/usr/bin/env bash | ||
|
||
if [ "$TYPE" = 'style' ]; then | ||
sudo apt install shellcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be apt-get
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the debian admin. handbook:
APT is a vast project, whose original plans included a graphical interface. It is based on a library which contains the core application, and apt-get is the first front end — command-line based — which was developed within the project. apt is a second command-line based front end provided by APT which overcomes some design mistakes of apt-get.
IMHO using apt
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. We use apt-get
everywhere else, let's use that for consistency. If there turns out to be advantages using apt
over apt-get
, we'll switch the whole project to use it in a separate task (wiki, travis, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Would it make more sense to force this as a Linux-environment run? In the current state, it's assuming items like |
It's taking the default from |
Fair enough, but these should still only live in the linux scripts and you can just add another block to the apt-get logic rather than segmenting them which also addresses https://github.com/LMMS/lmms/pull/3476/files#r109296139. |
Moving them to the Linux scripts may also benefit us if some of these tools shift from Linux to homebrew, etc as history has proven sometimes Homebrew has newer versions of packages which would change |
So, you wan't me only to merge the
When I click here, I only get a diff. Not sure what you're talking about here.
I don't understand sorry. Why adding them to linux would help if one day there's a more up to date homebrew version ? |
I thought of that too. I think it's fine. That way all CI platforms can have the formatting if needed. It's more granular.
The
I realized that and had edited my post. :) The point was if a utility that we're using for style or code quality is dated, often the Homebrew environment will get the bleeding edge first. This has happened time and time again (Qt5, GigPlayer, etc) so having
It got squashed out. Was the |
Sorry, I don't understand what you mean. But, what would you all the CI platforms to have the formatting ? And I don't understand what you want me to do.
Because now, shellcheck is going to check those files. In My point is really that we have - os: osx
env: TYPE=style And just edit the |
I think the The other points make sense and you're right they should stay for now. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some improvements.
.travis.yml
Outdated
@@ -18,17 +19,13 @@ matrix: | |||
- os: osx | |||
env: QT5=True | |||
before_install: | |||
- . ${TRAVIS_BUILD_DIR}/.travis/${TRAVIS_OS_NAME}.${TARGET_OS}.before_install.sh | |||
- . ${TRAVIS_BUILD_DIR}/.travis/before_install.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should try to remove all this sourcing and use single lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by use single lines
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
install: ${TRAVIS_BUILD_DIR}/.travis/install.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't work, have to do a chmod or call bash directly. So, here, I choosed to do: bash file
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will work if you set execute permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep', so if you want it to fit in a single line I'll have to do something like: chmod +x files && file
, here, using bash file
looked better to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how to set permissions in the repository or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, just did it. I didn't know it was possible to do this with git.
.travis/before_install.sh
Outdated
|
||
if [ "$TYPE" != 'style' ]; then | ||
# shellcheck disable=SC1090 | ||
. "$TRAVIS_BUILD_DIR/.travis/$TRAVIS_OS_NAME.$TARGET_OS.before_install.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind indenting with tabs, such as in .travis/linux..install.sh
?
You should try to remove sourcing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done for the indenting part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you want me to remove sourcing ? I could do:
chmod +x file && ./file
or bash file
, no idea what's best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should set permissions in the repository, like cmake/build_mingw32.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you meant, so I just did a chmod.
.travis/before_script.sh
Outdated
if [ -z "$TRAVIS_TAG" ]; then | ||
export CMAKE_FLAGS="$CMAKE_FLAGS -DUSE_CCACHE=ON" | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should merge this script with .travis/script.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.travis.yml
Outdated
- . ${TRAVIS_BUILD_DIR}/.travis/${TRAVIS_OS_NAME}.${TARGET_OS}.script.sh | ||
- make -j4 | ||
- if [[ $TARGET_OS != win* ]]; then make tests && ./tests/tests; fi; | ||
- . ${TRAVIS_BUILD_DIR}/.travis/script.sh | ||
after_script: | ||
- ccache -s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move this command to .travis/script.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you shouldn't. Moving it to script
will cause it to affect the build result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving it to
script
will cause it to affect the build result.
I am assuming @zapashcanon will drop sourcing and act accordingly. ccache -s
prints a statistics summary, are you worried that ccache
may fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how sourcing relates to this.
are you worried that ccache may fail?
If it fails, I don't want our CI to fail because of that, obviously.
Regardless, it doesn't belong in script
because it's not part of our tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zapashcanon, you should move this command to .travis/after_script.sh
and execute ccache
when appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By appropriate, you mean not when running the style
build right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so. If ShellCheck does not compile, then ccache
makes no sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little bit useless to me. ccache
indeed makes no sense, but it'll just print: "nothing changed" and it's done. Is it worth to add a ~10 lines script when keeping it in one line is the same ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If ccache -s
output is irrelevant, then you should not run ccache -s
. By ~10 lines, do you mean 2? No matter how many lines, it is worth because ShellCheck will check the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.travis/before_install.sh
Outdated
if [ "$TYPE" != 'style' ]; then | ||
# shellcheck disable=SC1090 | ||
. "$TRAVIS_BUILD_DIR/.travis/$TRAVIS_OS_NAME.$TARGET_OS.before_install.sh" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may merge this script with .travis/install.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.travis/script.sh
Outdated
if [[ $TARGET_OS != win* ]]; then | ||
|
||
make tests | ||
./tests/tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the dot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, that's how it was before in travis.yml
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Plain tests/tests
should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@jasp00, some of your comments are now on outdated code but not fixed. Just to make sure you don't miss my comments. |
@zapashcanon the |
@tresf setting this flag seems interesting. Do you want me to do it ? Otherwise, I'd like this to get merged so I can start adding things to the style job. |
Please, set the flag and drop |
@zapashcanon thanks. I know some of these things seem mundane, but it makes the feature cleaner as a whole and sets a good example (such as the execute flag). Thanks for the patience with this. |
.travis/install.sh
Outdated
sudo apt-get -yqq update | ||
sudo apt-get install shellcheck | ||
else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but there seem to be some additional newlines in this else
block as well as the the if [ ]
block in the after_script.sh
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@tresf, it's ok, I understand. I'm even glad to know now that git is able to handle permissions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further improvements.
@@ -0,0 +1,9 @@ | |||
#!/usr/bin/env bash | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add set -e
to all scripts except after_script.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why I shouldn't add it into after_script.sh
. If after_script.sh
returns a non-0 exit code, Travis won't say the build failed. That's exactly the purpose of the after_script
in the .yml
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't hurt in after_script
but to @jasp00's point, the ccache
statistics aren't really critical for a pass/fail and it's a single-line, so set -e
on the whole script hasn't yet been warranted over something like exit $?
. But @zapashcanon you're right, it's best to add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see after_script
, it is useful for statistics, non-critical tests, custom notifications (not webhooks), dumps, etc. You probably want to run all of them, so set -e
is not convenient. Right now, it does not matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add set -e
to linux..before_install.sh
, linux.win32.before_install.sh
, linux.win32.install.sh
, etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did it.
.travis/script.sh
Outdated
|
||
else | ||
|
||
mkdir build && cd build || exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use simple commands and drop exit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkdir build && cd build
was here before in the .yml
. I added the exit but with set -e
it's useless now.
@zapashcanon Homebrew seems to be picky about the install command. If a package is already installed, it returns a non-zero code and bombs out the script. This is now exposed by I'd recommend we keep the package listing incase we need to invoke this from another build system and make it variable. # skip preinstalled packages
if ! "${TRAVIS}"; then
PACKAGES="$PACKAGES cmake pkgconfig node"
fi Alternately, I believe |
@tresf, I tried something else, which seems better to me. Currrently not working, but I'll fix it tomorrow. Do you agree with the idea ? I'm getting the list of already installed packages from Moreover, there's this error too: |
Absolutely. This is what I find recommended most places. It could even be extended to install them one-by-one and remove the bleeding $FOO, which would probably make @jasp00 happy.
It's simply the first already-installed package... Yet another side-effect of |
I thought about that, but I was afraid it would make the installation process longer. |
It shouldn't. |
I was wrong @zapashcanon... it does make a difference. Here's my benchmarking
Probably best to build out the string in this case. |
@tresf, I replaced Now it fails on: |
@zapashcanon the git command should be valid, it just gets the current branch name. Custom homebrew formulas are hosted I'm guessing the script just doesn't know where the git repository is. Can you try something like |
I tried I'm not sure the command is valid, see this. Looks like we're in a detached HEAD state, no ? I don't know how travis get the git repo. etc. |
Travis build log:
|
@zapashcanon it appears weren't not the only ones wanting this. Can we add a fallback to use Back on topic... here's the Travis-CI documentation around the branch name: |
Ok, so, from the latest test: pwd:
/Users/travis/build/LMMS/lmms
url=https://github.com/LMMS/lmms.git
git branch:
* (HEAD detached at FETCH_HEAD)
master
git status:
HEAD detached at FETCH_HEAD
nothing to commit, working tree clean
fatal: ref HEAD is not a symbolic ref So I could do something like: if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
branch="master"
else
branch=$(git symbolic-ref --short HEAD)
fi But it won't work for PR to |
I think we're on the same page. It is paramount we know the branch name. If it becomes too much of a struggle we can research how Homebrew does local |
@tresf, it works now, it's a bit hacky but it should do the trick. |
That's perfect. |
So, do you see anything left to do before merging ? |
@zapashcanon I found a script that we missed... I'm not sure how well |
@tresf, I fixed everything except one thing which seems strange to me. We have: STK_RAWWAVE=$HOME/stk-*/rawwaves
if [ ! -d "$STK_RAWWAVE" ]; then
STK_RAWWAVE=$(brew --prefix stk)/share/stk/rawwaves
fi Shellcheck doesn't like that. What's the STK_RAWWAVE_LIST=( $HOME/stk-*/rawwaves )
STK_RAWWAVE=${STK_RAWWAVE_LIST[0]}
if [ ! -d "$STK_RAWWAVE" ]; then
STK_RAWWAVE=$(brew --prefix stk)/share/stk/rawwaves
fi But I don't know what's this code and I probably can't test it so... |
@zapashcanon your assumptions are exactly correct. The purpose is a bit more vague... perhaps it could benefit from a comment but the raw waves must be copied at bundle time and at the time of writing that script, MacPorts didn't have libstk available. Since then, we've moved to Homebrew (which does have libstk), so I kept the home-built rawwaves directory for backwards compatibility although I no longer use it for bundling and haven't tested against MacPorts in quite a while. |
Ok, so what should I do ? Is the current script ok ? |
@zapashcanon sorry I was giving a background story on it all. It looks good. Merging. Note, to other devs... we will not be back-porting this to stable-1.2. |
@zapashcanon spearheaded this PR, I'll see if he's interested in fixing it. Seems like the documentation is straightforward. |
I'll open a PR soon, should be easy. Note: koalaman/shellcheck#942 |
Add shellcheck to the build
Hi,
Just add a build called 'style', which will be used for kwstyle and astyle too (I hope at least).
Currently it's checking for each
.sh
file in.travis/
and in.cmake/
, others scripts are not ours so we won't check against them. If there are others scripts I forgot, just tell me.I also moved some of the code in
.travis.yml
to separated.sh
files as @jasp00 advised, so they can be checked (shellcheck found a few things in them btw) and also to ease the process of adding a "style build" which has nothing in common with other builds.