citation-style-language / Sheldon

Pull request bot for the CSL styles repository
MIT License
3 stars 4 forks source link

Show sample citations & bib entries for PRs that validate #13

Closed adam3smith closed 5 years ago

adam3smith commented 5 years ago

Just going to do a simple mock-up: Currently Sheldon posts this when a PR gets opened:

Awesome! You just created a pull request to the Citation Styles Language styles repository. One of our human volunteers will try to get in touch soon (usually within a week). In the meantime, I will run some automated checks. You should be notified of the results in a few minutes.

If you haven't done so yet, please make sure your style validates and follows all our other Style Requirements.

To update this pull request, visit the "Files changed" tab above, and click on the pencil icon (see below) in the top-right corner of your style to start editing.

If you have any questions, please leave a comment and we'll get back to you. While we usually respond in English, feel free to write in whatever language you're most comfortable.

Followed by this when the PR passes our tests:

:smiley: Your submission passed all our automated tests.

I'd suggest leaving the first message as is, but would like the second one to be something like:

:smiley: Your submission passed all our automated tests.

Your style will produce the following output: Citations: (Campbell & Pedersen, 2007; Mares, 2001)

Bibliography: Campbell, J. L., & Pedersen, O. K. (2007). The varieties of capitalism and hybrid success. Comparative Political Studies, 40(3), 307–332. https://doi.org/10.1177/0010414006286542 Mares, I. (2001). Firms and the welfare state: When, why, and how does social policy matter to employers? In P. A. Hall & D. Soskice (Eds.), Varieties of capitalism. The institutional foundations of comparative advantage (pp. 184–213). New York: Oxford University Press.

Where citations and bibliography are generated from the new style (I was thinking we could have the data in a public Zotero group and simply use API calls to Zotero, but agnostic about the method to be used.

retorquere commented 5 years ago

I'm terribly sorry about this, but I had forgotten that in PRs, secret variables like github tokens are not set (for good reasons). This means PR-builds cannot post directly to GH. I've been talking to Travis support about this (who are super responsive!), and it looks like the best option is to mostly keep Sheldon but also keep the stuff I've done and have them cooperate.

The reason now-Sheldon can't (reasonably) do everything on its own is that you really need a checked out repo at the exact point where the PR runs as well as access to the master branch and have the travis vars available -- we'd be trying to replicate the Travis build environment on Heroku (which is where shel-bot runs right?)

The coop solution would be to keep shel-gem mostly as-is, but have it not post to github but either upload its output to transfer.sh or just output it to the console. shel-bot would then parse out either the transfer.sh response url or the shel-gem output from the travis log, and post that.

There's upsides and downsides to each of these coop modes:

I don't currently see a way around this. I'm trying to think of a format which would look good enough to post in the log that would also be re-parsable for shel-bot.

adam3smith commented 5 years ago

I think it makes sense to go with the transfer.sh option and see if we're having issues with stability. Given that one of the reasons for doing this is to improve the experience for style contributors, clean output would be important.

retorquere commented 5 years ago

I'm trying a few services - transfer.sh is really slow (10-20 seconds) and in some of my tests it simply times out when I try to post the assets. Edit: this may be a rate limit because I'm now structurally hitting this but I've also occasionally seen transfer.sh just keel over.

retorquere commented 5 years ago

0x0.st explicitly forbids "spamming the service with CI build assets" and file.io has both a monthly limit of 100 uploads (and it's probably enforced by IP address so from a CI service we'd be pooled in with anyone else using it) and there's some kind of rate limit going on (I sometimes get "too many requests" even from my home system).

If anyone knows other services of the kind, I'd love to hear about it, but I'm currently looking for different solutions altogether.

retorquere commented 5 years ago

One other option would be to set up an S3 or backblaze bucket which allows anon uploads but only authenticated downloads, with an auto-expiry policy to keep the bucket size down. I use this setup for BBT logs and I've only once broken the 8ct/month limit which was when I was furiously putting out new builds in the Z5 port. Benefit of this would be that there'd need to be nothing in the logs -- shel-bot could just pick it up at an agreed name.

retorquere commented 5 years ago

There's one other way that just struck me -- technically possible but ho-hum from a beauty point of view. The travis log renderer honors ansi escape sequences, so I could output the shel-bot message, erase it using backspaces, which would remove it from view but it would remain in the actual log where I could parse it out.

retorquere commented 5 years ago

There's an ungodly amount of magic going on in rspec -- I'm getting

undefined method `assert_equal' for nil:NilClass

when I run rspec on shel-bot. I've so far traced it back to the minitest context (ctx) being nil in minitest-5.11.3/lib/minitest/spec.rb. Anyone here experience with rspec?

retorquere commented 5 years ago

In a clean rvm setup, I'm hitting

$ rspec
/Users/emile/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem rspec-core (>= 0.a) with executable rspec (Gem::GemNotFoundException)
    from /Users/emile/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems.rb:302:in `activate_bin_path'
    from /usr/local/lib/ruby/gems/2.6.0/bin/rspec:23:in `<main>'
retorquere commented 5 years ago

Wait, I don't need rspec -- I just need to run rake. But when I run rake, I get

Fabulous run in 0.000468s, 0.0000 runs/s, 0.0000 assertions/s.

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
retorquere commented 5 years ago

This is driving me nuts. What I see in the Rakefile seems to use minitest, but then the actual spec files use rspec's describe/it syntax. @inukshuk, can you give me a push in the right direction?

retorquere commented 5 years ago

Alright, more clarity; the csl gems pull in newer versions of rspec it seems, and the existing test setup does not like this. No errors, but no tests ran.

The quick way to solve this is to keep shel-bot and shel-gem on different branches. I do worry a little about the technological debt shel-bot is going to accumulate over time. I had tried to merge shel-bot and shel-gem (which should be possible), but realistically, that would require some gems in shel-bot to be updated, and due to the amount of magic going on in rspec, it's not easy to find out which gem is injecting what into the various namespaces.

inukshuk commented 5 years ago

@retorquere I've not been following along, but on a quick glance Sheldon does not use rspec but rather minitest. The csl/citeproc gems use rspec, but only as dev dependencies -- those should not be pulled in when you install them (unless you specifically use dev dependencies).

retorquere commented 5 years ago

My bad.

I've been able to get it to work by pinning gems to the exact versions I get when the tests run on Travis. I've not been able to get the tests to run bu just having the gems all at their latest versions -- rake runs without errors but no tests are actually ran.

If this pinning is OK, I can proceed to merge the shel-gem part; it doesn't actually touch shel-bot (yet), just adds the gem-installable executable to the existing Sheldon so that the travis counterpart can be easily installed on styles and locales.

inukshuk commented 5 years ago

I'm a bit confused by that gemspec file. Most gems don't package test/spec files at all, in my experience; the test files also don't seem to be added to spec.files here, so maybe that's why no tests ran? The file also pulls in rspec even though it's not being used, that doesn't seem right. In any case, pinning versions of dev and test dependencies is much easier to do using bundler / Gemfile.lock -- I'd really try to use that instead of specifying everything as gem dependencies. Specifying something like puma is also potentially restricting since you could use other rack-compatible servers to run this. Furthermore, the bin folder` only contained bundler binstubs, which are just there for convenience really, it's not something that should be included in a gem.

That said, I'm really out of the loop here, so I may be missing the point.

retorquere commented 5 years ago

Ah no, the gemspec file isn't complete yet, but for the shel-bot part nothing changes; the gemspec is really only being used by gem consumers. I can run rake in the current state and the tests run, it's just when I upgraded the gems that the tests don't run. I don't intend to add the spec files to spec.files.

Using the gemspec is really the same as using the Gemfile from the point of view of shel-bot -- a lockfile is also generated as normal. That said, I'm no expert on gem packaging, I'm just cribbing things together best I can.

Turns out puma isn't required, I just at some point added everything that I saw was being pulled in previously to just get the tests going. The tests run without puma being brought in just fine, so I've removed it. I'm going through the pinned gems one by one to see which I can remove from pinning.

The bin directory also include the executable I intend to run on Travis, so it's no longer just the stubs.

In the end, the idea is that the gem-part offers a ruby script that generates a GH-friendly summary of the test results, which the bot-part can pick up. I could just have either the gem-part on a separate branch, or even a separate repo, but given that these two would work so closely together, at least the same repo would make most sense to me.

inukshuk commented 5 years ago

Is the part that's going to be run on Travis also run by the stateless web service on Heroku?

retorquere commented 5 years ago

No, but the part that's going to be ran on heroku will expect there to be something in the travis log that's put there by the script in bin.

retorquere commented 5 years ago

I'm going to start moving stuff back into the Gemfile -- I had misinterpreted the gemspec stuff I found to say that everything needs to be there, which is not the case.

inukshuk commented 5 years ago

Cool, I think that's better (I'd just leave runtime deps in the gemspec). If the Travis script does not run on Heroku, I'd also put its dependencies into a separate Group in the Gemfile which is not installed on Heroku. But in general, maybe it would be easier to use a separate repo for this (because I'm not sure that you could actually keep dependencies defined in the gemspec file out of the bundle created on Heroku).

