Skip to content
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

Fixes compiler version in postinstall command #38

Merged
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
78 changes: 69 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95238,6 +95238,14 @@ const { isUint8Array, isArrayBuffer } = __nccwpck_require__(84978)
const { File: UndiciFile } = __nccwpck_require__(78511)
const { parseMIMEType, serializeAMimeType } = __nccwpck_require__(685)

let random
try {
const crypto = __nccwpck_require__(6005)
random = (max) => crypto.randomInt(0, max)
} catch {
random = (max) => Math.floor(Math.random(max))
}

let ReadableStream = globalThis.ReadableStream

/** @type {globalThis['File']} */
Expand Down Expand Up @@ -95323,7 +95331,7 @@ function extractBody (object, keepalive = false) {
// Set source to a copy of the bytes held by object.
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
} else if (util.isFormDataLike(object)) {
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
const prefix = `--${boundary}\r\nContent-Disposition: form-data`

/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
Expand Down Expand Up @@ -113212,6 +113220,14 @@ module.exports = require("net");

/***/ }),

/***/ 6005:
/***/ ((module) => {

"use strict";
module.exports = require("node:crypto");

/***/ }),

/***/ 15673:
/***/ ((module) => {

Expand Down Expand Up @@ -137462,8 +137478,8 @@ const create = makeCommand(createFileSync, createFile, createSync, createAsync,
//# sourceMappingURL=create.js.map
;// CONCATENATED MODULE: external "node:assert"
const external_node_assert_namespaceObject = require("node:assert");
;// CONCATENATED MODULE: external "node:crypto"
const external_node_crypto_namespaceObject = require("node:crypto");
// EXTERNAL MODULE: external "node:crypto"
var external_node_crypto_ = __nccwpck_require__(6005);
;// CONCATENATED MODULE: ./node_modules/tar/dist/esm/get-write-flag.js
// Get the appropriate flag to use for creating files
// We use fmap on Windows platforms for files less than
Expand Down Expand Up @@ -138329,7 +138345,7 @@ const unlinkFile = (path, cb) => {
if (!unpack_isWindows) {
return external_node_fs_.unlink(path, cb);
}
const name = path + '.DELETE.' + (0,external_node_crypto_namespaceObject.randomBytes)(16).toString('hex');
const name = path + '.DELETE.' + (0,external_node_crypto_.randomBytes)(16).toString('hex');
external_node_fs_.rename(path, name, er => {
if (er) {
return cb(er);
Expand All @@ -138343,7 +138359,7 @@ const unlinkFileSync = (path) => {
if (!unpack_isWindows) {
return external_node_fs_.unlinkSync(path);
}
const name = path + '.DELETE.' + (0,external_node_crypto_namespaceObject.randomBytes)(16).toString('hex');
const name = path + '.DELETE.' + (0,external_node_crypto_.randomBytes)(16).toString('hex');
external_node_fs_.renameSync(path, name);
external_node_fs_.unlinkSync(name);
};
Expand Down Expand Up @@ -139539,6 +139555,40 @@ let workingDirectory = core.getInput("working-directory") || process.cwd();
workingDirectory = external_path_.isAbsolute(workingDirectory)
? workingDirectory
: external_path_.join(process.cwd(), workingDirectory);
function getCompilerVersion(sandbox) {
// let lockFileFolder;
// if (!sandbox) {
// lockFileFolder = "esy.lock";
// } else {
// lockFileFolder = `${sandbox}.esy.lock`;
// }
// console.log(`Looking up ${lockFileFolder} for compiler version`);
// const lockFile = JSON.parse(
// fs
// .readFileSync(path.join(process.cwd(), lockFileFolder, "index.json"))
// .toString()
// );
// const ocamlPackages = Object.keys(lockFile.node).filter((k) =>
// k.startsWith("ocaml@")
// );
// if (ocamlPackages.length === 0) {
// throw new Error(
// "Couldn't figure ocaml compiler version from lock file because no ocaml-like packages were found"
// );
// }
// const ocamlPackageID = ocamlPackages[0];
// const ocamlPackageIDParts = ocamlPackageID.split("@");
// if (ocamlPackageIDParts.length !== 3) {
// throw new Error(
// `Couldn't figure ocaml compiler version from lock file because PackageId wasn't in expected format: ${ocamlPackageID}`
// );
// }
// return ocamlPackageIDParts[1];
const ocamlcVersionCmd = sandbox
? `esy ${sandbox} ocamlc --version`
: "esy ocamlc --version";
return external_child_process_.execSync(ocamlcVersionCmd).toString();
}
function run(name, command, args) {
return __awaiter(this, void 0, void 0, function* () {
const PATH = process.env.PATH ? process.env.PATH : "";
Expand Down Expand Up @@ -139727,13 +139777,19 @@ function compress(dir, outputFile) {
}
function prepareNPMArtifacts() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
var _a, _b, _c;
const statusCmd = manifestKey ? `esy ${manifestKey} status` : "esy status";
try {
const manifestFilePath = JSON.parse(external_child_process_.execSync(statusCmd, { cwd: workingDirectory }).toString()).rootPackageConfigPath;
const manifest = JSON.parse(external_fs_.readFileSync(manifestFilePath).toString());
if ((_a = manifest.esy) === null || _a === void 0 ? void 0 : _a.release) {
yield runEsyCommand("Running esy npm-release", ["npm-release"]);
const command = ["npm-release"];
if ((_c = (_b = manifest.esy) === null || _b === void 0 ? void 0 : _b.release) === null || _c === void 0 ? void 0 : _c.rewritePrefix) {
const compilerVersion = getCompilerVersion();
command.push("--ocaml-version");
command.push(compilerVersion);
}
yield runEsyCommand("Running esy npm-release", command);
let tarFile = `npm-tarball.tgz`;
yield compress(external_path_.join(workingDirectory, "_release"), tarFile);
const artifactName = `esy-npm-release-${index_platform}-${arch}`;
Expand Down Expand Up @@ -139820,6 +139876,10 @@ function bundleNPMArtifacts() {
return external_child_process_.execSync(cmd).toString().trim();
}
const version = exec("git describe --tags --always");
const compilerVersion = getCompilerVersion();
console.log("Found compiler version", compilerVersion);
const staticCompilerVersion = getCompilerVersion("static.esy");
console.log("Found static compiler version", staticCompilerVersion);
const packageJson = JSON.stringify({
name: mainPackageJson.name,
version,
Expand All @@ -139828,8 +139888,8 @@ function bundleNPMArtifacts() {
repository: mainPackageJson.repository,
scripts: {
postinstall: rewritePrefix
? "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\""
: "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; require('./postinstall.js')\"",
? `node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '${staticCompilerVersion}-musl.static.flambda': '${compilerVersion}'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\"`
: "require('./postinstall.js')\"",
},
bin: bins,
files: [
Expand Down
59 changes: 56 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,47 @@ workingDirectory = path.isAbsolute(workingDirectory)
? workingDirectory
: path.join(process.cwd(), workingDirectory);

function getCompilerVersion(sandbox?: string) {
// let lockFileFolder;

// if (!sandbox) {
// lockFileFolder = "esy.lock";
// } else {
// lockFileFolder = `${sandbox}.esy.lock`;
// }
// console.log(`Looking up ${lockFileFolder} for compiler version`);
// const lockFile = JSON.parse(
// fs
// .readFileSync(path.join(process.cwd(), lockFileFolder, "index.json"))
// .toString()
// );
// const ocamlPackages = Object.keys(lockFile.node).filter((k) =>
// k.startsWith("ocaml@")
// );

// if (ocamlPackages.length === 0) {
// throw new Error(
// "Couldn't figure ocaml compiler version from lock file because no ocaml-like packages were found"
// );
// }

// const ocamlPackageID = ocamlPackages[0];
// const ocamlPackageIDParts = ocamlPackageID.split("@");

// if (ocamlPackageIDParts.length !== 3) {
// throw new Error(
// `Couldn't figure ocaml compiler version from lock file because PackageId wasn't in expected format: ${ocamlPackageID}`
// );
// }

// return ocamlPackageIDParts[1];

const ocamlcVersionCmd = sandbox
? `esy ${sandbox} ocamlc --version`
: "esy ocamlc --version";
return cp.execSync(ocamlcVersionCmd).toString();
}

async function run(name: string, command: string, args: string[]) {
const PATH = process.env.PATH ? process.env.PATH : "";
core.startGroup(name);
Expand Down Expand Up @@ -295,7 +336,13 @@ async function prepareNPMArtifacts() {
).rootPackageConfigPath;
const manifest = JSON.parse(fs.readFileSync(manifestFilePath).toString());
if (manifest.esy?.release) {
await runEsyCommand("Running esy npm-release", ["npm-release"]);
const command = ["npm-release"];
if (manifest.esy?.release?.rewritePrefix) {
const compilerVersion = getCompilerVersion();
command.push("--ocaml-version");
command.push(compilerVersion);
}
await runEsyCommand("Running esy npm-release", command);
let tarFile = `npm-tarball.tgz`;
await compress(path.join(workingDirectory, "_release"), tarFile);

Expand Down Expand Up @@ -410,6 +457,12 @@ async function bundleNPMArtifacts() {
return cp.execSync(cmd).toString().trim();
}
const version = exec("git describe --tags --always");

const compilerVersion = getCompilerVersion();
console.log("Found compiler version", compilerVersion);
const staticCompilerVersion = getCompilerVersion("static.esy");
console.log("Found static compiler version", staticCompilerVersion);

const packageJson = JSON.stringify(
{
name: mainPackageJson.name,
Expand All @@ -419,8 +472,8 @@ async function bundleNPMArtifacts() {
repository: mainPackageJson.repository,
scripts: {
postinstall: rewritePrefix
? "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\""
: "node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '4.12.0-musl.static.flambda': '4.12.0'; process.env['OCAML_PKG_NAME'] = 'ocaml'; require('./postinstall.js')\"",
? `node -e \"process.env['OCAML_VERSION'] = process.platform == 'linux' ? '${staticCompilerVersion}-musl.static.flambda': '${compilerVersion}'; process.env['OCAML_PKG_NAME'] = 'ocaml'; process.env['ESY_RELEASE_REWRITE_PREFIX']=true; require('./postinstall.js')\"`
: "require('./postinstall.js')\"",
},
bin: bins,
files: [
Expand Down