diff --git a/.eslintrc.json b/.eslintrc.json index 012ac01..69d2c32 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -19,6 +19,8 @@ "sourceType": "module" }, "plugins": ["@typescript-eslint"], - "rules": {}, + "rules": { + "no-unused-vars": "off" + }, "ignorePatterns": ["dist", "coverage", "*.md", "*.yml", "*.yaml"] } diff --git a/__test__/main.test.ts b/__test__/main.test.ts index a1023df..bd1b500 100644 --- a/__test__/main.test.ts +++ b/__test__/main.test.ts @@ -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(() => { @@ -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()); @@ -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(() => { diff --git a/dist/index.js b/dist/index.js index 72f290e..d3fb151 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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}`]); } @@ -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. * @@ -26828,14 +26855,6 @@ function determineDistribCodename() { return distribCodename; }); } -// List of valid Gazebo distributions -const validDistro = [ - "citadel", - "fortress", - "garden", - "harmonic", - "ionic", -]; /** * Validate all Gazebo input distribution names * @@ -26843,6 +26862,7 @@ const validDistro = [ * @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; @@ -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 * diff --git a/src/setup-gazebo-linux.ts b/src/setup-gazebo-linux.ts index 1eb8b44..9595bea 100644 --- a/src/setup-gazebo-linux.ts +++ b/src/setup-gazebo-linux.ts @@ -103,6 +103,10 @@ export async function runLinux(): Promise { 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}`]); } diff --git a/src/utils.ts b/src/utils.ts index 7c62625..1af41bf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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. * @@ -48,15 +76,6 @@ export async function determineDistribCodename(): Promise { return distribCodename; } -// List of valid Gazebo distributions -const validDistro: string[] = [ - "citadel", - "fortress", - "garden", - "harmonic", - "ionic", -]; - /** * Validate all Gazebo input distribution names * @@ -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; @@ -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 *