main entrypoint.js to use with a GitHub Action to run action written in ruby
# .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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment