mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 07:22:14 +00:00
Replace toml with @iarna/toml
This commit is contained in:
parent
5fe4cfd090
commit
6f8266d242
6 changed files with 2345 additions and 55 deletions
26
.licenses/npm/@iarna/toml.dep.yml
generated
Normal file
26
.licenses/npm/@iarna/toml.dep.yml
generated
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
---
|
||||||
|
name: "@iarna/toml"
|
||||||
|
version: 2.2.5
|
||||||
|
type: npm
|
||||||
|
summary: Better TOML parsing and stringifying all in that familiar JSON interface.
|
||||||
|
homepage: https://github.com/iarna/iarna-toml#readme
|
||||||
|
license: isc
|
||||||
|
licenses:
|
||||||
|
- sources: LICENSE
|
||||||
|
text: |+
|
||||||
|
Copyright (c) 2016, Rebecca Turner <me@re-becca.org>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
notices: []
|
||||||
|
...
|
|
@ -125,4 +125,14 @@ describe('Version from file test', () => {
|
||||||
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
|
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
|
||||||
|
'Version undefined',
|
||||||
|
async _fn => {
|
||||||
|
await io.mkdirP(tempDir);
|
||||||
|
const pythonVersionFileName = 'pyproject.toml';
|
||||||
|
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||||
|
fs.writeFileSync(pythonVersionFilePath, ``);
|
||||||
|
expect(_fn(pythonVersionFilePath)).toEqual([]);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
2278
dist/setup/index.js
vendored
2278
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
24
package-lock.json
generated
24
package-lock.json
generated
|
@ -15,8 +15,8 @@
|
||||||
"@actions/glob": "^0.2.0",
|
"@actions/glob": "^0.2.0",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^1.5.5",
|
"@actions/tool-cache": "^1.5.5",
|
||||||
"semver": "^7.1.3",
|
"@iarna/toml": "^2.2.5",
|
||||||
"toml": "^3.0.0"
|
"semver": "^7.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
|
@ -2047,6 +2047,11 @@
|
||||||
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
|
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@iarna/toml": {
|
||||||
|
"version": "2.2.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
|
||||||
|
"integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg=="
|
||||||
|
},
|
||||||
"node_modules/@istanbuljs/load-nyc-config": {
|
"node_modules/@istanbuljs/load-nyc-config": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
|
||||||
|
@ -6362,11 +6367,6 @@
|
||||||
"node": ">=8.0"
|
"node": ">=8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/toml": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w=="
|
|
||||||
},
|
|
||||||
"node_modules/tough-cookie": {
|
"node_modules/tough-cookie": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",
|
||||||
|
@ -8427,6 +8427,11 @@
|
||||||
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
|
"integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@iarna/toml": {
|
||||||
|
"version": "2.2.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
|
||||||
|
"integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg=="
|
||||||
|
},
|
||||||
"@istanbuljs/load-nyc-config": {
|
"@istanbuljs/load-nyc-config": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
|
||||||
|
@ -11666,11 +11671,6 @@
|
||||||
"is-number": "^7.0.0"
|
"is-number": "^7.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"toml": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w=="
|
|
||||||
},
|
|
||||||
"tough-cookie": {
|
"tough-cookie": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
"@actions/glob": "^0.2.0",
|
"@actions/glob": "^0.2.0",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^1.5.5",
|
"@actions/tool-cache": "^1.5.5",
|
||||||
"semver": "^7.1.3",
|
"@iarna/toml": "^2.2.5",
|
||||||
"toml": "^3.0.0"
|
"semver": "^7.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
|
|
42
src/utils.ts
42
src/utils.ts
|
@ -4,7 +4,7 @@ import * as core from '@actions/core';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as toml from 'toml';
|
import * as toml from '@iarna/toml';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export const IS_WINDOWS = process.platform === 'win32';
|
export const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
@ -183,6 +183,23 @@ export async function getOSInfo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a value from an object by following the keys path provided.
|
||||||
|
* If the value is present, it is returned. Otherwise undefined is returned.
|
||||||
|
*/
|
||||||
|
function extractValue(obj: any, keys: string[]): string | undefined {
|
||||||
|
if (keys.length > 0) {
|
||||||
|
const value = obj[keys[0]];
|
||||||
|
if (keys.length > 1 && value !== undefined) {
|
||||||
|
return extractValue(value, keys.slice(1));
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Python version extracted from the TOML file.
|
* Python version extracted from the TOML file.
|
||||||
* If the `project` key is present at the root level, the version is assumed to
|
* If the `project` key is present at the root level, the version is assumed to
|
||||||
|
@ -196,28 +213,19 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
|
||||||
|
|
||||||
const pyprojectFile = fs.readFileSync(versionFile, 'utf8');
|
const pyprojectFile = fs.readFileSync(versionFile, 'utf8');
|
||||||
const pyprojectConfig = toml.parse(pyprojectFile);
|
const pyprojectConfig = toml.parse(pyprojectFile);
|
||||||
const versions = [];
|
let keys = [];
|
||||||
|
|
||||||
if ('project' in pyprojectConfig) {
|
if ('project' in pyprojectConfig) {
|
||||||
// standard project metadata (PEP 621)
|
// standard project metadata (PEP 621)
|
||||||
const projectMetadata = pyprojectConfig['project'];
|
keys = ['project', 'requires-python'];
|
||||||
if ('requires-python' in projectMetadata) {
|
|
||||||
versions.push(projectMetadata['requires-python']);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// python poetry
|
// python poetry
|
||||||
if ('tool' in pyprojectConfig) {
|
keys = ['tool', 'poetry', 'dependencies', 'python'];
|
||||||
const toolMetadata = pyprojectConfig['tool'];
|
|
||||||
if ('poetry' in toolMetadata) {
|
|
||||||
const poetryMetadata = toolMetadata['poetry'];
|
|
||||||
if ('dependencies' in poetryMetadata) {
|
|
||||||
const dependenciesMetadata = poetryMetadata['dependencies'];
|
|
||||||
if ('python' in dependenciesMetadata) {
|
|
||||||
versions.push(dependenciesMetadata['python']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const versions = [];
|
||||||
|
const version = extractValue(pyprojectConfig, keys);
|
||||||
|
if (version !== undefined) {
|
||||||
|
versions.push(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Extracted ${versions} from ${versionFile}`);
|
core.info(`Extracted ${versions} from ${versionFile}`);
|
||||||
|
|
Loading…
Add table
Reference in a new issue