Skip to content

Commit

Permalink
Exit process after running, workaround for #236
Browse files Browse the repository at this point in the history
  • Loading branch information
jurplel committed May 19, 2024
1 parent 72c56a4 commit 45ea618
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 172 deletions.
14 changes: 7 additions & 7 deletions action/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

328 changes: 163 additions & 165 deletions action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,190 +281,188 @@ class Inputs {
}
}

const run = async (): Promise<void> => {
try {
const inputs = new Inputs();

// Qt installer assumes basic requirements that are not installed by
// default on Ubuntu.
if (process.platform === "linux") {
if (inputs.installDeps) {
const dependencies = [
"build-essential",
"libgl1-mesa-dev",
"libgstreamer-gl1.0-0",
"libpulse-dev",
"libxcb-glx0",
"libxcb-icccm4",
"libxcb-image0",
"libxcb-keysyms1",
"libxcb-randr0",
"libxcb-render-util0",
"libxcb-render0",
"libxcb-shape0",
"libxcb-shm0",
"libxcb-sync1",
"libxcb-util1",
"libxcb-xfixes0",
"libxcb-xinerama0",
"libxcb1",
"libxkbcommon-dev",
"libxkbcommon-x11-0",
"libxcb-xkb-dev",
];

// Qt 6.5.0 adds this requirement:
// https://code.qt.io/cgit/qt/qtreleasenotes.git/about/qt/6.5.0/release-note.md
if (compareVersions(inputs.version, ">=", "6.5.0")) {
dependencies.push("libxcb-cursor0");
}

const updateCommand = "apt-get update";
const installCommand = `apt-get install ${dependencies.join(" ")} -y`;
if (inputs.installDeps === "nosudo") {
await exec(updateCommand);
await exec(installCommand);
} else {
await exec(`sudo ${updateCommand}`);
await exec(`sudo ${installCommand}`);
}
async function run(): Promise<void> {

Check failure on line 284 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Expected a function expression
const inputs = new Inputs();

// Qt installer assumes basic requirements that are not installed by
// default on Ubuntu.
if (process.platform === "linux") {
if (inputs.installDeps) {
const dependencies = [
"build-essential",
"libgl1-mesa-dev",
"libgstreamer-gl1.0-0",
"libpulse-dev",
"libxcb-glx0",
"libxcb-icccm4",
"libxcb-image0",
"libxcb-keysyms1",
"libxcb-randr0",
"libxcb-render-util0",
"libxcb-render0",
"libxcb-shape0",
"libxcb-shm0",
"libxcb-sync1",
"libxcb-util1",
"libxcb-xfixes0",
"libxcb-xinerama0",
"libxcb1",
"libxkbcommon-dev",
"libxkbcommon-x11-0",
"libxcb-xkb-dev",
];

// Qt 6.5.0 adds this requirement:
// https://code.qt.io/cgit/qt/qtreleasenotes.git/about/qt/6.5.0/release-note.md
if (compareVersions(inputs.version, ">=", "6.5.0")) {
dependencies.push("libxcb-cursor0");
}
}

// Restore internal cache
let internalCacheHit = false;
if (inputs.cache) {
const cacheHitKey = await cache.restoreCache([inputs.dir], inputs.cacheKey);
if (cacheHitKey) {
core.info(`Automatic cache hit with key "${cacheHitKey}"`);
internalCacheHit = true;
const updateCommand = "apt-get update";
const installCommand = `apt-get install ${dependencies.join(" ")} -y`;
if (inputs.installDeps === "nosudo") {
await exec(updateCommand);
await exec(installCommand);
} else {
core.info("Automatic cache miss, will cache this run");
await exec(`sudo ${updateCommand}`);
await exec(`sudo ${installCommand}`);
}
}
}

// Install Qt and tools if not cached
if (!internalCacheHit) {
// 7-zip is required, and not included on macOS
if (process.platform === "darwin") {
await exec("brew install p7zip");
}
// Restore internal cache
let internalCacheHit = false;
if (inputs.cache) {
const cacheHitKey = await cache.restoreCache([inputs.dir], inputs.cacheKey);
if (cacheHitKey) {
core.info(`Automatic cache hit with key "${cacheHitKey}"`);
internalCacheHit = true;
} else {
core.info("Automatic cache miss, will cache this run");
}
}

// Install dependencies via pip
await execPython("pip install", ["setuptools", "wheel", `"py7zr${inputs.py7zrVersion}"`]);
// Install Qt and tools if not cached
if (!internalCacheHit) {
// 7-zip is required, and not included on macOS
if (process.platform === "darwin") {
await exec("brew install p7zip");
}

// Install aqtinstall separately: allows aqtinstall to override py7zr if required
if (inputs.aqtSource.length > 0) {
await execPython("pip install", [`"${inputs.aqtSource}"`]);
} else {
await execPython("pip install", [`"aqtinstall${inputs.aqtVersion}"`]);
}
// Install dependencies via pip
await execPython("pip install", ["setuptools", "wheel", `"py7zr${inputs.py7zrVersion}"`]);

// This flag will install a parallel desktop version of Qt, only where required.
// aqtinstall will automatically determine if this is necessary.
const autodesktop = (await isAutodesktopSupported()) ? ["--autodesktop"] : [];

// Install Qt
if (inputs.isInstallQtBinaries) {
const qtArgs = [
inputs.host,
inputs.target,
inputs.version,
...(inputs.arch ? [inputs.arch] : []),
...autodesktop,
...["--outputdir", inputs.dir],
...flaggedList("--modules", inputs.modules),
...flaggedList("--archives", inputs.archives),
...inputs.extra,
];

await execPython("aqt install-qt", qtArgs);
}
// Install aqtinstall separately: allows aqtinstall to override py7zr if required
if (inputs.aqtSource.length > 0) {
await execPython("pip install", [`"${inputs.aqtSource}"`]);
} else {
await execPython("pip install", [`"aqtinstall${inputs.aqtVersion}"`]);
}

const installSrcDocExamples = async (
flavor: "src" | "doc" | "example",
archives: readonly string[],
modules: readonly string[]
): Promise<void> => {
const qtArgs = [
inputs.host,
// Aqtinstall < 2.0.4 requires `inputs.target` here, but that's deprecated
inputs.version,
...["--outputdir", inputs.dir],
...flaggedList("--archives", archives),
...flaggedList("--modules", modules),
...inputs.extra,
];
await execPython(`aqt install-${flavor}`, qtArgs);
};

// Install source, docs, & examples
if (inputs.src) {
await installSrcDocExamples("src", inputs.srcArchives, []);
}
if (inputs.doc) {
await installSrcDocExamples("doc", inputs.docArchives, inputs.docModules);
}
if (inputs.example) {
await installSrcDocExamples("example", inputs.exampleArchives, inputs.exampleModules);
}
// This flag will install a parallel desktop version of Qt, only where required.
// aqtinstall will automatically determine if this is necessary.
const autodesktop = (await isAutodesktopSupported()) ? ["--autodesktop"] : [];

// Install tools
for (const tool of inputs.tools) {
const toolArgs = [inputs.host, inputs.target, tool];
toolArgs.push("--outputdir", inputs.dir);
toolArgs.push(...inputs.extra);
await execPython("aqt install-tool", toolArgs);
}
// Install Qt
if (inputs.isInstallQtBinaries) {
const qtArgs = [
inputs.host,
inputs.target,
inputs.version,
...(inputs.arch ? [inputs.arch] : []),
...autodesktop,
...["--outputdir", inputs.dir],
...flaggedList("--modules", inputs.modules),
...flaggedList("--archives", inputs.archives),
...inputs.extra,
];

await execPython("aqt install-qt", qtArgs);
}

// Save automatic cache
if (!internalCacheHit && inputs.cache) {
const cacheId = await cache.saveCache([inputs.dir], inputs.cacheKey);
core.info(`Automatic cache saved with id ${cacheId}`);
const installSrcDocExamples = async (
flavor: "src" | "doc" | "example",
archives: readonly string[],
modules: readonly string[]
): Promise<void> => {
const qtArgs = [
inputs.host,
// Aqtinstall < 2.0.4 requires `inputs.target` here, but that's deprecated
inputs.version,
...["--outputdir", inputs.dir],
...flaggedList("--archives", archives),
...flaggedList("--modules", modules),
...inputs.extra,
];
await execPython(`aqt install-${flavor}`, qtArgs);
};

// Install source, docs, & examples
if (inputs.src) {
await installSrcDocExamples("src", inputs.srcArchives, []);
}

// Add tools to path
if (inputs.addToolsToPath && inputs.tools.length) {
toolsPaths(inputs.dir).map(nativePath).forEach(core.addPath);
if (inputs.doc) {
await installSrcDocExamples("doc", inputs.docArchives, inputs.docModules);
}
if (inputs.example) {
await installSrcDocExamples("example", inputs.exampleArchives, inputs.exampleModules);
}

// Set environment variables/outputs for tools
if (inputs.tools.length && inputs.setEnv) {
core.exportVariable("IQTA_TOOLS", nativePath(`${inputs.dir}/Tools`));
// Install tools
for (const tool of inputs.tools) {
const toolArgs = [inputs.host, inputs.target, tool];
toolArgs.push("--outputdir", inputs.dir);
toolArgs.push(...inputs.extra);
await execPython("aqt install-tool", toolArgs);
}
// Set environment variables/outputs for binaries
if (inputs.isInstallQtBinaries) {
const qtPath = nativePath(locateQtArchDir(inputs.dir));
// Set outputs
core.setOutput("qtPath", qtPath);

// Set env variables
if (inputs.setEnv) {
if (process.platform === "linux") {
setOrAppendEnvVar("LD_LIBRARY_PATH", nativePath(`${qtPath}/lib`));
}
if (process.platform !== "win32") {
setOrAppendEnvVar("PKG_CONFIG_PATH", nativePath(`${qtPath}/lib/pkgconfig`));
}
// If less than qt6, set Qt5_DIR variable
if (compareVersions(inputs.version, "<", "6.0.0")) {
core.exportVariable("Qt5_DIR", nativePath(`${qtPath}/lib/cmake`));
}
core.exportVariable("QT_ROOT_DIR", qtPath);
core.exportVariable("QT_PLUGIN_PATH", nativePath(`${qtPath}/plugins`));
core.exportVariable("QML2_IMPORT_PATH", nativePath(`${qtPath}/qml`));
core.addPath(nativePath(`${qtPath}/bin`));
}

// Save automatic cache
if (!internalCacheHit && inputs.cache) {
const cacheId = await cache.saveCache([inputs.dir], inputs.cacheKey);
core.info(`Automatic cache saved with id ${cacheId}`);
}

// Add tools to path
if (inputs.addToolsToPath && inputs.tools.length) {
toolsPaths(inputs.dir).map(nativePath).forEach(core.addPath);
}

// Set environment variables/outputs for tools
if (inputs.tools.length && inputs.setEnv) {
core.exportVariable("IQTA_TOOLS", nativePath(`${inputs.dir}/Tools`));
}
// Set environment variables/outputs for binaries
if (inputs.isInstallQtBinaries) {
const qtPath = nativePath(locateQtArchDir(inputs.dir));
// Set outputs
core.setOutput("qtPath", qtPath);

// Set env variables
if (inputs.setEnv) {
if (process.platform === "linux") {
setOrAppendEnvVar("LD_LIBRARY_PATH", nativePath(`${qtPath}/lib`));
}
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(error);
} else {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
core.setFailed(`unknown error: ${error}`);
if (process.platform !== "win32") {
setOrAppendEnvVar("PKG_CONFIG_PATH", nativePath(`${qtPath}/lib/pkgconfig`));
}
// If less than qt6, set Qt5_DIR variable
if (compareVersions(inputs.version, "<", "6.0.0")) {
core.exportVariable("Qt5_DIR", nativePath(`${qtPath}/lib/cmake`));
}
core.exportVariable("QT_ROOT_DIR", qtPath);
core.exportVariable("QT_PLUGIN_PATH", nativePath(`${qtPath}/plugins`));
core.exportVariable("QML2_IMPORT_PATH", nativePath(`${qtPath}/qml`));
core.addPath(nativePath(`${qtPath}/bin`));
}
}
};

Check failure on line 459 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

void run();
run()

Check failure on line 461 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
.catch(err => {

Check failure on line 462 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `err` with `(err)`
core.setFailed(err.message)

Check failure on line 463 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe argument of type `any` assigned to a parameter of type `string | Error`

Check failure on line 463 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .message on an `any` value

Check failure on line 463 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
process.exit(1)

Check failure on line 464 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
})
.then(() => {
process.exit(0)

Check failure on line 467 in action/src/main.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
});

0 comments on commit 45ea618

Please sign in to comment.