Use TOML 1.0.0 compliant library for parsing (#47)

iarna/toml is unmaintained.
Replaced by smol-toml which is maintained and has the same api
This commit is contained in:
Kevin Stillhammer
2025-01-16 17:20:40 +01:00
committed by GitHub
parent 0c24450c01
commit 9071a7b1c3
6 changed files with 1139 additions and 2442 deletions
Generated Vendored
+1063 -2359
View File
File diff suppressed because it is too large Load Diff
+44 -70
View File
@@ -34478,39 +34478,28 @@ var __importStar = (this && this.__importStar) || (function () {
return result; return result;
}; };
})(); })();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.updateChecksums = updateChecksums; exports.updateChecksums = updateChecksums;
const node_fs_1 = __nccwpck_require__(3024); const node_fs_1 = __nccwpck_require__(3024);
const tc = __importStar(__nccwpck_require__(3472)); const tc = __importStar(__nccwpck_require__(3472));
const known_checksums_1 = __nccwpck_require__(2764); const known_checksums_1 = __nccwpck_require__(2764);
function updateChecksums(filePath, downloadUrls) { async function updateChecksums(filePath, downloadUrls) {
return __awaiter(this, void 0, void 0, function* () { await node_fs_1.promises.rm(filePath);
yield node_fs_1.promises.rm(filePath); await node_fs_1.promises.appendFile(filePath, "// AUTOGENERATED_DO_NOT_EDIT\nexport const KNOWN_CHECKSUMS: { [key: string]: string } = {\n");
yield node_fs_1.promises.appendFile(filePath, "// AUTOGENERATED_DO_NOT_EDIT\nexport const KNOWN_CHECKSUMS: { [key: string]: string } = {\n"); let firstLine = true;
let firstLine = true; for (const downloadUrl of downloadUrls) {
for (const downloadUrl of downloadUrls) { const key = getKey(downloadUrl);
const key = getKey(downloadUrl); if (key === undefined) {
if (key === undefined) { continue;
continue;
}
const checksum = yield getOrDownloadChecksum(key, downloadUrl);
if (!firstLine) {
yield node_fs_1.promises.appendFile(filePath, ",\n");
}
yield node_fs_1.promises.appendFile(filePath, ` "${key}":\n "${checksum}"`);
firstLine = false;
} }
yield node_fs_1.promises.appendFile(filePath, ",\n};\n"); const checksum = await getOrDownloadChecksum(key, downloadUrl);
}); if (!firstLine) {
await node_fs_1.promises.appendFile(filePath, ",\n");
}
await node_fs_1.promises.appendFile(filePath, ` "${key}":\n "${checksum}"`);
firstLine = false;
}
await node_fs_1.promises.appendFile(filePath, ",\n};\n");
} }
function getKey(downloadUrl) { function getKey(downloadUrl) {
const parts = downloadUrl.split("/"); const parts = downloadUrl.split("/");
@@ -34530,24 +34519,20 @@ function getKey(downloadUrl) {
const name = fileName.split(".")[0].split("ruff-")[1]; const name = fileName.split(".")[0].split("ruff-")[1];
return `${name}-${version}`; return `${name}-${version}`;
} }
function getOrDownloadChecksum(key, downloadUrl) { async function getOrDownloadChecksum(key, downloadUrl) {
return __awaiter(this, void 0, void 0, function* () { let checksum;
let checksum; if (key in known_checksums_1.KNOWN_CHECKSUMS) {
if (key in known_checksums_1.KNOWN_CHECKSUMS) { checksum = known_checksums_1.KNOWN_CHECKSUMS[key];
checksum = known_checksums_1.KNOWN_CHECKSUMS[key]; }
} else {
else { const content = await downloadAssetContent(downloadUrl);
const content = yield downloadAssetContent(downloadUrl); checksum = content.split(" ")[0].trim();
checksum = content.split(" ")[0].trim(); }
} return checksum;
return checksum;
});
} }
function downloadAssetContent(downloadUrl) { async function downloadAssetContent(downloadUrl) {
return __awaiter(this, void 0, void 0, function* () { const downloadPath = await tc.downloadTool(downloadUrl);
const downloadPath = yield tc.downloadTool(downloadUrl); return await node_fs_1.promises.readFile(downloadPath, "utf8");
return yield node_fs_1.promises.readFile(downloadPath, "utf8");
});
} }
@@ -34591,39 +34576,28 @@ var __importStar = (this && this.__importStar) || (function () {
return result; return result;
}; };
})(); })();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const github = __importStar(__nccwpck_require__(3228)); const github = __importStar(__nccwpck_require__(3228));
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const constants_1 = __nccwpck_require__(6156); const constants_1 = __nccwpck_require__(6156);
const semver = __importStar(__nccwpck_require__(9318)); const semver = __importStar(__nccwpck_require__(9318));
const update_known_checksums_1 = __nccwpck_require__(6182); const update_known_checksums_1 = __nccwpck_require__(6182);
function run() { async function run() {
return __awaiter(this, void 0, void 0, function* () { const checksumFilePath = process.argv.slice(2)[0];
const checksumFilePath = process.argv.slice(2)[0]; const github_token = process.argv.slice(2)[1];
const github_token = process.argv.slice(2)[1]; const octokit = github.getOctokit(github_token);
const octokit = github.getOctokit(github_token); const response = await octokit.paginate(octokit.rest.repos.listReleases, {
const response = yield octokit.paginate(octokit.rest.repos.listReleases, { owner: constants_1.OWNER,
owner: constants_1.OWNER, repo: constants_1.REPO,
repo: constants_1.REPO,
});
const downloadUrls = response.flatMap((release) => release.assets
.filter((asset) => asset.name.endsWith(".sha256"))
.map((asset) => asset.browser_download_url));
yield (0, update_known_checksums_1.updateChecksums)(checksumFilePath, downloadUrls);
const latestVersion = response
.map((release) => release.tag_name)
.sort(semver.rcompare)[0];
core.setOutput("latest-version", latestVersion);
}); });
const downloadUrls = response.flatMap((release) => release.assets
.filter((asset) => asset.name.endsWith(".sha256"))
.map((asset) => asset.browser_download_url));
await (0, update_known_checksums_1.updateChecksums)(checksumFilePath, downloadUrls);
const latestVersion = response
.map((release) => release.tag_name)
.sort(semver.rcompare)[0];
core.setOutput("latest-version", latestVersion);
} }
run(); run();
+12 -6
View File
@@ -13,7 +13,7 @@
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@iarna/toml": "^2.2.5" "smol-toml": "^1.3.1"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4", "@biomejs/biome": "1.9.4",
@@ -242,11 +242,6 @@
"node": ">=14" "node": ">=14"
} }
}, },
"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/@octokit/auth-token": { "node_modules/@octokit/auth-token": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz",
@@ -459,6 +454,17 @@
"semver": "bin/semver.js" "semver": "bin/semver.js"
} }
}, },
"node_modules/smol-toml": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.3.1.tgz",
"integrity": "sha512-tEYNll18pPKHroYSmLLrksq233j021G0giwW7P3D24jC54pQ5W5BXMsQ/Mvw1OJCmEYDgY+lrzT+3nNUtoNfXQ==",
"engines": {
"node": ">= 18"
},
"funding": {
"url": "https://github.com/sponsors/cyyynthia"
}
},
"node_modules/tunnel": { "node_modules/tunnel": {
"version": "0.0.6", "version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
+1 -1
View File
@@ -26,7 +26,7 @@
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@iarna/toml": "^2.2.5" "smol-toml": "^1.3.1"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4", "@biomejs/biome": "1.9.4",
+18 -5
View File
@@ -1,15 +1,28 @@
import * as fs from "node:fs"; import * as fs from "node:fs";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as toml from "@iarna/toml"; import * as toml from "smol-toml";
export function getRuffVersionFromPyproject( export function getRuffVersionFromPyproject(
filePath: string, filePath: string,
): string | undefined { ): string | undefined {
if (!fs.existsSync(filePath)) {
core.warning(`Could not find file: ${filePath}`);
return undefined;
}
const pyprojectContent = fs.readFileSync(filePath, "utf-8"); const pyprojectContent = fs.readFileSync(filePath, "utf-8");
const pyproject = toml.parse(pyprojectContent) as { let pyproject:
project?: { dependencies?: string[] }; | {
"dependency-groups"?: { dev?: string[] }; project?: { dependencies?: string[] };
}; "dependency-groups"?: { dev?: string[] };
}
| undefined;
try {
pyproject = toml.parse(pyprojectContent);
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
const dependencies: string[] = pyproject?.project?.dependencies || []; const dependencies: string[] = pyproject?.project?.dependencies || [];
const devDependencies: string[] = pyproject?.["dependency-groups"]?.dev || []; const devDependencies: string[] = pyproject?.["dependency-groups"]?.dev || [];
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, "target": "ES2022" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib" /* Redirect output structure to the directory. */, "outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,