Skip to content
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

Travis configuration #229

Merged
merged 1 commit into from
Sep 4, 2016
Merged

Travis configuration #229

merged 1 commit into from
Sep 4, 2016

Conversation

dunn
Copy link
Contributor

@dunn dunn commented Sep 1, 2016

The secure environment variables need to be refreshed:

  • BT_TEST_MAIN_USER
  • BT_TEST_MAIN_PASS
  • CONSUMER_KEY
  • CONSUMER_SECRET

I used the travis gem:

travis encrypt CONSUMER_SECRET=etcetc

and so on.

@dunn
Copy link
Contributor Author

dunn commented Sep 1, 2016

Ah, forgot all the new stuff needs to be in a if [ "$TRAVIS_PULL_REQUEST" = "false" ] block: https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions

@dunn dunn force-pushed the travis branch 2 times, most recently from 7be842a to 9bc36d2 Compare September 1, 2016 18:41
@dunn
Copy link
Contributor Author

dunn commented Sep 1, 2016

Instead of doing big conditional blocks in Travis, I might pull the new steps into a shell script.

@dunn dunn force-pushed the travis branch 7 times, most recently from 39b3031 to 00af78f Compare September 2, 2016 02:55
@dunn
Copy link
Contributor Author

dunn commented Sep 2, 2016

Not as pretty, but it works.

@jsha
Copy link
Owner

jsha commented Sep 3, 2016

Thanks for writing this! I think TRAVIS_PULL_REQUEST isn't the right thing to check. For instance, I often use pull requests for my own code. Among other things, it's a handy way to make sure tests pass. Instead, I would check whether the credentials are available in env.

Also, I think we should run all the steps unconditionally, except the ones that will fail without credentials. For instance, npm install is fine, but npm test is expected to fail.


