Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

Help with actions for Ruby gem

Solved! Go to Solution.

I have a Ruby gem which I've been building with Travis but I want to make the transition to GitHub actions. I took the example Ruby gem action and expanded upon it somewhat, but I feel it could be further improved. The file as it stands now:

 

https://github.com/haiafara/underpass/blob/04f2c48a20dc66af051a6c9e5ccd91465387eaac/.github/workflow...

 

As you can see I have three jobs:

 

  • rubocop - checks for code style
  • rspec - depends on rubocop and runs the test suite
  • publish - depends on rspec and publishes the gem if the action was run on the master branch

 

What I would like to improve:

 

  • All three jobs run the checkout and Ruby setup steps, is it possible to run these only one time? I mean once rubocop finishes it would preserve the project directory and the next step would continue from that point.
  • Is it possible to somehow separate the publish job so that it doesn't even start on branches that are different from master?
2 Replies
Solution
Pilot Lvl 1
Message 2 of 3

Re: Help with actions for Ruby gem


@janosrusiczki wrote:
preserve the project directory and the next step would continue from that point.


No caching available yet...

 

EDIT: Posted too fast... next step or next job?

Everything is in place until job finishes, so everything* you do in one step is visible in another.

If it's about next job, currently only way to pass files from job to job is to upload files in one job and download in another (for example using actions/upload-artifact + actions/download-artifact).

 

*Current directory changes on each step; if you `cd my_dir` in one step, next one will push you back where you started.

 


@janosrusiczki wrote:
  • Is it possible to somehow separate the publish job so that it doesn't even start on branches that are different from master?

You have a small mistake there;

if: github.ref == 'master'

should be

if: github.ref == 'refs/heads/master'

 

If you want to skip whole job, move that check under `job.<id>`

publish:
 runs-on: ubuntu-latest
 if: github.ref == 'refs/heads/master'

 

Copilot Lvl 2
Message 3 of 3

Re: Help with actions for Ruby gem

Thank you for the hints. I moved the if statement and indeed it's skipping that job altogether.

 

As for artifact uploading and downloading: I printed out where it is installing the gems and it said: /opt/hostedtoolcache/Ruby/2.6.3/x64/lib/ruby/gems/2.6.0/gems - so I thought I'll upload that directory as an artifact and download it in the next job. The problem is that that directory is huge, because as its name says it's basically a systemwide cache. And since the upload was progressing really slowly I canceled it, but I'm not sure it would have worked anyway because AFAIK bundle install does some linking too.

 

The good news is that as stated here they're currently working on caching, so I won't try reinvent the wheel, I'll just wait patiently.