Skip to content

Commit e1a9b6d

Browse files
committed
WIP
1 parent 6df7f05 commit e1a9b6d

File tree

2 files changed

+136
-42
lines changed

2 files changed

+136
-42
lines changed

dist/index.js

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143905,9 +143905,15 @@ let workingDirectory = core.getInput("working-directory") || process.cwd();
143905143905
workingDirectory = external_path_.isAbsolute(workingDirectory)
143906143906
? workingDirectory
143907143907
: external_path_.join(process.cwd(), workingDirectory);
143908+
const staticCompilerVersionFileName = "esy-static-ocaml-compiler-version";
143909+
const compilerVersionFileName = "esy-ocaml-compiler-version";
143910+
function cli(cmd) {
143911+
console.log(`cli: ${cmd}`);
143912+
return external_child_process_.execSync(cmd).toString().trim();
143913+
}
143908143914
function getEsyCLIVersion() {
143909143915
const cmd = "esy --version";
143910-
return external_child_process_.execSync(cmd).toString().trim();
143916+
return cli(cmd);
143911143917
}
143912143918
function getEsyStoreVersion() {
143913143919
const esyCLIVersion = getEsyCLIVersion();
@@ -143949,7 +143955,7 @@ function getCompilerVersion(sandbox) {
143949143955
const ocamlcVersionCmd = sandbox
143950143956
? `esy ${sandbox} ocamlc --version`
143951143957
: "esy ocamlc --version";
143952-
return external_child_process_.execSync(ocamlcVersionCmd).toString();
143958+
return cli(ocamlcVersionCmd);
143953143959
}
143954143960
function run(name, command, args) {
143955143961
return __awaiter(this, void 0, void 0, function* () {
@@ -144143,12 +144149,15 @@ function prepareNPMArtifacts() {
144143144149
var _a, _b, _c;
144144144150
const statusCmd = manifestKey ? `esy ${manifestKey} status` : "esy status";
144145144151
try {
144152+
const compilerVersion = getCompilerVersion();
144153+
console.log("Found compiler version", compilerVersion);
144154+
const staticCompilerVersion = getCompilerVersion("static.esy");
144155+
console.log("Found static compiler version", staticCompilerVersion);
144146144156
const manifestFilePath = JSON.parse(external_child_process_.execSync(statusCmd, { cwd: workingDirectory }).toString()).rootPackageConfigPath;
144147144157
const manifest = JSON.parse(external_fs_.readFileSync(manifestFilePath).toString());
144148144158
if ((_a = manifest.esy) === null || _a === void 0 ? void 0 : _a.release) {
144149144159
const command = ["npm-release"];
144150144160
if ((_c = (_b = manifest.esy) === null || _b === void 0 ? void 0 : _b.release) === null || _c === void 0 ? void 0 : _c.rewritePrefix) {
144151-
const compilerVersion = getCompilerVersion();
144152144161
command.push("--ocaml-version");
144153144162
command.push(compilerVersion);
144154144163
}
@@ -144169,6 +144178,32 @@ function prepareNPMArtifacts() {
144169144178
retentionDays: 10,
144170144179
});
144171144180
console.log(`Created artifact with id: ${id} (bytes: ${size}`);
144181+
external_fs_.writeFileSync(compilerVersionFileName, compilerVersion);
144182+
const { id: compilerVersionFileNameID, size: compilerVersionFileNameSize, } = yield artifact_default().uploadArtifact(compilerVersionFileName, [compilerVersionFileName], process.env.GITHUB_WORKSPACE, {
144183+
// The level of compression for Zlib to be applied to the artifact archive.
144184+
// - 0: No compression
144185+
// - 1: Best speed
144186+
// - 6: Default compression (same as GNU Gzip)
144187+
// - 9: Best compression
144188+
compressionLevel: 0,
144189+
// optional: how long to retain the artifact
144190+
// if unspecified, defaults to repository/org retention settings (the limit of this value)
144191+
retentionDays: 10,
144192+
});
144193+
console.log(`Created artifact with name: ${compilerVersionFileName} id: ${compilerVersionFileNameID} (bytes: ${compilerVersionFileNameSize}`);
144194+
external_fs_.writeFileSync(staticCompilerVersionFileName, staticCompilerVersion);
144195+
const { id: staticCompilerVersionFileNameID, size: staticCompilerVersionFileNameSize, } = yield artifact_default().uploadArtifact(staticCompilerVersionFileName, [staticCompilerVersionFileName], process.env.GITHUB_WORKSPACE, {
144196+
// The level of compression for Zlib to be applied to the artifact archive.
144197+
// - 0: No compression
144198+
// - 1: Best speed
144199+
// - 6: Default compression (same as GNU Gzip)
144200+
// - 9: Best compression
144201+
compressionLevel: 0,
144202+
// optional: how long to retain the artifact
144203+
// if unspecified, defaults to repository/org retention settings (the limit of this value)
144204+
retentionDays: 10,
144205+
});
144206+
console.log(`Created artifact with name: ${staticCompilerVersionFileNameID} id: ${id} (bytes: ${staticCompilerVersionFileNameSize}`);
144172144207
}
144173144208
else {
144174144209
console.error(external_fs_.readFileSync(manifestFilePath).toString());
@@ -144193,21 +144228,27 @@ function bundleNPMArtifacts() {
144193144228
external_fs_.mkdirSync(releaseFolder);
144194144229
const { artifacts } = yield artifact_default().listArtifacts();
144195144230
// TODO: filter out artifacts that dont have esy-npm-release-* prefix in their name
144196-
const artifactFoldersList = yield Promise.all(artifacts.map((a) => __awaiter(this, void 0, void 0, function* () {
144197-
const folderName = `platform-${a.name}`;
144198-
const folderPath = external_path_.join(releaseFolder, folderName);
144199-
yield artifact_default().downloadArtifact(a.id, {
144200-
path: folderPath,
144201-
});
144202-
const npmTarballPath = external_path_.join(folderPath, "npm-tarball.tgz");
144203-
yield uncompress(folderPath, npmTarballPath, 1);
144204-
external_fs_.rmSync(npmTarballPath);
144205-
return folderName;
144206-
})));
144207-
const artifactFolders = artifactFoldersList.reduce((acc, folderName) => {
144208-
acc.push(folderName);
144209-
return acc;
144210-
}, []);
144231+
const artifactFoldersList = [];
144232+
for (let i = 0; i < artifacts.length; ++i) {
144233+
const a = artifacts[i];
144234+
if (a.name === compilerVersionFileName ||
144235+
a.name === staticCompilerVersionFileName) {
144236+
yield artifact_default().downloadArtifact(a.id, {
144237+
path: workingDirectory,
144238+
});
144239+
}
144240+
else {
144241+
const folderName = `platform-${a.name}`;
144242+
const folderPath = external_path_.join(releaseFolder, folderName);
144243+
yield artifact_default().downloadArtifact(a.id, {
144244+
path: folderPath,
144245+
});
144246+
const npmTarballPath = external_path_.join(folderPath, "npm-tarball.tgz");
144247+
yield uncompress(folderPath, npmTarballPath, 1);
144248+
external_fs_.rmSync(npmTarballPath);
144249+
artifactFoldersList.push(folderName);
144250+
}
144251+
}
144211144252
try {
144212144253
const esyInstallReleaseJS = "esyInstallRelease.js";
144213144254
external_fs_.cpSync(external_path_.join(releaseFolder, artifactFoldersList[0], esyInstallReleaseJS), external_path_.join(releaseFolder, esyInstallReleaseJS));
@@ -144234,15 +144275,11 @@ function bundleNPMArtifacts() {
144234144275
const rewritePrefix = mainPackageJson.esy &&
144235144276
mainPackageJson.esy.release &&
144236144277
mainPackageJson.esy.release.rewritePrefix;
144237-
function exec(cmd) {
144238-
console.log(`exec: ${cmd}`);
144239-
return external_child_process_.execSync(cmd).toString().trim();
144240-
}
144241-
const version = exec("git describe --tags --always");
144242-
const compilerVersion = getCompilerVersion();
144278+
const compilerVersion = "1"; // todo read from downloade artifact file
144279+
const staticCompilerVersion = "2"; // todo read from downloaded artifact file
144243144280
console.log("Found compiler version", compilerVersion);
144244-
const staticCompilerVersion = getCompilerVersion("static.esy");
144245144281
console.log("Found static compiler version", staticCompilerVersion);
144282+
const version = cli("git describe --tags --always");
144246144283
const packageJson = JSON.stringify({
144247144284
name: mainPackageJson.name,
144248144285
version,
@@ -144260,7 +144297,7 @@ function bundleNPMArtifacts() {
144260144297
"bin/",
144261144298
"postinstall.js",
144262144299
"esyInstallRelease.js",
144263-
].concat(artifactFolders),
144300+
].concat(artifactFoldersList),
144264144301
}, null, 2);
144265144302
external_fs_.writeFileSync(external_path_.join(releaseFolder, "package.json"), packageJson, {
144266144303
encoding: "utf8",

index.ts

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ workingDirectory = path.isAbsolute(workingDirectory)
5454
? workingDirectory
5555
: path.join(process.cwd(), workingDirectory);
5656

57+
const staticCompilerVersionFileName = "esy-static-ocaml-compiler-version";
58+
const compilerVersionFileName = "esy-ocaml-compiler-version";
59+
5760
function cli(cmd: string) {
5861
console.log(`cli: ${cmd}`);
5962
return cp.execSync(cmd).toString().trim();
@@ -352,14 +355,18 @@ async function compress(dir: string, outputFile: string): Promise<void> {
352355
async function prepareNPMArtifacts() {
353356
const statusCmd = manifestKey ? `esy ${manifestKey} status` : "esy status";
354357
try {
358+
const compilerVersion = getCompilerVersion();
359+
console.log("Found compiler version", compilerVersion);
360+
const staticCompilerVersion = getCompilerVersion("static.esy");
361+
console.log("Found static compiler version", staticCompilerVersion);
362+
355363
const manifestFilePath = JSON.parse(
356364
cp.execSync(statusCmd, { cwd: workingDirectory }).toString()
357365
).rootPackageConfigPath;
358366
const manifest = JSON.parse(fs.readFileSync(manifestFilePath).toString());
359367
if (manifest.esy?.release) {
360368
const command = ["npm-release"];
361369
if (manifest.esy?.release?.rewritePrefix) {
362-
const compilerVersion = getCompilerVersion();
363370
command.push("--ocaml-version");
364371
command.push(compilerVersion);
365372
}
@@ -387,6 +394,54 @@ async function prepareNPMArtifacts() {
387394
);
388395

389396
console.log(`Created artifact with id: ${id} (bytes: ${size}`);
397+
398+
fs.writeFileSync(compilerVersionFileName, compilerVersion);
399+
const {
400+
id: compilerVersionFileNameID,
401+
size: compilerVersionFileNameSize,
402+
} = await artifact.uploadArtifact(
403+
compilerVersionFileName,
404+
[compilerVersionFileName],
405+
process.env.GITHUB_WORKSPACE!,
406+
{
407+
// The level of compression for Zlib to be applied to the artifact archive.
408+
// - 0: No compression
409+
// - 1: Best speed
410+
// - 6: Default compression (same as GNU Gzip)
411+
// - 9: Best compression
412+
compressionLevel: 0,
413+
// optional: how long to retain the artifact
414+
// if unspecified, defaults to repository/org retention settings (the limit of this value)
415+
retentionDays: 10,
416+
}
417+
);
418+
console.log(
419+
`Created artifact with name: ${compilerVersionFileName} id: ${compilerVersionFileNameID} (bytes: ${compilerVersionFileNameSize}`
420+
);
421+
422+
fs.writeFileSync(staticCompilerVersionFileName, staticCompilerVersion);
423+
const {
424+
id: staticCompilerVersionFileNameID,
425+
size: staticCompilerVersionFileNameSize,
426+
} = await artifact.uploadArtifact(
427+
staticCompilerVersionFileName,
428+
[staticCompilerVersionFileName],
429+
process.env.GITHUB_WORKSPACE!,
430+
{
431+
// The level of compression for Zlib to be applied to the artifact archive.
432+
// - 0: No compression
433+
// - 1: Best speed
434+
// - 6: Default compression (same as GNU Gzip)
435+
// - 9: Best compression
436+
compressionLevel: 0,
437+
// optional: how long to retain the artifact
438+
// if unspecified, defaults to repository/org retention settings (the limit of this value)
439+
retentionDays: 10,
440+
}
441+
);
442+
console.log(
443+
`Created artifact with name: ${staticCompilerVersionFileNameID} id: ${id} (bytes: ${staticCompilerVersionFileNameSize}`
444+
);
390445
} else {
391446
console.error(fs.readFileSync(manifestFilePath).toString());
392447
throw new Error(
@@ -410,8 +465,17 @@ async function bundleNPMArtifacts() {
410465
const { artifacts } = await artifact.listArtifacts();
411466

412467
// TODO: filter out artifacts that dont have esy-npm-release-* prefix in their name
413-
const artifactFoldersList = await Promise.all(
414-
artifacts.map(async (a: Artifact) => {
468+
const artifactFoldersList: string[] = [];
469+
for (let i = 0; i < artifacts.length; ++i) {
470+
const a: Artifact = artifacts[i];
471+
if (
472+
a.name === compilerVersionFileName ||
473+
a.name === staticCompilerVersionFileName
474+
) {
475+
await artifact.downloadArtifact(a.id, {
476+
path: workingDirectory,
477+
});
478+
} else {
415479
const folderName = `platform-${a.name}`;
416480
const folderPath = path.join(releaseFolder, folderName);
417481
await artifact.downloadArtifact(a.id, {
@@ -420,16 +484,9 @@ async function bundleNPMArtifacts() {
420484
const npmTarballPath = path.join(folderPath, "npm-tarball.tgz");
421485
await uncompress(folderPath, npmTarballPath, 1);
422486
fs.rmSync(npmTarballPath);
423-
return folderName;
424-
})
425-
);
426-
const artifactFolders = artifactFoldersList.reduce(
427-
(acc: string[], folderName: string) => {
428-
acc.push(folderName);
429-
return acc;
430-
},
431-
[]
432-
);
487+
artifactFoldersList.push(folderName);
488+
}
489+
}
433490
try {
434491
const esyInstallReleaseJS = "esyInstallRelease.js";
435492
fs.cpSync(
@@ -473,9 +530,9 @@ async function bundleNPMArtifacts() {
473530
mainPackageJson.esy.release &&
474531
mainPackageJson.esy.release.rewritePrefix;
475532

476-
const compilerVersion = getCompilerVersion();
533+
const compilerVersion = "1"; // todo read from downloade artifact file
534+
const staticCompilerVersion = "2"; // todo read from downloaded artifact file
477535
console.log("Found compiler version", compilerVersion);
478-
const staticCompilerVersion = getCompilerVersion("static.esy");
479536
console.log("Found static compiler version", staticCompilerVersion);
480537

481538
const version = cli("git describe --tags --always");
@@ -498,7 +555,7 @@ async function bundleNPMArtifacts() {
498555
"bin/",
499556
"postinstall.js",
500557
"esyInstallRelease.js",
501-
].concat(artifactFolders),
558+
].concat(artifactFoldersList),
502559
},
503560
null,
504561
2

0 commit comments

Comments
 (0)