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

run either apt or dnf update with or without sudo #881

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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
36 changes: 33 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30701,7 +30701,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = exports.validateDistros = exports.execShellCommand = exports.filterNonEmptyJoin = void 0;
exports.run = exports.determineDistrib = exports.validateDistros = exports.execShellCommand = exports.filterNonEmptyJoin = void 0;
const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
const tr = __importStar(__nccwpck_require__(8159));
Expand Down Expand Up @@ -30841,6 +30841,25 @@ function validateDistros(ros1Distro, ros2Distro) {
return true;
}
exports.validateDistros = validateDistros;
/**
* Determines the Linux distribution.
*
* @returns Promise<string> Linux distribution (e.g. "ubuntu")
*/
function determineDistrib() {
return __awaiter(this, void 0, void 0, function* () {
let distrib = "";
const options = {};
options.listeners = {
stdout: (data) => {
distrib += data.toString();
},
};
yield execShellCommand(['source /etc/os-release ; echo -n "$ID"'], options);
return distrib;
});
}
exports.determineDistrib = determineDistrib;
/**
* Install ROS dependencies for given packages in the workspace, for all ROS distros being used.
*/
Expand Down Expand Up @@ -31153,8 +31172,19 @@ done`;
// Print HEAD commits of all repos
yield execShellCommand(["vcs log -l1 src/"], options);
if (isLinux) {
// Always update APT before installing packages on Ubuntu
yield execShellCommand(["sudo apt-get update"]);
// Always update package index before installing packages
const dist = yield determineDistrib();
if (dist === "ubuntu") {
yield execShellCommand(["apt update || sudo apt update"]);
}
else if (dist === "almalinux" || dist === "rocky") {
yield execShellCommand([
"dnf check-update || sudo dnf check-update || true",
]);
}
else {
core.setFailed(`Unsupported distribution ${dist}`);
}
}
// rosdep does not really work on Windows, so do not use it
// See: https://github.com/ros-infrastructure/rosdep/issues/610
Expand Down
30 changes: 28 additions & 2 deletions src/action-ros-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ export function validateDistros(
return true;
}

/**
* Determines the Linux distribution.
*
* @returns Promise<string> Linux distribution (e.g. "ubuntu")
*/
export async function determineDistrib(): Promise<string> {
let distrib = "";
const options: im.ExecOptions = {};
options.listeners = {
stdout: (data: Buffer) => {
distrib += data.toString();
},
};
await execShellCommand(['source /etc/os-release ; echo -n "$ID"'], options);
return distrib;
}

/**
* Install ROS dependencies for given packages in the workspace, for all ROS distros being used.
*/
Expand Down Expand Up @@ -629,8 +646,17 @@ done`;
await execShellCommand(["vcs log -l1 src/"], options);

if (isLinux) {
// Always update APT before installing packages on Ubuntu
await execShellCommand(["sudo apt-get update"]);
// Always update package index before installing packages
const dist: string = await determineDistrib();
if (dist === "ubuntu") {
await execShellCommand(["apt update || sudo apt update"]);
} else if (dist === "almalinux" || dist === "rocky") {
await execShellCommand([
"dnf check-update || sudo dnf check-update || true",
]);
} else {
core.setFailed(`Unsupported distribution ${dist}`);
}
}
// rosdep does not really work on Windows, so do not use it
// See: https://github.com/ros-infrastructure/rosdep/issues/610
Expand Down
Loading