@@ -51,6 +51,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
5151Object.defineProperty(exports, "__esModule", ({ value: true }));
5252exports.getJuliaVersionInfo = getJuliaVersionInfo;
5353exports.getJuliaVersions = getJuliaVersions;
54+ exports.readJuliaVersionFromToolVersionsFile = readJuliaVersionFromToolVersionsFile;
5455exports.getProjectFilePath = getProjectFilePath;
5556exports.validJuliaCompatRange = validJuliaCompatRange;
5657exports.readJuliaCompatRange = readJuliaCompatRange;
@@ -133,6 +134,38 @@ function getJuliaVersions(versionInfo) {
133134 return versions;
134135 });
135136}
137+ /**
138+ * @returns The Julia version specified in an asdf/mise-en-place .tool-versions file.
139+ */
140+ function readJuliaVersionFromToolVersionsFile(versionFilePath) {
141+ var _a;
142+ if (path.basename(versionFilePath) !== ".tool-versions") {
143+ throw new Error(`The version-file input only supports .tool-versions files: ${versionFilePath}`);
144+ }
145+ if (!fs.existsSync(versionFilePath)) {
146+ throw new Error(`The specified version-file does not exist: ${versionFilePath}`);
147+ }
148+ const lines = fs.readFileSync(versionFilePath, 'utf8').split(/\r\n|\r|\n/);
149+ for (let line of lines) {
150+ line = line.trim();
151+ if (!line || line.startsWith("#")) {
152+ continue;
153+ }
154+ const match = line.match(/^julia(?:\s+(.+))?$/);
155+ if (!match) {
156+ continue;
157+ }
158+ const version = ((_a = match[1]) === null || _a === void 0 ? void 0 : _a.trim().split(/\s+/)[0]) || "";
159+ if (!version || version.startsWith("#")) {
160+ throw new Error(`No Julia version found in ${versionFilePath}`);
161+ }
162+ if (!semver.valid(version)) {
163+ throw new Error(`The Julia version in ${versionFilePath} must specify major, minor, and patch versions: ${version}`);
164+ }
165+ return version;
166+ }
167+ throw new Error(`No Julia version found in ${versionFilePath}`);
168+ }
136169/**
137170 * @returns The path to the Julia project file
138171 */
@@ -599,19 +632,38 @@ function run() {
599632 }
600633 // Inputs.
601634 // Note that we intentionally strip leading and lagging whitespace by using `.trim()`
602- const versionInput = core.getInput('version').trim();
635+ const rawVersionInput = core.getInput('version').trim();
636+ const versionFileInput = core.getInput('version-file').trim();
603637 const includePrereleases = core.getInput('include-all-prereleases').trim() == 'true';
604638 const originalArchInput = core.getInput('arch').trim();
605639 const forceArch = core.getInput('force-arch').trim() == 'true';
606640 const projectInput = core.getInput('project').trim(); // Julia project file
607- // It can easily happen that, for example, a workflow file contains an input `version: ${{ matrix.julia-version }}`
608- // while the strategy matrix only contains a key `${{ matrix.version }}`.
609- // In that case, we want the action to fail, rather than trying to download julia from an URL that's missing parts and 404ing.
610- // We _could_ fall back to the default but that means that builds silently do things differently than they're meant to, which
611- // is worse than failing the build.
612- if (!versionInput) { // if `versionInput` is an empty string
641+ // `core.getInput('version')` returns an empty string both when the input is
642+ // omitted and when it is explicitly set to an empty value. Those cases now
643+ // differ: omitted means use `version-file` or the default `1`, while an
644+ // explicitly empty value usually indicates a typo like
645+ // `version: ${{ matrix.julia-version }}` with no matching matrix key.
646+ // GitHub exposes provided inputs as `INPUT_*` environment variables, so
647+ // `INPUT_VERSION` lets us preserve the old explicit-empty error.
648+ const versionInputWasProvided = process.env.INPUT_VERSION !== undefined;
649+ if (versionInputWasProvided && !rawVersionInput) { // if `rawVersionInput` is an empty string
613650 throw new Error('Version input must not be null');
614651 }
652+ if (rawVersionInput && versionFileInput) {
653+ throw new Error('The "version" and "version-file" inputs cannot both be set');
654+ }
655+ let versionInput = rawVersionInput;
656+ if (!versionInput && versionFileInput) {
657+ // GitHub Actions does not apply a step-specific working directory to `uses:` steps,
658+ // so relative `version-file` paths are resolved from the checked-out workspace.
659+ const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
660+ const versionFilePath = path.isAbsolute(versionFileInput) ? versionFileInput : path.join(workspace, versionFileInput);
661+ versionInput = installer.readJuliaVersionFromToolVersionsFile(versionFilePath);
662+ core.info(`Resolved ${versionFileInput} as ${versionInput}`);
663+ }
664+ if (!versionInput) {
665+ versionInput = '1';
666+ }
615667 if (versionInput == '1.6') {
616668 core.notice('[setup-julia] If you are testing 1.6 as a Long Term Support (lts) version, consider using the new "lts" version specifier instead of "1.6" explicitly, which will automatically resolve the current lts.');
617669 }
0 commit comments