Skip to content

Commit

Permalink
Added Ubuntu/Gazebo combination check to throw an early warning (#44)
Browse files Browse the repository at this point in the history
* Added ubuntu/gazebo combination check
* Added test for ubuntu check
* Changed gz-ubuntu combination object from enums to strings

---------
Signed-off-by: Saurabh Kamat <[email protected]>
  • Loading branch information
sauk2 authored Jul 29, 2024
1 parent 0ba2bb0 commit 2d5a3ea
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 18 deletions.
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
54 changes: 46 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,34 @@ 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));
// List of Valid Gazebo distributions with compatible
// Ubuntu distributions
const validGazeboDistroList = [
{
name: "citadel",
compatibleUbuntuDistros: ["focal"],
},
{
name: "fortress",
compatibleUbuntuDistros: ["focal", "jammy"],
},
{
name: "garden",
compatibleUbuntuDistros: ["focal", "jammy"],
},
{
name: "harmonic",
compatibleUbuntuDistros: ["jammy", "noble"],
},
{
name: "ionic",
compatibleUbuntuDistros: ["noble"],
},
];
/**
* Execute a command and wrap the output in a log group.
*
Expand Down Expand Up @@ -26828,21 +26855,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 = validGazeboDistroList.map((obj) => obj.name);
for (const gazeboDistro of requiredGazeboDistributionsList) {
if (validDistro.indexOf(gazeboDistro) <= -1) {
return false;
Expand Down Expand Up @@ -26870,6 +26890,24 @@ 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 compatibleDistros = validGazeboDistroList.find((obj) => obj.name === element).compatibleUbuntuDistros;
if (compatibleDistros.indexOf(ubuntuCodename) <= -1) {
throw new Error("Incompatible Gazebo and Ubuntu combination. \
All compatible combinations can be found at \
https://gazebosim.org/docs/latest/getstarted/#step-1-install");
}
});
}
/**
* 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
64 changes: 55 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@ import * as actions_exec from "@actions/exec";
import * as core from "@actions/core";
import * as im from "@actions/exec/lib/interfaces";

// List of Valid Gazebo distributions with compatible
// Ubuntu distributions
const validGazeboDistroList: {
name: string;
compatibleUbuntuDistros: string[];
}[] = [
{
name: "citadel",
compatibleUbuntuDistros: ["focal"],
},
{
name: "fortress",
compatibleUbuntuDistros: ["focal", "jammy"],
},
{
name: "garden",
compatibleUbuntuDistros: ["focal", "jammy"],
},
{
name: "harmonic",
compatibleUbuntuDistros: ["jammy", "noble"],
},
{
name: "ionic",
compatibleUbuntuDistros: ["noble"],
},
];

/**
* Execute a command and wrap the output in a log group.
*
Expand Down Expand Up @@ -48,15 +76,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 +85,7 @@ const validDistro: string[] = [
export function validateDistro(
requiredGazeboDistributionsList: string[],
): boolean {
const validDistro: string[] = validGazeboDistroList.map((obj) => obj.name);
for (const gazeboDistro of requiredGazeboDistributionsList) {
if (validDistro.indexOf(gazeboDistro) <= -1) {
return false;
Expand Down Expand Up @@ -98,6 +118,32 @@ 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 compatibleDistros = validGazeboDistroList.find(
(obj) => obj.name === element,
)!.compatibleUbuntuDistros;
if (compatibleDistros.indexOf(ubuntuCodename) <= -1) {
throw new Error(
"Incompatible Gazebo and Ubuntu combination. \
All compatible combinations can be found at \
https://gazebosim.org/docs/latest/getstarted/#step-1-install",
);
}
});
}

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

0 comments on commit 2d5a3ea

Please sign in to comment.