Skip to content

Instantly share code, notes, and snippets.

@1stvamp

1stvamp/Gemfile

Last active Sep 11, 2019
Embed
What would you like to do?
main entrypoint.js to use with a GitHub Action to run action written in ruby
# .github/actions/my-action/lib/action.rb
require 'json'
puts "I'm an action!"
event = JSON.parse(File.read(ENV['GITHUB_EVENT_PATH']))
puts event.inspect
# .github/actions/my-action/action.yml
name: "My fabulous ruby action!"
description: ""
runs:
using: 'node12'
main: 'entrypoint.js'
// .github/actions/base_entrypoint.js
// NOTE: this script just runs the main action.rb file with the ruby
// installed by GitHub's actions/setup-ruby action.
const { existsSync } = require('fs')
const { spawnSync } = require('child_process')
function run(cmd, cwd) {
try {
const child = spawnSync(cmd, { shell: true, cwd })
if (child.stdout) {
console.log(child.stdout.toString())
}
if (child.stderr) {
console.error(child.stderr.toString())
}
if (child.status != 0) {
process.exit(child.status)
}
} catch (err) {
console.error(err.message)
process.exit(err.status)
}
}
function main (cwd) {
if (existsSync(`${cwd}/Gemfile`) || existsSync(`${pwd}/Gemfile.lock`)) {
run('gem install bundler', cwd)
run('bundle install', cwd)
}
run(`ruby ./lib/action.rb`, cwd)
}
module.exports = { main, run }
// .github/actions/my-action/entrypoint.js
const { main } = require('../base_entrypoint.js')
main(__dirname)
# .github/actions/my-action/Gemfile
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment