Last active
September 11, 2019 14:05
-
-
Save 1stvamp/64f889404d58906875c42291f9117746 to your computer and use it in GitHub Desktop.
main entrypoint.js to use with a GitHub Action to run action written in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/actions/my-action/action.yml | |
name: "My fabulous ruby action!" | |
description: "" | |
runs: | |
using: 'node12' | |
main: 'entrypoint.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .github/actions/my-action/entrypoint.js | |
const { main } = require('../base_entrypoint.js') | |
main(__dirname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .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