Skip to content

Keep the build directory clean with the --local-package-dir argument #949

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

Merged
merged 1 commit into from
Mar 12, 2025
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
44 changes: 4 additions & 40 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions dist/post/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as system from "systeminformation";
import {
ARCHITECTURE,
CACHE_PREFIX,
CYGWIN_MIRROR_ENCODED_URI,
CYGWIN_ROOT,
DUNE_CACHE_ROOT,
GITHUB_WORKSPACE,
Expand All @@ -24,7 +23,7 @@ import { cygwinVersion } from "./windows.js";

async function composeCygwinCacheKeys() {
const version = await cygwinVersion;
const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${version}`;
const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${version}`;
const restoreKeys = [key];
return { key, restoreKeys };
}
Expand Down Expand Up @@ -68,15 +67,7 @@ async function composeOpamCacheKeys() {

function composeCygwinCachePaths() {
const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin");
const cygwinLocalPackageDirectory = path.join(
GITHUB_WORKSPACE,
CYGWIN_MIRROR_ENCODED_URI,
);
const paths = [
CYGWIN_ROOT,
cygwinLocalPackageDirectory,
cygwinRootSymlinkPath,
];
const paths = [CYGWIN_ROOT, cygwinRootSymlinkPath];
return paths;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/setup-ocaml/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ export const CYGWIN_MIRROR = "https://mirrors.kernel.org/sourceware/cygwin/";

export const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE ?? process.cwd();

export const CYGWIN_MIRROR_ENCODED_URI =
encodeURIComponent(CYGWIN_MIRROR).toLowerCase();

// [HACK] https://github.com/ocaml/setup-ocaml/pull/55
export const CYGWIN_ROOT = path.join("D:", "cygwin");

export const CYGWIN_ROOT_BIN = path.join(CYGWIN_ROOT, "bin");

export const CYGWIN_LOCAL_PACKAGE_DIR = path.join(CYGWIN_ROOT, "packages");

export const CYGWIN_BASH_ENV = path.join(CYGWIN_ROOT, "bash_env");

export const DUNE_CACHE_ROOT = (() => {
Expand Down
38 changes: 2 additions & 36 deletions packages/setup-ocaml/src/windows.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import { HttpClient } from "@actions/http-client";
Expand All @@ -9,8 +6,8 @@ import * as toolCache from "@actions/tool-cache";
import * as cheerio from "cheerio";
import * as semver from "semver";
import {
CYGWIN_LOCAL_PACKAGE_DIR,
CYGWIN_MIRROR,
CYGWIN_MIRROR_ENCODED_URI,
CYGWIN_ROOT,
} from "./constants.js";

Expand All @@ -37,40 +34,8 @@ export const cygwinVersion = (async () => {
return version;
})();

async function setGitToIgnoreCygwinLocalPackageDirectory() {
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
const homeDir = os.homedir();
const globalGitConfigDir = xdgConfigHome
? path.join(xdgConfigHome, "git")
: path.join(homeDir, ".config", "git");
await fs.mkdir(globalGitConfigDir, { recursive: true });
const globalGitIgnorePath = path.join(globalGitConfigDir, "ignore");
try {
await fs.access(globalGitIgnorePath, fs.constants.R_OK);
const contents = await fs.readFile(globalGitIgnorePath, {
encoding: "utf8",
});
if (!contents.includes(CYGWIN_MIRROR_ENCODED_URI)) {
await fs.appendFile(globalGitIgnorePath, CYGWIN_MIRROR_ENCODED_URI, {
encoding: "utf8",
});
}
} catch {
await fs.writeFile(globalGitIgnorePath, CYGWIN_MIRROR_ENCODED_URI, {
encoding: "utf8",
});
} finally {
await exec(
"git",
["config", "--add", "--global", "core.excludesfile", globalGitIgnorePath],
{ windowsVerbatimArguments: true },
);
}
}

export async function setupCygwin() {
await core.group("Setting up Cygwin environment", async () => {
await setGitToIgnoreCygwinLocalPackageDirectory();
const version = await cygwinVersion;
const cachedPath = toolCache.find("cygwin", version, "x86_64");
if (cachedPath === "") {
Expand Down Expand Up @@ -106,6 +71,7 @@ export async function setupCygwin() {
"--quiet-mode",
"--symlink-type=sys",
"--upgrade-also",
`--local-package-dir=${CYGWIN_LOCAL_PACKAGE_DIR}`,
`--packages=${packages}`,
`--root=${CYGWIN_ROOT}`,
`--site=${CYGWIN_MIRROR}`,
Expand Down