retorquere commented 5 years ago

It may be possible to have the gem deps not installed on heroku; the current gemfile adds a section called travis (https://github.com/retorquere/Sheldon/blob/gem/Gemfile#L29), but I don't know how heroku chooses what sections to install.

retorquere commented 5 years ago

(other than that it turns out I only had to pin hashdiff because newer versions of hashdiff have a namespace conflict with another gem).

retorquere commented 5 years ago

OK, I think I have things prepped now. Shel-bot should be unaffected other than picking up the build report from the log, and the sheldon gem now lives in a single script. I'm going to deploy it to my own heroku instance to see how it works out.

retorquere commented 5 years ago

Two questions:

  1. How can I verify that my copy of shel-bot is receiving events and acting on them? I have my copy set up on https://retorquere-sheldon.herokuapp.com/ but I'm not seeing any responses on my own PR.
  2. Perhaps related: it looks like PRs submitted by the repo owner do not get treated as PRs; @adam3smith, could you merge the reporting branch again and push to see if that's the difference?
rmzelle commented 5 years ago
  1. How can I verify that my copy of shel-bot is receiving events and acting on them? I have my copy set up on https://retorquere-sheldon.herokuapp.com/ but I'm not seeing any responses on my own PR.

Maybe you're missing a webhook (https://github.com/citation-style-language/styles/blob/0e4b1f80ed20ccf3a88febebf2c526aa734d80e1/.travis.yml#L14)?

retorquere commented 5 years ago

I have it figured out (and tested), the PRs are ready.

adam3smith commented 5 years ago

I have it figured out (and tested), the PRs are ready.

... and waiting for your input: https://github.com/citation-style-language/Sheldon/pull/15#issuecomment-499906106

retorquere commented 5 years ago

OK, I think everything is in place now. Sheldon is running on heroku-18, and styles/locales now automatically fetch the latest sheldon reporter during the tests, so maintenance can be done on this repo for the entire setup. I think that is that then?

rmzelle commented 5 years ago

Thanks both for getting this in place!

retorquere commented 5 years ago

All for a good cause https://imgur.com/a/gruF37o