Skip to content
This repository was archived by the owner on Oct 27, 2022. It is now read-only.

Commit 6e7f687

Browse files
committed
improve input parsing
1 parent 2d620bc commit 6e7f687

File tree

10 files changed

+414
-310
lines changed

10 files changed

+414
-310
lines changed

action.yml

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,51 @@
1-
name: 'Setup Qt environment'
2-
description: 'Setup Qt by using the prebuilt binaries the Qt-Company provides'
3-
author: 'Skycoder42'
4-
inputs:
5-
version:
6-
description: 'The Qt version to download and install. Example: 5.13.1'
7-
required: true
8-
platform:
9-
description: 'A version dependend platform package to be installed. Example: gcc_64'
10-
required: true
11-
packages:
12-
description: 'A comma seperated list of additional packages to be installed. Example: qtnetworkauth,qtwebengine,qt.tools.ifw.32'
13-
required: false
14-
default: ''
15-
deep-sources:
16-
description: 'A space seperated list of additional URLs to download modules from. Modules should be layed out as "<url>/<os>_<arch>/<type>/qt5_qt<version>/<module>"'
17-
required: false
18-
default: ''
19-
flat-sources:
20-
description: 'A space seperated list of additional URLs to download modules from. Modules should be layed out as "<url>/<os>_<arch>/qt<version>/<module>"'
21-
required: false
22-
default: ''
23-
clean:
24-
description: 'Perform a clean installation, ignoring any caches'
25-
required: false
26-
default: 'false'
27-
outputs:
28-
shell:
29-
description: 'The shell that should be used to run qmake/make commands'
30-
make:
31-
description: 'Name of the "make" executable to be used, i.e. name, nmake or mingw32-make'
32-
tests:
33-
description: 'Set to true if tests should be run, false otherwise'
34-
testflags:
35-
description: 'makeflags to be used when running tests'
36-
qtdir:
37-
description: 'The path where qt was installed'
38-
installdir:
39-
description: 'The path to install stuff to before packing them as artifact'
40-
outdir:
41-
description: 'The path where installed files go after installing to installdir'
42-
runs:
43-
using: 'node12'
44-
main: 'lib/setup-qt.js'
45-
1+
name: "Setup Qt environment"
2+
description: "Setup Qt by using the prebuilt binaries the Qt-Company provides"
3+
author: "Skycoder42"
4+
inputs:
5+
version:
6+
description: "The Qt version to download and install. Example: 5.13.1"
7+
required: true
8+
platform:
9+
description: "A version dependend platform package to be installed. Example: gcc_64"
10+
required: true
11+
packages:
12+
description: "A comma seperated list of additional packages to be installed. Example: qtnetworkauth,qtwebengine,qt.tools.ifw.32"
13+
required: false
14+
default: ""
15+
deep-sources:
16+
description: 'A space seperated list of additional URLs to download modules from. Modules should be layed out as "<url>/<os>_<arch>/<type>/qt5_qt<version>/<module>"'
17+
required: false
18+
default: ""
19+
flat-sources:
20+
description: 'A space seperated list of additional URLs to download modules from. Modules should be layed out as "<url>/<os>_<arch>/qt<version>/<module>"'
21+
required: false
22+
default: ""
23+
cache-mode:
24+
description: 'Specify the cache mode. Must be one of "default", "none", "post"'
25+
required: false
26+
default: "default"
27+
clean:
28+
description: "Perform a clean installation, ignoring any caches"
29+
required: false
30+
default: "false"
31+
outputs:
32+
shell:
33+
description: "The shell that should be used to run qmake/make commands"
34+
make:
35+
description: 'Name of the "make" executable to be used, i.e. name, nmake or mingw32-make'
36+
tests:
37+
description: "Set to true if tests should be run, false otherwise"
38+
testflags:
39+
description: "makeflags to be used when running tests"
40+
qtdir:
41+
description: "The path where qt was installed"
42+
installdir:
43+
description: "The path to install stuff to before packing them as artifact"
44+
outdir:
45+
description: "The path where installed files go after installing to installdir"
46+
runs:
47+
using: "node12"
48+
main: "lib/main.js"
49+
# post: 'lib/post.js'
50+
# post-if: 'success()'
51+

