Skip to content

Commit

Permalink
Added action to configure linux distro
Browse files Browse the repository at this point in the history
Signed-off-by: Saurabh Kamat <[email protected]>
  • Loading branch information
sauk2 committed Jun 1, 2024
1 parent bfceebd commit 6949e68
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 0 deletions.
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'Setup Gazebo release'
description: |
Install a Gazebo release on a Linux system
runs:
using: node20
main: dist/index.js
28 changes: 28 additions & 0 deletions src/package_manager/apt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as utils from "../utils";

const aptCommandLine: string[] = [
"DEBIAN_FRONTEND=noninteractive",
"RTI_NC_LICENSE_ACCEPTED=yes",
"apt-get",
"install",
"--no-install-recommends",
"--quiet",
"--yes",
];

/**
* Run apt-get install on list of specified packages.
*
* This invokation guarantees that APT install will be non-blocking.
*
* In particular, it automatically accepts the RTI Connext license, which would block forever otherwise.
* Skipping the license agreement page requires RTI_NC_LICENSE_ACCEPTED to be set to "yes".
* This package would normally be installed automatically by rosdep, but
* there is no way to pass RTI_NC_LICENSE_ACCEPTED through rosdep.
*
* @param packages list of Debian pacakges to be installed
* @returns Promise<number> exit code
*/
export async function runAptGetInstall(packages: string[]): Promise<number> {
return utils.exec("sudo", aptCommandLine.concat(packages));
}
58 changes: 58 additions & 0 deletions src/setup-gazebo-linux.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as core from "@actions/core";
import * as io from "@actions/io";

import * as apt from "./package_manager/apt";
import * as utils from "./utils";

import * as path from "path";
import fs from "fs";

/**
* Configure basic OS stuff.
*/
async function configOs(): Promise<void> {
// When this action runs in a Docker image, sudo may be missing.
// This installs sudo to avoid having to handle both cases (action runs as
// root, action does not run as root) everywhere in the action.
try {
await io.which("sudo", true);
} catch (err) {
await utils.exec("apt-get", ["update"]);
await utils.exec("apt-get", [
"install",
"--no-install-recommends",
"--quiet",
"--yes",
"sudo",
]);
}

await utils.exec("sudo", ["bash", "-c", "echo 'Etc/UTC' > /etc/timezone"]);
await utils.exec("sudo", ["apt-get", "update"]);

// Install tools required to configure the worker system.
await apt.runAptGetInstall(["curl", "gnupg2", "locales", "lsb-release"]);

// Select a locale supporting Unicode.
await utils.exec("sudo", ["locale-gen", "en_US", "en_US.UTF-8"]);
core.exportVariable("LANG", "en_US.UTF-8");

// Enforce UTC time for consistency.
await utils.exec("sudo", ["bash", "-c", "echo 'Etc/UTC' > /etc/timezone"]);
await utils.exec("sudo", [
"ln",
"-sf",
"/usr/share/zoneinfo/Etc/UTC",
"/etc/localtime",
]);
await apt.runAptGetInstall(["tzdata"]);
}

/**
* Install Gazebo on a Linux worker.
*/
export async function runLinux(): Promise<void> {

await configOs();

}
17 changes: 17 additions & 0 deletions src/setup-gazebo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as core from "@actions/core";
import * as linux from "./setup-gazebo-linux";

async function run() {
try {
linux.runLinux();
}
catch (error) {
let errorMessage = "Unknown error";
if (error instanceof Error) {
errorMessage = error.message;
}
core.setFailed(errorMessage);
}
}

run();
49 changes: 49 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as actions_exec from "@actions/exec";
import * as core from "@actions/core";
import * as im from "@actions/exec/lib/interfaces";

/**
* Execute a command and wrap the output in a log group.
*
* @param commandLine command to execute (can include additional args). Must be correctly escaped.
* @param args optional arguments for tool. Escaping is handled by the lib.
* @param options optional exec options. See ExecOptions
* @param log_message log group title.
* @returns Promise<number> exit code
*/
export async function exec(
commandLine: string,
args?: string[],
options?: im.ExecOptions,
log_message?: string,
): Promise<number> {
const argsAsString = (args || []).join(" ");
const message = log_message || `Invoking "${commandLine} ${argsAsString}"`;
return core.group(message, () => {
return actions_exec.exec(commandLine, args, options);
});
}

/**
* Determines the Ubuntu distribution codename.
*
* This function directly source /etc/lsb-release instead of invoking
* lsb-release as the package may not be installed.
*
* @returns Promise<string> Ubuntu distribution codename (e.g. "focal")
*/
export async function determineDistribCodename(): Promise<string> {
let distribCodename = "";
const options: im.ExecOptions = {};
options.listeners = {
stdout: (data: Buffer) => {
distribCodename += data.toString();
},
};
await exec(
"bash",
["-c", 'source /etc/lsb-release ; echo -n "$DISTRIB_CODENAME"'],
options,
);
return distribCodename;
}

0 comments on commit 6949e68

Please sign in to comment.