Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const attributes = core.getInput('attributes');
const name = core.getInput('name', { required: true });
const signingKey = core.getInput('signingKey');
const authToken = core.getInput('authToken')
const cachixExecutable = "/nix/var/nix/profiles/per-user/runner/profile/bin/cachix";
core.startGroup('Installing Cachix')
await exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
core.endGroup()
// for private caches
if (authToken !== "") {
await exec.exec(cachixExecutable, ['authtoken', authToken]);
}
core.startGroup(`Cachix: using ` + name);
await exec.exec('cachix', ['use', name]);
core.endGroup();
if (signingKey !== "") {
core.startGroup('Cachix: Configuring push');
// needed to discover auth token
await exec.exec("sudo", ["sh", "-c", `echo export HOME=${home()} > /etc/nix/cachix-push.sh`]);
await exec.exec("sudo", ["sh", "-c", `echo export CACHIX_SIGNING_KEY=${signingKey} >> /etc/nix/cachix-push.sh`]);
// needed to for nix-store
await exec.exec("sudo", ["sh", "-c", `echo export PATH=\\$PATH:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/per-user/runner/profile/bin >> /etc/nix/cachix-push.sh`]);
await exec.exec("sudo", ["sh", "-c", `echo ${cachixExecutable} push ${name} \\$OUT_PATHS >> /etc/nix/cachix-push.sh`]);
await exec.exec("sudo", ["sh", "-c", `chmod +x /etc/nix/cachix-push.sh`]);
// enable post-build-hook
await exec.exec("sudo", ["sh", "-c", `echo post-build-hook = /etc/nix/cachix-push.sh >> /etc/nix/nix.conf`]);
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
async function installDependencies(kind, dependencyList) {
if (dependencyList === '') { return }
core.startGroup(`Installing ${kind} dependencies`)
core.info(`installing ${kind} dependencies ${dependencyList}`)
// only update package list once per workflow invocation.
if (!aptUpdated) {
await exec.exec(`sudo apt-get update`)
aptUpdated = true
}
await exec.exec(`sudo apt-get install -y --no-install-recommends ${dependencyList}`)
core.endGroup()
}
async function run() {
try {
// inputs
const file = core.getInput('file');
const skipNixBuild = core.getInput('skipNixBuild');
const attributes = core.getInput('attributes');
const name = core.getInput('name', { required: true });
const signingKey = core.getInput('signingKey');
const authToken = core.getInput('authToken')
const cachixExecutable = "/nix/var/nix/profiles/per-user/runner/profile/bin/cachix";
core.startGroup('Installing Cachix')
await exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
core.endGroup()
// for private caches
if (authToken !== "") {
await exec.exec(cachixExecutable, ['authtoken', authToken]);
}
core.startGroup(`Cachix: using ` + name);
await exec.exec('cachix', ['use', name]);
core.endGroup();
if (signingKey !== "") {
core.startGroup('Cachix: Configuring push');
// needed to discover auth token
await exec.exec("sudo", ["sh", "-c", `echo export HOME=${home()} > /etc/nix/cachix-push.sh`]);
async function setupTestEnvironment(rubyVersion) {
core.startGroup('Setup Test Environment')
const filePath = gemspecFilePath(rubyVersion)
const workspacePath = process.env.GITHUB_WORKSPACE
await restoreBundleFromCache(rubyVersion)
// restore the Gemfile.lock to working folder if cache-hit
if (fs.existsSync(`${filePath}/Gemfile.lock`)) {
await io.cp(`${filePath}/Gemfile.lock`, `${workspacePath}/Gemfile.lock`)
await exec.exec('bundle', ['install'])
}
// otherwise, bundle install and cache it
else {
await exec.exec('bundle', ['install'])
await io.cp(`${workspacePath}/Gemfile.lock`, `${filePath}/Gemfile.lock`)
async function saveBundleToCache(rubyVersion) {
core.startGroup(`Save Bundle to Cache`)
const key = bundleCacheKey(rubyVersion)
await cache.saveCache(bundleCachePaths(rubyVersion), key)
core.endGroup()
}
async function _installRubyBuild() {
core.startGroup('Installing ruby-build')
await _installDependencies()
const rubyBuildDir = `${process.env.HOME}/var/ruby-build`
await exec.exec(`git clone https://github.com/rbenv/ruby-build.git ${rubyBuildDir}`)
await exec.exec(`sudo ${rubyBuildDir}/install.sh`, { env: { 'PREFIX': '/usr/local' } })
core.endGroup()
}
async function _installRuby(rubyVersion, cacheAvailable) {
core.startGroup(`Installing ${rubyVersion}`)
if (!cacheAvailable) {
await exec.exec(`ruby-build ${rubyVersion} ${process.env.HOME}/local/rubies/${rubyVersion}`)
} else {
core.info(`Skipping installation of ${rubyVersion}, already available in cache.`)
}
core.addPath(`${process.env.HOME}/local/rubies/${rubyVersion}/bin`)
const rubyPath = await io.which('ruby', true)
await exec.exec(`${rubyPath} --version`)
core.setOutput('ruby-path', rubyPath);
core.endGroup()
}
'-C', dest.replace(/\\/g, '/'),
'-f', distrib
]);
let cmd = path.join(dest, 'msys2do.cmd');
fs.writeFileSync(cmd, [
'setlocal',
'IF NOT DEFINED MSYS2_PATH_TYPE set MSYS2_PATH_TYPE=' + core.getInput('path-type'),
`%~dp0\\msys64\\usr\\bin\\bash.exe -ilc "cd $OLDPWD && %*"`
].join('\r\n'));
core.addPath(dest);
core.exportVariable('MSYSTEM', core.getInput('msystem'));
core.startGroup('Starting MSYS2 for the first time...');
await exec.exec(`msys2do`, (core.getInput('update') == 'true') ?
['pacman', '-Syu', '--noconfirm']
:
['uname', '-a']
);
core.endGroup();
}
catch (error) {
core.setFailed(error.message);
}
}
async function restoreBundleFromCache(rubyVersion) {
core.startGroup(`Restore Bundle from Cache`)
const key = bundleCacheKey(rubyVersion)
core.info(`restore using ${key}`)
await cache.restoreCache(bundleCachePaths(rubyVersion), key, [key])
core.endGroup()
}