lib/installer.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ const mingwplatform_1 = __importDefault(require("./platforms/mingwplatform"));
2727
const msvcplatform_1 = __importDefault(require("./platforms/msvcplatform"));
2828
const macosplatform_1 = __importDefault(require("./platforms/macosplatform"));
2929
const downloader_1 = __importDefault(require("./downloader"));
30-
const versionnumber_1 = __importDefault(require("./versionnumber"));
3130
const exists = util_1.promisify(fs_1.exists);
3231
let Installer = /** @class */ (() => {
3332
class Installer {
3433
constructor(version, platform) {
3534
this._tempDir = this.initTempDir(os_1.platform());
36-
this._version = versionnumber_1.default.fromString(version);
35+
this._version = version;
3736
let host;
3837
let arch;
3938
switch (os_1.platform()) {
@@ -72,18 +71,19 @@ let Installer = /** @class */ (() => {
7271
yield this._platform.runPreInstall();
7372
// try to get Qt from cache, unless clean is specified
7473
let toolPath = null;
75-
if (clean != "true") {
74+
if (!clean) {
7675
core_1.debug(`Trying to restore Qt from cache with key: ${this._cacheKey} `);
7776
const hitKey = yield cache_1.restoreCache([Installer.CacheDir], this._cacheKey);
78-
if (hitKey && (yield exists(path_1.join(Installer.CacheDir, "bin", this._platform.qmakeName())))) {
77+
if (hitKey &&
78+
(yield exists(path_1.join(Installer.CacheDir, "bin", this._platform.qmakeName())))) {
7979
toolPath = path_1.resolve(Installer.CacheDir);
8080
core_1.debug(`Restored Qt from cache to path: ${toolPath}`);
8181
}
8282
}
8383
// download, extract, cache
8484
if (!toolPath) {
85-
core_1.debug('Downloading and installing Qt');
86-
toolPath = yield this.acquireQt(this.parseList(packages, ','), this.parseList(deepSrc, ' '), this.parseList(flatSrc, ' '));
85+
core_1.debug("Downloading and installing Qt");
86+
toolPath = yield this.acquireQt(packages, deepSrc, flatSrc);
8787
core_1.debug(`Caching Qt with key: ${this._cacheKey}`);
8888
yield this._platform.runPostInstall(false, toolPath);
8989
try {
@@ -95,7 +95,7 @@ let Installer = /** @class */ (() => {
9595
}
9696
else
9797
yield this._platform.runPostInstall(true, toolPath);
98-
core_1.info('Using Qt installation: ' + toolPath);
98+
core_1.info("Using Qt installation: " + toolPath);
9999
// generate qdep prf
100100
yield this.generateQdepPrf(toolPath);
101101
// update output / env vars
@@ -114,40 +114,34 @@ let Installer = /** @class */ (() => {
114114
const iPath = this._platform.installDirs(toolPath);
115115
yield io_1.mkdirP(iPath[0]);
116116
const instPath = path_1.join(iPath[0], os_1.platform() == "win32" ? toolPath.substr(3) : toolPath.substr(1), "..", "..");
117-
core_1.setOutput('outdir', instPath);
118-
core_1.setOutput('installdir', iPath[1]);
117+
core_1.setOutput("outdir", instPath);
118+
core_1.setOutput("installdir", iPath[1]);
119119
});
120120
}
121-
parseList(list, seperator) {
122-
return list
123-
.split(seperator)
124-
.map(e => e.trim())
125-
.filter(e => e.length > 0);
126-
}
127121
initTempDir(platform) {
128-
let tempDirectory = process.env['RUNNER_TEMP'] || '';
122+
let tempDirectory = process.env["RUNNER_TEMP"] || "";
129123
if (!tempDirectory) {
130124
let baseLocation;
131125
if (platform == "win32") {
132126
// On windows use the USERPROFILE env variable
133-
baseLocation = process.env['USERPROFILE'] || 'C:\\';
127+
baseLocation = process.env["USERPROFILE"] || "C:\\";
134128
}
135129
else {
136-
if (platform === 'darwin')
137-
baseLocation = '/Users';
130+
if (platform === "darwin")
131+
baseLocation = "/Users";
138132
else
139-
baseLocation = '/home';
133+
baseLocation = "/home";
140134
}
141-
tempDirectory = path_1.join(baseLocation, 'actions', 'temp');
135+
tempDirectory = path_1.join(baseLocation, "actions", "temp");
142136
}
143137
return tempDirectory;
144138
}
145139
installQdep() {
146140
return __awaiter(this, void 0, void 0, function* () {
147-
const pythonPath = yield io_1.which('python', true);
141+
const pythonPath = yield io_1.which("python", true);
148142
core_1.debug(`Using python: ${pythonPath}`);
149143
yield exec_1.exec(pythonPath, ["-m", "pip", "install", "qdep"]);
150-
const qdepPath = yield io_1.which('qdep', true);
144+
const qdepPath = yield io_1.which("qdep", true);
151145
yield exec_1.exec(qdepPath, ["--version"]);
152146
core_1.info("Installed qdep");
153147
});
@@ -167,7 +161,7 @@ let Installer = /** @class */ (() => {
167161
for (const pkg of packages)
168162
this._downloader.addDownload(pkg, true);
169163
// download and install
170-
const installPath = path_1.join(this._tempDir, 'qt');
164+
const installPath = path_1.join(this._tempDir, "qt");
171165
yield this._downloader.installTo(installPath);
172166
const dataPath = path_1.join(installPath, this._version.toString(), this._platform.platform);
173167
// move tools
@@ -186,7 +180,7 @@ let Installer = /** @class */ (() => {
186180
return __awaiter(this, void 0, void 0, function* () {
187181
// add qdep prf file
188182
const qmakePath = path_1.join(installPath, "bin", this._platform.qmakeName());
189-
const qdepPath = yield io_1.which('qdep', true);
183+
const qdepPath = yield io_1.which("qdep", true);
190184
yield exec_1.exec(qdepPath, ["prfgen", "--qmake", qmakePath]);
191185
core_1.info("Successfully prepared qdep");
192186
});

lib/setup-qt.js renamed to lib/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1414
Object.defineProperty(exports, "__esModule", { value: true });
1515
const core_1 = require("@actions/core");
1616
const installer_1 = __importDefault(require("./installer"));
17+
const options_1 = require("./options");
1718
function run() {
1819
return __awaiter(this, void 0, void 0, function* () {
1920
try {
20-
const installer = new installer_1.default(core_1.getInput('version'), core_1.getInput('platform'));
21-
yield installer.getQt(core_1.getInput('packages'), core_1.getInput('deep-sources'), core_1.getInput('flat-sources'), core_1.getInput('clean'));
21+
const installer = new installer_1.default(options_1.getParam("version" /* Version */), options_1.getParam("platform" /* Platform */));
22+
yield installer.getQt(options_1.getParam("packages" /* Packages */), options_1.getParam("deep-sources" /* DeepSources */), options_1.getParam("flat-sources" /* FlatSources */), options_1.getParam("clean" /* Clean */));
2223
}
2324
catch (e) {
2425
console.error(e);

lib/options.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.getParam = void 0;
7+
const core_1 = require("@actions/core");
8+
const versionnumber_1 = __importDefault(require("./versionnumber"));
9+
const parseList = (list, seperator) => list
10+
.split(seperator)
11+
.map((e) => e.trim())
12+
.filter((e) => e.length > 0);
13+
const parsers = {
14+
["version" /* Version */]: (v) => versionnumber_1.default.fromString(v),
15+
["platform" /* Platform */]: (v) => v,
16+
["packages" /* Packages */]: (v) => parseList(v, ","),
17+
["deep-sources" /* DeepSources */]: (v) => parseList(v, " "),
18+
["flat-sources" /* FlatSources */]: (v) => parseList(v, " "),
19+
["cache-mode" /* CacheMode */]: (v) => v,
20+
["clean" /* Clean */]: (v) => v === "true",
21+
};
22+
const getParser = (key) => {
23+
return parsers[key];
24+
};
25+
exports.getParam = (key, defaultValue) => {
26+
const input = core_1.getInput(key, { required: !defaultValue });
27+
return getParser(key)(input);
28+
};

lib/post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";

0 commit comments

Comments
 (0)