sudo install -o "$USER" -d /etc/blocktogether
sudo install -o "$USER" -d /data/blocktogether
cp -a "$(dirname ${BASH_SOURCE[0]})/../../"config/* /etc/blocktogether/
Copy link
Owner

Choose a reason for hiding this comment

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

For this type of stuff, I usually put a cd $(dirname $0) at the top of the file. You could do the same with ${BASH_SOURCE[0]} (I assume that's more broadly accurate?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I assumed $0 had a different value, but it looks like BASH_SOURCE is slightly more reliable: http://stackoverflow.com/a/179231

But I'll add the cd to the top. Should we also do set -e?

Copy link
Owner

Choose a reason for hiding this comment

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

Yep, -e is good.

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Thanks for writing this! I think TRAVIS_PULL_REQUEST isn't the right thing to check. For instance, I often use pull requests for my own code. Among other things, it's a handy way to make sure tests pass. Instead, I would check whether the credentials are available in env.

For PRs from branches that are part of your own repository, Travis will build them twice as long as "Build pushes" is turned on; once as a PR and once as a push. But I also thought encrypted variables weren't available for any PRs, when they are only hidden from PRs coming from forks. So I'll update to check for the variable(s).

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Also, I think we should run all the steps unconditionally, except the ones that will fail without credentials. For instance, npm install is fine, but npm test is expected to fail.

What would be the benefit of running npm install?

@jsha
Copy link
Owner

jsha commented Sep 4, 2016

What would be the benefit of running npm install?

It makes the .travis.yml simpler, so there are fewer places where a reader has to say "Why is there a conditional here?"

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

OK, fair enough.


cd "$(dirname ${BASH_SOURCE[0]})/../../"

node_modules/.bin/sequelize --config /etc/blocktogether/sequelize.json db:migrate
Copy link
Owner

Choose a reason for hiding this comment

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

Can you put a ./ in from of this and run-dev.sh? I generally like to do that in case . isn't in PATH, which is fairly common. I'm actually surprised it is in Travis' PATH.

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Sweet, we're passing again: https://travis-ci.org/dunn/blocktogether/builds/157387268

mariadb: '5.5'

services:
- mariadb
Copy link
Owner

Choose a reason for hiding this comment

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

https://docs.travis-ci.com/user/database-setup/#Starting-Services

"If you install a service in the addons: section, such as MariaDB, you do not need to add it to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JdzAU1RB2Ukj3VBsEAR3PZir9nVnf+OxZhmDqiaI1uaDtCWOGA4tzeYa6jtbbrOY/7ouTCzxCHJwZia7rpH4cIHTgluVypm9wMxMcxdEB0noowEnn2miaQYB/4/FP5KNnqMC7mjT/RXDQd3LTgospLMmZDDPC26lnW841pAEA/RjbdDOhlBrN4IDSP7Jv4gYXhSHwuxEzH26LciWy/4AKz/tuQhw3Gzw3epHBYUo3iH/GQ02OTSTXmJ5Dyuv3PfZYCe0nY0J4p8yEM8otGX3qd9nAKYjEnnXta6AvSZr5nL99MHQzLtEySYsr/mPFC2SEjSMw='

before_install:
Copy link
Owner

Choose a reason for hiding this comment

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

My understanding of Travis build lifecycle is that before_install and before_script are only useful if you want to rely on the default install or script steps that Travis provides for a given environment: https://docs.travis-ci.com/user/customizing-the-build#Customizing-the-Installation-Step.

Since we're overriding install and script, simpler to move these steps into those and reduce the number of sections we have. That should also allow you to merge before_install.sh and before_script.sh into a single script, say travis_setup.sh, that gets run in the install phase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah! Will do.

@dunn dunn force-pushed the travis branch 2 times, most recently from 436420b to f3d857e Compare September 4, 2016 01:54
@jsha
Copy link
Owner

jsha commented Sep 4, 2016

Looks like you forgot to git add ./bin/travis/install.sh

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

🙀

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Yeah, this is the error I saw before: https://travis-ci.org/dunn/blocktogether/jobs/157389915#L277

@jsha
Copy link
Owner

jsha commented Sep 4, 2016

I think this is the cause:

https://stackoverflow.com/questions/26299552/travis-sudo-is-disabled

I'm guessing that when you put sudo in the .travis.yml, Travis figures it out and automatically disables the Docker-based infrastructure, but when it happens only in the shell script, Travis doesn't know, so the job runs on the Docker-based infrastructure where sudo is not enabled. Instead of including sudo in the Travis file, let's add:

sudo: true

to the config. I think we can do some refactoring to make things work without sudo, but that's work for another change.

@dunn dunn force-pushed the travis branch 2 times, most recently from 440e045 to abaae13 Compare September 4, 2016 02:09
@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Looks like ${CONSUMER_KEY} is returning true: https://travis-ci.org/jsha/blocktogether/jobs/157390801

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

🌲  "[ ${NONEXISTENT} ] && echo hello"
-bash: [  ] && echo hello: command not found

Oh, it's the quotes messing it up.

@jsha
Copy link
Owner

jsha commented Sep 4, 2016

Yep - there are two layer of interpolation here, I think. The string gets evaluated once, interpolating ${NONEXISTENT} to be the empty string. Then that becomes what gets run, which doesn't have a token in that position.

Did you conclude that Travis' YAML parser really does need those quotes?

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Did you conclude that Travis' YAML parser really does need those quotes?

Yeah, I tried without and it died with the same error message: https://travis-ci.org/dunn/blocktogether/builds/157388926

I got 1/2 passing this time: https://travis-ci.org/dunn/blocktogether/builds/157391226. I went back to having them run simultaneously, but I'm not sure why that would matter.

@jsha
Copy link
Owner

jsha commented Sep 4, 2016

Oh right, I forgot! Ok, I'm convinced that the if;then approach works better here.

@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Re-ran the failing job and it passed.

@jsha
Copy link
Owner

jsha commented Sep 4, 2016

Great. LGTM, will merge later tonight when I have a chance to set up the
env vars correctly. Thanks so much!

On Sat, Sep 3, 2016 at 10:28 PM, Alex Dunn notifications@github.com wrote:

Re-ran the failing job and it passed.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#229 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AANcLYcJaXQVOGoV7Ttx1SG1-5E2E8R3ks5qmizIgaJpZM4JyPYd
.

@jsha
Copy link
Owner

jsha commented Sep 4, 2016

Per https://docs.travis-ci.com/user/environment-variables/:

if it does not contain sensitive information, might be different for different branches and should be available to forks – add it to your .travis.yml
if it does contain sensitive information, and might be different for different branches – encrypt it and add it to your .travis.yml
if it does contain sensitive information, but is the same for all branches – add it to your Repository Settings

The third case is true, so I'm going to set the vars in Repository Settings, then merge this, then remove the env vars lines from .travis.yml.

@jsha jsha merged commit c478ce7 into jsha:master Sep 4, 2016
@dunn dunn deleted the travis branch September 4, 2016 13:56
@dunn
Copy link
Contributor Author

dunn commented Sep 4, 2016

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants