From 33f6f5cefd9867f797f7e8d47257b3a940eb38f0 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Tue, 6 Aug 2024 04:19:40 +0900 Subject: [PATCH] Set Git to ignore Cygwin local package directory Signed-off-by: Sora Morimoto --- CHANGELOG.md | 4 +++ dist/index.js | 43 +++++++++++++++++++-------- dist/post/index.js | 26 ++++++++-------- packages/setup-ocaml/src/cache.ts | 22 ++++++-------- packages/setup-ocaml/src/constants.ts | 8 +++++ packages/setup-ocaml/src/windows.ts | 28 ++++++++++++++++- 6 files changed, 92 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02f077a8..992c303a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to ## [unreleased] +### Changed + +- Set Git to ignore Cygwin local package directory. + ## [3.0.4] ### Changed diff --git a/dist/index.js b/dist/index.js index 355d572b..d70e0e56 100644 --- a/dist/index.js +++ b/dist/index.js @@ -108200,6 +108200,11 @@ const PLATFORM = (() => { } })(); const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/"; +const GITHUB_WORKSPACE = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); +const CYGWIN_LOCAL_PACKAGE_DIRECTORY = (() => { + const cygwinMirrorEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); + return external_node_path_namespaceObject.join(GITHUB_WORKSPACE, cygwinMirrorEncodedUri); +})(); // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 const CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); const CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bin"); @@ -108467,6 +108472,8 @@ async function repositoryRemoveAll() { }); } +;// CONCATENATED MODULE: external "node:fs/promises" +const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs/promises"); // EXTERNAL MODULE: ../../node_modules/@actions/http-client/lib/index.js var http_client_lib = __nccwpck_require__(87301); // EXTERNAL MODULE: ../../node_modules/@actions/io/lib/io.js @@ -125758,6 +125765,9 @@ const { root: esm_root } = static_namespaceObject; + + + function createHttpClient() { return new http_client_lib.HttpClient("OCamlBot (+https://github.com/ocaml/setup-ocaml)", [], { allowRetries: true, maxRetries: 5 }); } @@ -125775,8 +125785,22 @@ async function getCygwinVersion() { }); return version; } +async function setGitToIgnoreCygwinLocalPackageDirectory() { + const xdgConfigHome = process.env.XDG_CONFIG_HOME; + const homeDir = external_node_os_.homedir(); + const globalGitConfigDir = xdgConfigHome + ? external_node_path_namespaceObject.join(xdgConfigHome, "git") + : external_node_path_namespaceObject.join(homeDir, ".config", "git"); + await promises_namespaceObject.mkdir(globalGitConfigDir, { recursive: true }); + const globalGitIgnorePath = external_node_path_namespaceObject.join(globalGitConfigDir, "ignore"); + await promises_namespaceObject.appendFile(globalGitIgnorePath, CYGWIN_LOCAL_PACKAGE_DIRECTORY, { + encoding: "utf8", + }); + await (0,lib_exec.exec)("git", ["config", "--local", "core.excludesfile", globalGitIgnorePath], { windowsVerbatimArguments: true }); +} async function setupCygwin() { await lib_core.group("Prepare the Cygwin environment", async () => { + await setGitToIgnoreCygwinLocalPackageDirectory(); const version = await getCygwinVersion(); const cachedPath = tool_cache.find("cygwin", version, "x86_64"); if (cachedPath === "") { @@ -125824,7 +125848,6 @@ async function setupCygwin() { - async function composeCygwinCacheKeys() { const cygwinVersion = await getCygwinVersion(); const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${cygwinVersion}`; @@ -125863,14 +125886,12 @@ async function composeOpamCacheKeys() { return { key, restoreKeys }; } function composeCygwinCachePaths() { - const paths = []; - const githubWorkspace = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); - paths.push(CYGWIN_ROOT); const cygwinRootSymlinkPath = external_node_path_namespaceObject.posix.join("/cygdrive", "d", "cygwin"); - paths.push(cygwinRootSymlinkPath); - const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); - const cygwinPackageRoot = external_node_path_namespaceObject.join(githubWorkspace, cygwinEncodedUri); - paths.push(cygwinPackageRoot); + const paths = [ + CYGWIN_LOCAL_PACKAGE_DIRECTORY, + CYGWIN_ROOT, + cygwinRootSymlinkPath, + ]; return paths; } function composeDuneCachePaths() { @@ -125878,15 +125899,13 @@ function composeDuneCachePaths() { return paths; } function composeOpamCachePaths() { - const paths = [OPAM_ROOT]; + const opamLocalCachePath = external_node_path_namespaceObject.join(GITHUB_WORKSPACE, "_opam"); + const paths = [OPAM_ROOT, opamLocalCachePath]; if (PLATFORM === "windows") { const { repo: { repo }, } = lib_github.context; const opamCygwinLocalCachePath = external_node_path_namespaceObject.posix.join("/cygdrive", "d", "a", repo, repo, "_opam"); paths.push(opamCygwinLocalCachePath); } - const githubWorkspace = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); - const opamLocalCachePath = external_node_path_namespaceObject.join(githubWorkspace, "_opam"); - paths.push(opamLocalCachePath); return paths; } async function restoreCache(key, restoreKeys, paths) { diff --git a/dist/post/index.js b/dist/post/index.js index 6898843c..cf8bafaf 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -103538,7 +103538,12 @@ const constants_PLATFORM = (() => { } } })(); -const constants_CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/"; +const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/"; +const constants_GITHUB_WORKSPACE = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); +const constants_CYGWIN_LOCAL_PACKAGE_DIRECTORY = (() => { + const cygwinMirrorEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); + return external_node_path_namespaceObject.join(constants_GITHUB_WORKSPACE, cygwinMirrorEncodedUri); +})(); // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 const constants_CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); const CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(constants_CYGWIN_ROOT, "bin"); @@ -103618,7 +103623,6 @@ const constants_RESOLVED_COMPILER = (async () => { - async function composeCygwinCacheKeys() { const cygwinVersion = await getCygwinVersion(); const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${cygwinVersion}`; @@ -103657,14 +103661,12 @@ async function composeOpamCacheKeys() { return { key, restoreKeys }; } function composeCygwinCachePaths() { - const paths = []; - const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); - paths.push(CYGWIN_ROOT); const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin"); - paths.push(cygwinRootSymlinkPath); - const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); - const cygwinPackageRoot = path.join(githubWorkspace, cygwinEncodedUri); - paths.push(cygwinPackageRoot); + const paths = [ + CYGWIN_LOCAL_PACKAGE_DIRECTORY, + CYGWIN_ROOT, + cygwinRootSymlinkPath, + ]; return paths; } function composeDuneCachePaths() { @@ -103672,15 +103674,13 @@ function composeDuneCachePaths() { return paths; } function composeOpamCachePaths() { - const paths = [OPAM_ROOT]; + const opamLocalCachePath = path.join(GITHUB_WORKSPACE, "_opam"); + const paths = [OPAM_ROOT, opamLocalCachePath]; if (PLATFORM === "windows") { const { repo: { repo }, } = github.context; const opamCygwinLocalCachePath = path.posix.join("/cygdrive", "d", "a", repo, repo, "_opam"); paths.push(opamCygwinLocalCachePath); } - const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); - const opamLocalCachePath = path.join(githubWorkspace, "_opam"); - paths.push(opamLocalCachePath); return paths; } async function restoreCache(key, restoreKeys, paths) { diff --git a/packages/setup-ocaml/src/cache.ts b/packages/setup-ocaml/src/cache.ts index 58dfa223..10259daa 100644 --- a/packages/setup-ocaml/src/cache.ts +++ b/packages/setup-ocaml/src/cache.ts @@ -1,6 +1,5 @@ import * as crypto from "node:crypto"; import * as path from "node:path"; -import * as process from "node:process"; import * as cache from "@actions/cache"; import * as core from "@actions/core"; import { exec } from "@actions/exec"; @@ -9,9 +8,10 @@ import * as system from "systeminformation"; import { ARCHITECTURE, CACHE_PREFIX, - CYGWIN_MIRROR, + CYGWIN_LOCAL_PACKAGE_DIRECTORY, CYGWIN_ROOT, DUNE_CACHE_ROOT, + GITHUB_WORKSPACE, OPAM_DISABLE_SANDBOXING, OPAM_REPOSITORIES, OPAM_ROOT, @@ -64,14 +64,12 @@ async function composeOpamCacheKeys() { } function composeCygwinCachePaths() { - const paths = []; - const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); - paths.push(CYGWIN_ROOT); const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin"); - paths.push(cygwinRootSymlinkPath); - const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); - const cygwinPackageRoot = path.join(githubWorkspace, cygwinEncodedUri); - paths.push(cygwinPackageRoot); + const paths = [ + CYGWIN_LOCAL_PACKAGE_DIRECTORY, + CYGWIN_ROOT, + cygwinRootSymlinkPath, + ]; return paths; } @@ -81,7 +79,8 @@ function composeDuneCachePaths() { } function composeOpamCachePaths() { - const paths = [OPAM_ROOT]; + const opamLocalCachePath = path.join(GITHUB_WORKSPACE, "_opam"); + const paths = [OPAM_ROOT, opamLocalCachePath]; if (PLATFORM === "windows") { const { repo: { repo }, @@ -96,9 +95,6 @@ function composeOpamCachePaths() { ); paths.push(opamCygwinLocalCachePath); } - const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); - const opamLocalCachePath = path.join(githubWorkspace, "_opam"); - paths.push(opamLocalCachePath); return paths; } diff --git a/packages/setup-ocaml/src/constants.ts b/packages/setup-ocaml/src/constants.ts index 31530696..c0c6fb52 100644 --- a/packages/setup-ocaml/src/constants.ts +++ b/packages/setup-ocaml/src/constants.ts @@ -50,6 +50,14 @@ export const PLATFORM = (() => { export const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/"; +export const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE ?? process.cwd(); + +export const CYGWIN_LOCAL_PACKAGE_DIRECTORY = (() => { + const cygwinMirrorEncodedUri = + encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); + return path.join(GITHUB_WORKSPACE, cygwinMirrorEncodedUri); +})(); + // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 export const CYGWIN_ROOT = path.join("D:", "cygwin"); diff --git a/packages/setup-ocaml/src/windows.ts b/packages/setup-ocaml/src/windows.ts index 666f20c3..866680fc 100644 --- a/packages/setup-ocaml/src/windows.ts +++ b/packages/setup-ocaml/src/windows.ts @@ -1,3 +1,6 @@ +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"; @@ -5,7 +8,11 @@ import * as io from "@actions/io"; import * as toolCache from "@actions/tool-cache"; import * as cheerio from "cheerio"; import * as semver from "semver"; -import { CYGWIN_MIRROR, CYGWIN_ROOT } from "./constants.js"; +import { + CYGWIN_LOCAL_PACKAGE_DIRECTORY, + CYGWIN_MIRROR, + CYGWIN_ROOT, +} from "./constants.js"; function createHttpClient() { return new HttpClient( @@ -30,8 +37,27 @@ export async function getCygwinVersion() { 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"); + await fs.appendFile(globalGitIgnorePath, CYGWIN_LOCAL_PACKAGE_DIRECTORY, { + encoding: "utf8", + }); + await exec( + "git", + ["config", "--local", "core.excludesfile", globalGitIgnorePath], + { windowsVerbatimArguments: true }, + ); +} + export async function setupCygwin() { await core.group("Prepare the Cygwin environment", async () => { + await setGitToIgnoreCygwinLocalPackageDirectory(); const version = await getCygwinVersion(); const cachedPath = toolCache.find("cygwin", version, "x86_64"); if (cachedPath === "") {