Add range validation for toml files (#726) · Sondradae2106932/setup-python@65d7f2d · GitHub
Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 65d7f2d

Browse files
Add range validation for toml files (actions#726)
1 parent f97b831 commit 65d7f2d

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎.github/workflows/test-python.yml‎

Lines changed: 2 additions & 2 deletions

‎__tests__/utils.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('Version from file test', () => {
107107
await io.mkdirP(tempDir);
108108
const pythonVersionFileName = 'pyproject.toml';
109109
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
110-
const pythonVersion = '>=3.7';
110+
const pythonVersion = '>=3.7.0';
111111
const pythonVersionFileContent = `[project]\nrequires-python = "${pythonVersion}"`;
112112
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
113113
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
@@ -119,7 +119,7 @@ describe('Version from file test', () => {
119119
await io.mkdirP(tempDir);
120120
const pythonVersionFileName = 'pyproject.toml';
121121
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
122-
const pythonVersion = '>=3.7';
122+
const pythonVersion = '>=3.7.0';
123123
const pythonVersionFileContent = `[tool.poetry.dependencies]\npython = "${pythonVersion}"`;
124124
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
125125
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);

‎dist/setup/index.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70143,7 +70143,16 @@ function getVersionInputFromTomlFile(versionFile) {
7014370143
versions.push(version);
7014470144
}
7014570145
core.info(`Extracted ${versions} from ${versionFile}`);
70146-
return Array.from(versions, version => version.split(',').join(' '));
70146+
const rawVersions = Array.from(versions, version => version.split(',').join(' '));
70147+
const validatedVersions = rawVersions
70148+
.map(item => semver.validRange(item, true))
70149+
.filter((versionRange, index) => {
70150+
if (!versionRange) {
70151+
core.debug(`The version ${rawVersions[index]} is not valid SemVer range`);
70152+
}
70153+
return !!versionRange;
70154+
});
70155+
return validatedVersions;
7014770156
}
7014870157
exports.getVersionInputFromTomlFile = getVersionInputFromTomlFile;
7014970158
/**

‎src/utils.ts‎

Lines changed: 15 additions & 1 deletion

0 commit comments

Comments
 (0)