firstdraft / grade_runner

A Ruby client for grades.firstdraft.com
MIT License
1 stars 0 forks source link

Add non-Rails support #66

Closed jelaniwoods closed 1 year ago

jelaniwoods commented 1 year ago

Resolves #65

Problem

In the efforts to come up with one Gemfile for the entire "appdev" course, it would simplify things if grade_runner and ruby_grade_runner were unified into one gem instead of having to install both and remove one depending on which project is being worked on.

The main reason for the two gems was because grade_runner was assumed to be installed in a Rails app and didn't properly load methods from active support that were being used.

Solution

This PR:

An unrelated change I added was the ability to record the GitHub username of the person running rails grade. Previously, this was just reporting the full name of the user from the local Git config. In this PR I've added an API call to GitHub to retrieve the username and fallback to the full name if one is not found.

I've also bumped the gem version

Test

Install this version of the gem

gem "grade_runner", github: "firstdraft/grade_runner", branch: "65-jw-add-non-rails-support"

Rails

You should be all set! Just run rails grade again as usual.

non-Rails

Update bin/rails to find grade_runner instead of ruby_grade_runner.

#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'rake'

dir = Gem::Specification.find_by_name('grade_runner').gem_dir

load "#{dir}/lib/tasks/grade.rake"
task_name = ARGV[0]

Rake::Task[task_name].invoke

then bin/rails grade as usual.

bpurinton commented 1 year ago

@jelaniwoods I'm trying to get a sinatra app grading via either Gitpod or Codespaces (preferably both) with rails grade. I made the repo, added specs, and put it on the testing canvas and am trying both Gitpod and Codespaces; but I keep getting a permission denied error that I can't seem to debug. Is my repo setup missing something? I based the file structure (e.g. bin/ folder) off of the ruby-string chapter (non-rails based).

image

Here is the repo

And here is the Canvas launcher to test with the rails grade token

jelaniwoods commented 1 year ago

I keep getting a permission denied error that I can't seem to debug.

@bpurinton this sounds like a file permissions issue that can be resolved by making bin/rails executable. You can do this by running chmod 755 bin/rails, and then bin/rails grade should run.

Though, looking at your repo I realize that rake wasn't added as a runtime dependency. I'll add that now.

bpurinton commented 1 year ago

D'oh. I was trying sudo to get around it; forgot all about chmod. Everything runs beautifully with bin/rails grade. But, we are likely going to change grading to rake grade. Is that something we will change in this repo (maybe on a separate PR) or is that a change that will be made somewhere in the bin/ files for each project repo?

jelaniwoods commented 1 year ago

we are likely going to change grading to rake grade

@bpurinton Nothing about this gem needs to change for rake grade to work.

In Rails apps, grade is already loaded as a Rake task that can be run by either rails grade or rake grade.

In non-Rails apps, bin/rails is just named to be consistent with Rails apps, but you can name the file anything including bin/rake to make bin/rake grade work if that's the new thing. You can also add the bin folder to PATH to make it so students can run rake grade in a non-Rails environment too.

Does that help clarify?

bpurinton commented 1 year ago

Thanks for clarifying things here! I think I've fully gotten my head around grade_runner finally. And this change LGTM in case that wasn't clear.