Skip to content

Commit 8ac9d30

Browse files
authored
Merge pull request #646 from ocaml/fix-windows-cache
2 parents 3df20a2 + 44e5af1 commit 8ac9d30

File tree

9 files changed

+595
-457
lines changed

9 files changed

+595
-457
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ and this project adheres to
88

99
## [unreleased]
1010

11+
### Fixed
12+
13+
- Speed up caching and get rid of bugs and hacks on Windows.
14+
1115
## [2.0.9]
1216

1317
### Fixed
1418

15-
- Take the sandbox option value into account when computing the cache key
19+
- Take the sandbox option value into account when computing the cache key.
1620

1721
## [2.0.8]
1822

dist/index.js

Lines changed: 254 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post/index.js

Lines changed: 249 additions & 131 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lint-fmt/index.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build": "npm-run-all -p 'build:**'"
1515
},
1616
"dependencies": {
17-
"@actions/cache": "3.0.6",
17+
"@actions/cache": "3.1.4",
1818
"@actions/core": "1.10.0",
1919
"@actions/exec": "1.1.1",
2020
"@actions/github": "5.1.1",
@@ -23,17 +23,17 @@
2323
"@actions/io": "1.1.2",
2424
"@actions/tool-cache": "2.0.1",
2525
"cheerio": "1.0.0-rc.12",
26-
"core-js": "3.27.2",
26+
"core-js": "3.28.0",
2727
"date-fns": "2.29.3",
2828
"semver": "7.3.8",
2929
"yaml": "2.2.1"
3030
},
3131
"devDependencies": {
3232
"@tsconfig/strictest": "1.0.2",
33-
"@types/node": "18.13.0",
33+
"@types/node": "18.14.0",
3434
"@types/semver": "7.3.13",
35-
"@typescript-eslint/eslint-plugin": "5.51.0",
36-
"@typescript-eslint/parser": "5.51.0",
35+
"@typescript-eslint/eslint-plugin": "5.53.0",
36+
"@typescript-eslint/parser": "5.53.0",
3737
"@vercel/ncc": "0.36.1",
3838
"eslint": "8.34.0",
3939
"eslint-config-prettier": "8.6.0",

src/setup-ocaml/installer.ts

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,9 @@ export async function installer(): Promise<void> {
7070
core.exportVariable("MSYS", "winsymlinks:native");
7171
}
7272
if (platform === Platform.Win32) {
73-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74-
const originalPath = process.env["PATH"]!.split(path.delimiter);
75-
const msys64Path = path.join("C:", "msys64", "usr", "bin");
76-
const patchedPath = [msys64Path, ...originalPath];
77-
process.env["PATH"] = patchedPath.join(path.delimiter);
7873
await restoreCygwinCache();
79-
process.env["PATH"] = originalPath.join(path.delimiter);
80-
}
81-
let opamCacheHit;
82-
if (platform === Platform.Win32) {
83-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84-
const originalPath = process.env["PATH"]!.split(path.delimiter);
85-
const msys64Path = path.join("C:", "msys64", "usr", "bin");
86-
const patchedPath = [msys64Path, ...originalPath];
87-
process.env["PATH"] = patchedPath.join(path.delimiter);
88-
opamCacheHit = await restoreOpamCache();
89-
process.env["PATH"] = originalPath.join(path.delimiter);
90-
} else {
91-
opamCacheHit = await restoreOpamCache();
9274
}
75+
const opamCacheHit = await restoreOpamCache();
9376
await setupOpam();
9477
await repositoryRemoveAll();
9578
await repositoryAddAll(OPAM_REPOSITORIES);
@@ -100,44 +83,14 @@ export async function installer(): Promise<void> {
10083
: `ocaml-base-compiler.${await resolveVersion(OCAML_COMPILER)}`
10184
: OCAML_COMPILER;
10285
await installOcaml(ocamlCompiler);
103-
if (platform === Platform.Win32) {
104-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
105-
const originalPath = process.env["PATH"]!.split(path.delimiter);
106-
const msys64Path = path.join("C:", "msys64", "usr", "bin");
107-
const patchedPath = [msys64Path, ...originalPath];
108-
process.env["PATH"] = patchedPath.join(path.delimiter);
109-
await saveOpamCache();
110-
process.env["PATH"] = originalPath.join(path.delimiter);
111-
} else {
112-
await saveOpamCache();
113-
}
114-
}
115-
if (platform === Platform.Win32) {
116-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
117-
const originalPath = process.env["PATH"]!.split(path.delimiter);
118-
const msys64Path = path.join("C:", "msys64", "usr", "bin");
119-
const patchedPath = [msys64Path, ...originalPath];
120-
process.env["PATH"] = patchedPath.join(path.delimiter);
121-
await restoreOpamDownloadCache();
122-
process.env["PATH"] = originalPath.join(path.delimiter);
123-
} else {
124-
await restoreOpamDownloadCache();
86+
await saveOpamCache();
12587
}
88+
await restoreOpamDownloadCache();
12689
if (OPAM_DEPEXT) {
12790
await installDepext(platform);
12891
}
12992
if (DUNE_CACHE) {
130-
if (platform === Platform.Win32) {
131-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
132-
const originalPath = process.env["PATH"]!.split(path.delimiter);
133-
const msys64Path = path.join("C:", "msys64", "usr", "bin");
134-
const patchedPath = [msys64Path, ...originalPath];
135-
process.env["PATH"] = patchedPath.join(path.delimiter);
136-
await restoreDuneCache();
137-
process.env["PATH"] = originalPath.join(path.delimiter);
138-
} else {
139-
await restoreDuneCache();
140-
}
93+
await restoreDuneCache();
14194
await installDune();
14295
core.exportVariable("DUNE_CACHE", "enabled");
14396
core.exportVariable("DUNE_CACHE_TRANSPORT", "direct");

src/setup-ocaml/opam.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,9 @@ async function acquireOpamWindows() {
212212
const cachedPath = tc.find("opam", opamVersion);
213213
if (cachedPath === "") {
214214
const downloadedPath = await tc.downloadTool(
215-
`https://github.com/fdopen/opam-repository-mingw/releases/download/${opamVersion}/opam64.tar.xz`
215+
`https://github.com/fdopen/opam-repository-mingw/releases/download/${opamVersion}/opam64.zip`
216216
);
217-
const extractedPath = await tc.extractTar(downloadedPath, undefined, [
218-
"xv",
219-
]);
217+
const extractedPath = await tc.extractZip(downloadedPath);
220218
const cachedPath = await tc.cacheDir(extractedPath, "opam", opamVersion);
221219
const installSh = path.join(cachedPath, "opam64", "install.sh");
222220
await fs.chmod(installSh, 0o755);
@@ -257,11 +255,11 @@ async function setupOpamWindows() {
257255
core.addPath(CYGWIN_ROOT_WRAPPERBIN);
258256
await setupCygwin();
259257
core.endGroup();
258+
await saveCygwinCache();
260259
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
261260
const originalPath = process.env["PATH"]!.split(path.delimiter);
262261
const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath];
263262
process.env["PATH"] = patchedPath.join(path.delimiter);
264-
await saveCygwinCache();
265263
core.startGroup("Install opam");
266264
await acquireOpamWindows();
267265
core.endGroup();

src/setup-ocaml/post.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
import * as path from "node:path";
2-
31
import * as core from "@actions/core";
42

53
import { saveDuneCache, saveOpamDownloadCache } from "./cache";
6-
import { DUNE_CACHE, Platform } from "./constants";
4+
import { DUNE_CACHE } from "./constants";
75
import { trimDuneCache } from "./dune";
8-
import { getPlatform } from "./system";
96

107
async function run() {
118
try {
12-
const platform = getPlatform();
13-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14-
const originalPath = process.env["PATH"]!.split(path.delimiter);
15-
if (platform === Platform.Win32) {
16-
const msys64Path = path.join("C:", "msys64", "usr", "bin");
17-
const patchedPath = [msys64Path, ...originalPath];
18-
process.env["PATH"] = patchedPath.join(path.delimiter);
19-
}
209
if (DUNE_CACHE) {
2110
await trimDuneCache();
2211
await saveDuneCache();
2312
}
2413
await saveOpamDownloadCache();
25-
if (platform === Platform.Win32) {
26-
process.env["PATH"] = originalPath.join(path.delimiter);
27-
}
2814
} catch (error) {
2915
if (error instanceof Error) {
3016
core.error(error.message);

0 commit comments

Comments
 (0)