Skip to content

Add soft-fail-version-check toggle to warn (not error) on untested Swift versions #745

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
description: Swift version to configure
required: true
default: '6.1.0'
soft-fail-version-check:
description: 'If true, unknown Swift versions will only warn instead of error'
required: false
default: 'false'
outputs:
version:
description: The full Swift version that was configured
Expand Down
5 changes: 5 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ exports.verify = exports.swiftPackage = void 0;
const semver = __importStar(__nccwpck_require__(1383));
const core = __importStar(__nccwpck_require__(2186));
const os_1 = __nccwpck_require__(1855);
const softFailVersionCheck = core.getInput("soft-fail-version-check").toLowerCase() === "true";
const VERSIONS_LIST = [
["6.1.0", [os_1.OS.MacOS, os_1.OS.Ubuntu]],
["6.0.3", [os_1.OS.MacOS, os_1.OS.Ubuntu]],
Expand Down Expand Up @@ -575,6 +576,10 @@ function verify(version, system) {
let systemVersions = AVAILABLE_VERSIONS.filter(([_, os]) => os.includes(system.os)).map(([version, _]) => version);
let matchingVersion = evaluateVersions(systemVersions, version);
if (matchingVersion === null) {
if (softFailVersionCheck) {
core.warning(`Swift version "${version}" not in the list of tested versions; proceeding anyway because soft-fail-version-check is enabled.`);
return version;
}
throw new Error(`Version "${version}" is not available`);
}
core.debug(`Found matching version ${matchingVersion}`);
Expand Down
9 changes: 9 additions & 0 deletions src/swift-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as semver from "semver";
import * as core from "@actions/core";
import { System, OS } from "./os";

const softFailVersionCheck =
core.getInput("soft-fail-version-check").toLowerCase() === "true";

const VERSIONS_LIST: [string, OS[]][] = [
["6.1.0", [OS.MacOS, OS.Ubuntu]],
["6.0.3", [OS.MacOS, OS.Ubuntu]],
Expand Down Expand Up @@ -136,6 +139,12 @@ export function verify(version: string, system: System) {

let matchingVersion = evaluateVersions(systemVersions, version);
if (matchingVersion === null) {
if (softFailVersionCheck) {
core.warning(
`Swift version "${version}" not in the list of tested versions; proceeding anyway because soft-fail-version-check is enabled.`
);
return version;
}
throw new Error(`Version "${version}" is not available`);
}

Expand Down