-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added action to configure linux distro
Signed-off-by: Saurabh Kamat <[email protected]>
- Loading branch information
Showing
5 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |