Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR to test distro check fix #13

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {},
"rules": {
"no-unused-vars": "off"
},
"ignorePatterns": ["dist", "coverage", "*.md", "*.yml", "*.yaml"]
}
23 changes: 23 additions & 0 deletions __test__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe("workflow test with a valid distro input", () => {
beforeAll(() => {
jest.spyOn(exec, "exec").mockImplementation(jest.fn());
jest.spyOn(core, "getInput").mockReturnValue("harmonic");
jest
.spyOn(utils, "determineDistribCodename")
.mockReturnValue(Promise.resolve("jammy"));
});

afterAll(() => {
Expand Down Expand Up @@ -95,6 +98,23 @@ describe("validate distribution test", () => {
});
});

describe("workflow test with incompatible Ubuntu combination", () => {
beforeAll(() => {
jest.spyOn(exec, "exec").mockImplementation(jest.fn());
jest.spyOn(core, "getInput").mockReturnValue("harmonic");
jest
.spyOn(utils, "determineDistribCodename")
.mockReturnValue(Promise.resolve("focal"));
});
afterAll(() => {
jest.resetAllMocks();
});

it("run Linux workflow with incompatible Ubuntu combination", async () => {
await expect(linux.runLinux()).rejects.toThrow();
});
});

describe("check for unstable repositories input", () => {
beforeAll(() => {
jest.spyOn(exec, "exec").mockImplementation(jest.fn());
Expand All @@ -108,6 +128,9 @@ describe("check for unstable repositories input", () => {
.spyOn(utils, "checkForUnstableAptRepos")
.mockReturnValueOnce(["prerelease", "nightly"]);
jest.spyOn(core, "getInput").mockReturnValue("harmonic");
jest
.spyOn(utils, "determineDistribCodename")
.mockReturnValue(Promise.resolve("jammy"));
});

afterAll(() => {
Expand Down
71 changes: 63 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26487,6 +26487,8 @@ function runLinux() {
// Add repo according to Ubuntu version
const ubuntuCodename = yield utils.determineDistribCodename();
yield addAptRepo(ubuntuCodename);
const gazeboDistros = utils.getRequiredGazeboDistributions();
utils.checkUbuntuCompatibility(gazeboDistros, ubuntuCodename);
for (const gazeboDistro of utils.getRequiredGazeboDistributions()) {
yield apt.runAptGetInstall([`gz-${gazeboDistro}`]);
}
Expand Down Expand Up @@ -26786,9 +26788,50 @@ exports.exec = exec;
exports.determineDistribCodename = determineDistribCodename;
exports.validateDistro = validateDistro;
exports.getRequiredGazeboDistributions = getRequiredGazeboDistributions;
exports.checkUbuntuCompatibility = checkUbuntuCompatibility;
exports.checkForUnstableAptRepos = checkForUnstableAptRepos;
const actions_exec = __importStar(__nccwpck_require__(1514));
const core = __importStar(__nccwpck_require__(2186));
// Enum of Gazebo distributions
var gazeboDistro;
(function (gazeboDistro) {
gazeboDistro["CITADEL"] = "citadel";
gazeboDistro["FORTRESS"] = "fortress";
gazeboDistro["GARDEN"] = "garden";
gazeboDistro["HARMONIC"] = "harmonic";
gazeboDistro["IONIC"] = "ionic";
})(gazeboDistro || (gazeboDistro = {}));
// Enum of Ubuntu distributions
var ubuntuDistro;
(function (ubuntuDistro) {
ubuntuDistro["FOCAL"] = "focal";
ubuntuDistro["JAMMY"] = "jammy";
ubuntuDistro["NOBLE"] = "noble";
})(ubuntuDistro || (ubuntuDistro = {}));
// List of Valid Gazebo distributions with compatible
// Ubuntu distributions
const validGazeboDistroList = [
{
name: gazeboDistro.CITADEL,
compatibleUbuntuDistros: [ubuntuDistro.FOCAL],
},
{
name: gazeboDistro.FORTRESS,
compatibleUbuntuDistros: [ubuntuDistro.FOCAL, ubuntuDistro.JAMMY],
},
{
name: gazeboDistro.GARDEN,
compatibleUbuntuDistros: [ubuntuDistro.FOCAL, ubuntuDistro.JAMMY],
},
{
name: gazeboDistro.HARMONIC,
compatibleUbuntuDistros: [ubuntuDistro.JAMMY, ubuntuDistro.NOBLE],
},
{
name: gazeboDistro.IONIC,
compatibleUbuntuDistros: [ubuntuDistro.NOBLE],
},
];
/**
* Execute a command and wrap the output in a log group.
*
Expand Down Expand Up @@ -26828,21 +26871,14 @@ function determineDistribCodename() {
return distribCodename;
});
}
// List of valid Gazebo distributions
const validDistro = [
"citadel",
"fortress",
"garden",
"harmonic",
"ionic",
];
/**
* Validate all Gazebo input distribution names
*
* @param requiredGazeboDistributionsList
* @returns boolean Validity of Gazebo distribution
*/
function validateDistro(requiredGazeboDistributionsList) {
const validDistro = Object.values(gazeboDistro);
for (const gazeboDistro of requiredGazeboDistributionsList) {
if (validDistro.indexOf(gazeboDistro) <= -1) {
return false;
Expand Down Expand Up @@ -26870,6 +26906,25 @@ function getRequiredGazeboDistributions() {
}
return requiredGazeboDistributionsList;
}
/**
* Check the compatability of the Ubuntu version against the
* Gazebo distribution. Throws an error if incompatible
* combination found
*
* @param requiredGazeboDistributionsList
* @param ubuntuCodename
*/
function checkUbuntuCompatibility(requiredGazeboDistributionsList, ubuntuCodename) {
requiredGazeboDistributionsList.forEach((element) => {
const idx = validGazeboDistroList.findIndex((obj) => {
return obj.name === element;
});
const compatibleUbuntuList = Object.values(validGazeboDistroList[idx].compatibleUbuntuDistros);
if (compatibleUbuntuList.indexOf(ubuntuCodename) <= -1) {
throw new Error("Incompatible Gazebo and Ubuntu combination.");
}
});
}
/**
* Check for unstable repository inputs
*
Expand Down
4 changes: 4 additions & 0 deletions src/setup-gazebo-linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export async function runLinux(): Promise<void> {
const ubuntuCodename = await utils.determineDistribCodename();
await addAptRepo(ubuntuCodename);

const gazeboDistros = utils.getRequiredGazeboDistributions();

utils.checkUbuntuCompatibility(gazeboDistros, ubuntuCodename);

for (const gazeboDistro of utils.getRequiredGazeboDistributions()) {
await apt.runAptGetInstall([`gz-${gazeboDistro}`]);
}
Expand Down
79 changes: 70 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@ import * as actions_exec from "@actions/exec";
import * as core from "@actions/core";
import * as im from "@actions/exec/lib/interfaces";

// Enum of Gazebo distributions
enum gazeboDistro {
CITADEL = "citadel",
FORTRESS = "fortress",
GARDEN = "garden",
HARMONIC = "harmonic",
IONIC = "ionic",
}

// Enum of Ubuntu distributions
enum ubuntuDistro {
FOCAL = "focal",
JAMMY = "jammy",
NOBLE = "noble",
}

// List of Valid Gazebo distributions with compatible
// Ubuntu distributions
const validGazeboDistroList: {
name: gazeboDistro;
compatibleUbuntuDistros: ubuntuDistro[];
}[] = [
{
name: gazeboDistro.CITADEL,
compatibleUbuntuDistros: [ubuntuDistro.FOCAL],
},
{
name: gazeboDistro.FORTRESS,
compatibleUbuntuDistros: [ubuntuDistro.FOCAL, ubuntuDistro.JAMMY],
},
{
name: gazeboDistro.GARDEN,
compatibleUbuntuDistros: [ubuntuDistro.FOCAL, ubuntuDistro.JAMMY],
},
{
name: gazeboDistro.HARMONIC,
compatibleUbuntuDistros: [ubuntuDistro.JAMMY, ubuntuDistro.NOBLE],
},
{
name: gazeboDistro.IONIC,
compatibleUbuntuDistros: [ubuntuDistro.NOBLE],
},
];

/**
* Execute a command and wrap the output in a log group.
*
Expand Down Expand Up @@ -48,15 +92,6 @@ export async function determineDistribCodename(): Promise<string> {
return distribCodename;
}

// List of valid Gazebo distributions
const validDistro: string[] = [
"citadel",
"fortress",
"garden",
"harmonic",
"ionic",
];

/**
* Validate all Gazebo input distribution names
*
Expand All @@ -66,6 +101,7 @@ const validDistro: string[] = [
export function validateDistro(
requiredGazeboDistributionsList: string[],
): boolean {
const validDistro: string[] = Object.values(gazeboDistro);
for (const gazeboDistro of requiredGazeboDistributionsList) {
if (validDistro.indexOf(gazeboDistro) <= -1) {
return false;
Expand Down Expand Up @@ -98,6 +134,31 @@ export function getRequiredGazeboDistributions(): string[] {
return requiredGazeboDistributionsList;
}

/**
* Check the compatability of the Ubuntu version against the
* Gazebo distribution. Throws an error if incompatible
* combination found
*
* @param requiredGazeboDistributionsList
* @param ubuntuCodename
*/
export function checkUbuntuCompatibility(
requiredGazeboDistributionsList: string[],
ubuntuCodename: string,
) {
requiredGazeboDistributionsList.forEach((element) => {
const idx = validGazeboDistroList.findIndex((obj) => {
return obj.name === element;
});
const compatibleUbuntuList: string[] = Object.values(
validGazeboDistroList[idx].compatibleUbuntuDistros,
);
if (compatibleUbuntuList.indexOf(ubuntuCodename) <= -1) {
throw new Error("Incompatible Gazebo and Ubuntu combination.");
}
});
}

/**
* Check for unstable repository inputs
*
Expand Down
Loading