From a0179489c805bd4125f830943661638c1406e68f Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Mon, 22 Mar 2021 00:37:59 +0000 Subject: [PATCH] Test unavailable Elixir upon mix --- __tests__/setup-beam.test.js | 18 ++++++++++++++++++ dist/index.js | 16 ++++++++++++++-- src/setup-beam.js | 16 ++++++++++++++-- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/__tests__/setup-beam.test.js b/__tests__/setup-beam.test.js index df603543..61671f99 100644 --- a/__tests__/setup-beam.test.js +++ b/__tests__/setup-beam.test.js @@ -42,6 +42,24 @@ async function test() { }, `Installing rebar3 ${r3Version} is supposed to fail`) + await assert.rejects( + async () => { + await setupElixir.mixRebar() + }, + (err) => { + assert.ok(err instanceof Error); return true + }, + `Mixing rebar without Elixir is supposed to fail`) + + await assert.rejects( + async () => { + await setupElixir.mixHex() + }, + (err) => { + assert.ok(err instanceof Error); return true + }, + `Mixing Hex without Elixir is supposed to fail`) + getOTPVersion({ spec: '19.3.x', osVersion: 'ubuntu-16.04', expected: 'OTP-19.3.6', diff --git a/dist/index.js b/dist/index.js index 0db6c119..93491b73 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4014,13 +4014,23 @@ function maybeInstallElixir(otpVersion, elixirBuildsListing) { async function mixRebar() { if (core.getInput('install-rebar') !== false) { - await exec('mix local.rebar --force') + const cmd = 'mix local.rebar --force' + await exec(cmd) + .catch((err) => { + core.error(`${cmd} failed`) + throw new Error(err) + }) } } async function mixHex() { if (core.getInput('install-hex') !== false) { - await exec('mix local.hex --force') + const cmd = 'mix local.hex --force' + await exec(cmd) + .catch((err) => { + core.error(`${cmd} failed`) + throw new Error(err) + }) } } @@ -4170,6 +4180,8 @@ module.exports = { getOTPVersion: getOTPVersion, getElixirVersion: getElixirVersion, getRebar3Version: getRebar3Version, + mixRebar: mixRebar, + mixHex: mixHex, } diff --git a/src/setup-beam.js b/src/setup-beam.js index 7a5bf58c..0652a321 100644 --- a/src/setup-beam.js +++ b/src/setup-beam.js @@ -66,13 +66,23 @@ function maybeInstallElixir(otpVersion, elixirBuildsListing) { async function mixRebar() { if (core.getInput('install-rebar') !== false) { - await exec('mix local.rebar --force') + const cmd = 'mix local.rebar --force' + await exec(cmd) + .catch((err) => { + core.error(`${cmd} failed`) + throw new Error(err) + }) } } async function mixHex() { if (core.getInput('install-hex') !== false) { - await exec('mix local.hex --force') + const cmd = 'mix local.hex --force' + await exec(cmd) + .catch((err) => { + core.error(`${cmd} failed`) + throw new Error(err) + }) } } @@ -222,4 +232,6 @@ module.exports = { getOTPVersion: getOTPVersion, getElixirVersion: getElixirVersion, getRebar3Version: getRebar3Version, + mixRebar: mixRebar, + mixHex: mixHex, }