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

Build bottles on Travis-CI and deploy to Bintray #114

Merged
merged 7 commits into from
Oct 20, 2017
Merged

Conversation

davidchall
Copy link
Owner

@davidchall davidchall commented Oct 13, 2017

The aim is to use Travis-CI to build bottles for this tap's formulae, and then upload them to my Bintray.

@MikeMcQuaid seems keen for this functionality in Homebrew/brew#2572 and cartr/qt4-autobottler#1. This would be helpful for other tap maintainers, and might be incorporated into brew tap-new.

I believe I can do this using brew test-bot and brew test-bot --ci-upload if the right environment variables are set and arguments are passed. Some changes to brew test-bot might be required.

Notes:

  • I set HOMEBREW_BINTRAY_KEY using encrypted Travis-CI variables

@davidchall
Copy link
Owner Author

There appears to be a conflict because GIT_DIR is set to the tap repo, which causes brew update to fail: https://github.com/Homebrew/homebrew-test-bot/blob/master/cmd/brew-test-bot.rb#L1202

$ brew test-bot --ci-upload --git-name=davidchall --git-email=dhcrawley@gmail.com --bintray_org=davidchall
Homebrew/homebrew-test-bot e43a85a (Merge pull request #122 from MikeMcQuaid/fix-linux)
ARGV: --ci-upload --git-name=davidchall --git-email=dhcrawley@gmail.com --bintray_org=davidchall --verbose --ci-auto --no-pull --coverage --ci-pr --cleanup --test-default-formula
git checkout -f master
Warning: you are leaving 2 commits behind, not connected to
any of your branches:
  6e1354f Merge e741771942638706731f5647200cfd59c90f59a9 into 730bdaba3d1ddcd3b3f158d6c3323181c3b160c0
  e741771 Initial attempt to build bottles
If you want to keep them by creating a new branch, this may be a good time
to do so with:
 git branch <new-branch-name> 6e1354f
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
git reset --hard origin/master
HEAD is now at 730bdab fjcontrib 1.030 (#110)
brew update
fatal: $program_name cannot be used without a working tree.
Error: Could not 'git stash' in /usr/local/Homebrew!
Please stash/commit manually if you need to keep your changes or, if not, run:
  cd /usr/local/Homebrew
  git reset --hard origin/master
Error: Failure while executing: brew update

@davidchall davidchall changed the title Initial attempt to build bottles Build and deploy bottles on Travis-CI Oct 14, 2017
@davidchall davidchall changed the title Build and deploy bottles on Travis-CI Build bottles on Travis-CI and deploy to Bintray Oct 14, 2017
@MikeMcQuaid
Copy link

This seems like a good idea, thanks @davidchall. The main thing you may want to additionally check is to only upload on PRs from non-forks. This unfortunately is also the possible blocker for this functionality being widely useful but it still seems like something useful to have in brew tap-new.

@davidchall
Copy link
Owner Author

@MikeMcQuaid Could you please elaborate on why we should only upload on PRs from non-forks?

Since taps often do get PRs from forks, I was thinking that we should do the upload after a PR has been accepted. That is, upload from non-PR builds on the master branch.

@MikeMcQuaid
Copy link

Could you please elaborate on why we should only upload on PRs from non-forks?

Unfortunately Travis CI only exposes "secret" environment variables to PRs from non-forks i.e. the Bintray key needed for upload.

@davidchall
Copy link
Owner Author

Could you please elaborate on why we should only upload on PRs from non-forks?

Unfortunately Travis CI only exposes "secret" environment variables to PRs from non-forks i.e. the Bintray key needed for upload.

Right, of course. That's why I thought uploading from master branch builds (after PR merge) might be better. Do you see any problem with this approach?

@MikeMcQuaid
Copy link

@davidchall The main problem is you'll need to push a commit somehow with the updated bottle checksums. Broadly that does seem like a good approach, though. It's also something that could work pretty well for single-maintainer taps where you're the main person creating the PRs.

Fix brew-audit for yoda formula.
@davidchall
Copy link
Owner Author

@MikeMcQuaid These changes, in combination with my changes to homebrew-test-bot now upload bottles to my Bintray repo from PRs, using the same package structure as Homebrew.

I'm struggling to edit brew-test-bot to produce bottles on master branch builds, though. This is pretty different from your current workflow of having an independent BrewTestBot handle this, which is based on PRs. Right now, it doesn't seem to notice that formulae have changed, so nothing is built. Would you be able to provide some advice on this step?

Once this barrier is overcome, brew test-bot --ci-upload already commits the bottle DSL changes, and it's possible to git push this to the master branch. Of course, this assumes that there are no conflicts in the formulae involved - but for small taps like the ones we're thinking about, it is probably fine.

- ulimit -n 1024

script:
- brew test-bot
- brew tap davidchall/test-bot

Choose a reason for hiding this comment

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

Would love you to submit a PR for some of these changes upstream 😁

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'll make sure to open a PR sometime soon.

.travis.yml Outdated
fi

after_success:
- if [ "$TRAVIS_BRANCH" = "master" ]; then

Choose a reason for hiding this comment

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

Could maybe just do/detect this on any non-fork-PR branch?

Copy link
Owner Author

Choose a reason for hiding this comment

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

When to upload the bottle is a matter of workflow. I think we should discuss this when I open a PR on the test-bot repo. For now, I just want a proof of concept.

@davidchall davidchall merged commit 575c347 into master Oct 20, 2017
@davidchall davidchall deleted the bottles branch October 20, 2017 19:26
@maelvls
Copy link

maelvls commented Oct 31, 2017

Hi @davidchall,

First of all, thank you for all the (invaluable) information in this PR. I was looking for a way of using test-bot on a tap with travis+bintray.

That would be great if we could summarize the whole thing (things like:

  • when testing travis builds, I had to "force" a commit with changes only to a formula.rb (if you commit a change to .travis.yml as well as a change to Formula/formula.rb, it doesn't work) in order to trigger a "real" test-bot build; it took me so many travis builds before realizing that. If you don't change the formula, brew test-bot will not build the bottle and everything.
  • on bintray, the repo name must be of the form
    https://api.bintray.com/packages/<user>/bottles-<repo>
  • Error: Kernel.Exit means that one of the commands in brew test-bot failed

Too bad the test-bot project isn't that documented 😞

I was also wondering about the commit made by brew test-bot --ci-upload during the travis build, e.g. in this build:

sherpa: add 2.2.4 bottle.

Shouldn't it be pushed to master? Or it should be done by hand?

Thanks for your work!!

@maelvls
Copy link

maelvls commented Oct 31, 2017

If I understand correctly the workflow:

  1. create a new release of some formulae, create a PR
  2. during the PR TravisCI build, test-bot --ci-pr will push 3 commits corresponding to the binaries hashes into the PR:
bottle do
  sha256 "62cbd8989162d53d648751b232e73a5fa3cf6cae1c73095b47c26b7c915d444b" => :high_sierra
  sha256 "83f450adc044bd5faf8e820b2d4148ffdeffdb014643410a756547371fd692c5" => :sierra
  sha256 "b5c57196809ed3a7ab04bc9e725587679d7e8d77b4cc03156536ce247ed7da81" => :el_capitan
end

But at that time, no upload yet.

  1. we rebase the multiple commits made by travis into one commit
  2. when the PR is accepted and is merged, TravisCI will build and upload using --ci-upload; this is the moment where the binaries are uploaded to Bintray

Did I understand correctly?

@MikeMcQuaid
Copy link

If you don't change the formula, brew test-bot will not build the bottle and everything.

Yep.

Too bad the test-bot project isn't that documented 😞

We'd welcome PRs to improve that!

during the PR TravisCI build, test-bot --ci-pr will push 3 commits corresponding to the binaries hashes into the PR:

test-bot --ci-pr will only commit onto the local Git repository in the Travis CI instance. You'll need to upload the resulting JSON files somewhere and combine them for the final commit to be done in the --ci-upload step.

@maelvls
Copy link

maelvls commented Nov 8, 2017

Thank you so much!
So what I did was to set up a staged CI using TravisCI (.travis.yml here, travis builds here, tap homebrew-touist is here):
capture d ecran 2017-11-08 a 19 51 10

  1. First stage is running brew test-bot only; at the end, they upload the bottle+json to an AWS S3 bucket (free).
  2. Second stage ("deploy") only runs on master; it download the bottles+json from AWS S3 and uploads the bottles to Bintray and creates and pushes the commit with the merged bottle DSL stuff.

I forked homebrew-test-bot here; I added some comments (for --help) and I enabled the git push using https instead of ssh.

There still is a problem with the rebuilds needed in case of updated dependencies as @scpeters mentionned in Homebrew/brew#2572 (comment) and also mentionned in Homebrew/brew#3346. I only rely on gmp but still; I should find a way to subscribe to the updates of gmp and trigger a revision+rebuild on my TravisCI instance.

@scpeters
Copy link

scpeters commented Nov 8, 2017

Nice work

@MikeMcQuaid
Copy link

I forked homebrew-test-bot here; I added some comments (for --help) and I enabled the git push using https instead of ssh.

@maelvalais Could you submit a pull request for your changes?

@MikeMcQuaid
Copy link

So what I did was to set up a staged CI using TravisCI (.travis.yml here, travis builds here, tap homebrew-touist is here):

Similarly a PR to Homebrew/brew's tap-new.rb would be great for Travis CI, too!

@maelvls
Copy link

maelvls commented Nov 11, 2017

Here is the PR for test-bot: davidchall/homebrew-test-bot#1
I'll take a look to tap-new and draft a PR, it is a good idea! 👍

@davidchall
Copy link
Owner Author

Hi @maelvalais, thanks for all your hard work on this. I'm in the middle of a coast-to-coast move, so things have slowed down a bit. But I'm more than willing to open a PR against Homebrew/homebrew-test-bot if this is what people desire.

I was keeping notes on the steps I took to set this up, with the idea to update How-to-Create-and-Maintain-a-Tap once I had the entire workflow ready. But it seems that you reverse-engineered a lot of this already.

I originally just focussed on creating and uploading the bottles to Bintray, and was then planning to figure out how to use staged Travis builds to push the commit that adds the bottle DSL to the formula. Looks like you've got this figured out, and in a smart way. Thank you!!

@MikeMcQuaid
Copy link

@davidchall @maelvalais Sorry, I was meaning could the two of you submit your changes back up to the main homebrew-test-bot and Homebrew/brew repos. No rush, though.

@maelvls
Copy link

maelvls commented Nov 11, 2017

Thanks @davidchall :)

I began to write some notes for How-to-Create-and-Maintain-a-Tap in a gist; I wrote it in case I forget something.

papucci pushed a commit to papucci/homebrew-hep that referenced this pull request Jan 26, 2018
* Build and upload bottles from master branch builds
* Fix brew-audit for yoda formula
@MikeMcQuaid
Copy link

@davidchall Any updates here? No worries if not. Thanks!

@maelvls
Copy link

maelvls commented Feb 6, 2018

Hi!
I merged (like 1h ago) the current Linuxbrew's Homebrew's test-bot into @davidchall's fork. I opened a PR (davidchall/homebrew-test-bot#3); some conflicts were kind of tricky and I had to git blame a lot in order to find what was what. I hope we will manage to get it merged 😇

Update: I meant Homebrew/homebrew-test-bot (not Linuxbrew/homebrew-test-bot), sorry for that! I fixed this and changed the name of the PR also.

@davidchall
Copy link
Owner Author

Hi @MikeMcQuaid @maelvalais, I plan to get back into this project over the next couple of weeks and review the latest PR. Sounds like we're getting very close to merging back into the Homebrew repo.

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

4 participants