Skip to content

Commit

Permalink
Merge pull request #254 from aminya/cache
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Aug 8, 2024
2 parents f7abbbc + e2c1dd3 commit 3774e9b
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 77 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ description: "Install all the tools required for building and testing C++/C proj
author: "Amin Yahyaabadi"

inputs:
cache-tools:
description: "If should cache the installed tools? (Default: false)"
required: false
compiler:
description: "The compiler to use and its optional version separated by - e.g. llvm-13.0.0"
required: false
Expand Down
54 changes: 27 additions & 27 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/modern/actions_python.21d1fd22.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/actions_python.21d1fd22.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/modern/hdi.c45e802a.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/hdi.c45e802a.js.map

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
"scripts": {
"build": "run-s clean build.packages && run-p lint.tsc build.parcel copy.matchers",
"build.packages": "pnpm run -r build",
"build.parcel": "cross-env NODE_ENV=production parcel build --detailed-report 10 && run-s build.babel",
"build.parcel": "cross-env NODE_ENV=production parcel build && run-s build.babel && shx cp -r ./dist/actions/* ./dist/modern",
"build.babel": "babel ./dist --out-dir dist --plugins @upleveled/babel-plugin-remove-node-prefix --plugins @babel/plugin-transform-private-methods --compact --no-babelrc --source-maps true",
"bump": "ncu -u -x numerous,execa,prettier,@types/node,eslint,@types/eslint && pnpm update && pnpx typesync",
"clean": "shx rm -rf ./dist ./exe ./packages/*/dist/ ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
"copy.matchers": "run-p copy.matchers.legacy copy.matchers.actions copy.matchers.modern",
"copy.matchers": "run-p copy.matchers.legacy copy.matchers.actions",
"copy.matchers.legacy": "shx cp ./src/gcc/gcc_matcher.json ./dist/legacy/ && shx cp ./src/msvc/msvc_matcher.json ./dist/legacy/ && shx cp ./src/python/python_matcher.json ./dist/legacy/ && shx cp ./src/llvm/llvm_matcher.json ./dist/legacy/",
"copy.matchers.actions": "shx cp ./src/gcc/gcc_matcher.json ./dist/actions/ && shx cp ./src/msvc/msvc_matcher.json ./dist/actions/ && shx cp ./src/python/python_matcher.json ./dist/actions/ && shx cp ./src/llvm/llvm_matcher.json ./dist/actions/",
"copy.matchers.modern": "shx cp ./src/gcc/gcc_matcher.json ./dist/modern/ && shx cp ./src/msvc/msvc_matcher.json ./dist/modern/ && shx cp ./src/python/python_matcher.json ./dist/modern/ && shx cp ./src/llvm/llvm_matcher.json ./dist/modern/",
"dev": "cross-env NODE_ENV=development parcel watch",
"docs": "shx rm -rf packages/*/README.md && pnpm -r exec readme --path ../../dev/readme/template.md -y && pnpm -r exec ts-readme",
"format": "run-s lint.dprint",
Expand Down Expand Up @@ -203,15 +202,6 @@
"includeNodeModules": true,
"optimize": true,
"outputFormat": "commonjs"
},
"modern": {
"context": "node",
"engines": {
"node": ">=20.x"
},
"includeNodeModules": true,
"optimize": true,
"outputFormat": "commonjs"
}
}
}
1 change: 1 addition & 0 deletions src/cmake/__tests__/cmake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("setup-cmake", () => {
let directory: string
beforeAll(async () => {
directory = await setupTmpDir("cmake")
process.env.CACHE_TOOLS = "true"
})

it("should setup CMake", async () => {
Expand Down
7 changes: 3 additions & 4 deletions src/cmake/cmake.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { extractTar } from "@actions/tool-cache"
import { addExeExt } from "patha"
import semverCoerce from "semver/functions/coerce"
import semverLte from "semver/functions/lte"
import { extractZip } from "../utils/setup/extract"
import { extractTarByExe, extractZip } from "../utils/setup/extract"
import { type InstallationInfo, type PackageInfo, setupBin } from "../utils/setup/setupBin"

/** Get the platform data for cmake */
Expand Down Expand Up @@ -34,7 +33,7 @@ function getCmakePackageInfo(version: string, platform: NodeJS.Platform, arch: s
binRelativeDir: "CMake.app/Contents/bin/",
binFileName: addExeExt("cmake"),
extractedFolderName: folderName,
extractFunction: extractTar,
extractFunction: extractTarByExe,
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
}
}
Expand All @@ -51,7 +50,7 @@ function getCmakePackageInfo(version: string, platform: NodeJS.Platform, arch: s
binRelativeDir: "bin/",
binFileName: addExeExt("cmake"),
extractedFolderName: folderName,
extractFunction: extractTar,
extractFunction: extractTarByExe,
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/kcov/kcov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getBuildKcovPackageInfo(version: string): PackageInfo {
}

async function buildKcov(file: string, dest: string) {
const out = await extractTarByExe(file, dest, ["--strip-components=1"])
const out = await extractTarByExe(file, dest, 1)

// build after extraction using CMake
const cmake = await getCmake()
Expand Down
2 changes: 1 addition & 1 deletion src/llvm/llvm_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export async function getLLVMPackageInfo(
extractFunction: platform === "win32"
? extractExe
: (file: string, dest: string) => {
return extractTarByExe(file, dest, ["--strip-components=1"])
return extractTarByExe(file, dest, 1)
},
}
}
1 change: 1 addition & 0 deletions src/ninja/__tests__/ninja.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe("setup-ninja", () => {
let directory: string
beforeEach(async () => {
directory = await setupTmpDir("ninja")
process.env.CACHE_TOOLS = "true"
})

it("should setup Ninja", async () => {
Expand Down
1 change: 1 addition & 0 deletions src/task/__tests__/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("setup-task", () => {
let directory: string
beforeAll(async () => {
directory = await setupTmpDir("task")
process.env.CACHE_TOOLS = "true"
})

it("should setup task", async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/setup/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function extractZip(file: string, dest: string) {
return extract7Zip(file, dest)
}

export async function extractTarByExe(file: string, dest: string, flags = ["--strip-components=0"]) {
export async function extractTarByExe(file: string, dest: string, stripComponents: number = 0, flags: string[] = []) {
try {
await mkdirP(dest)
} catch {
Expand All @@ -48,7 +48,9 @@ export async function extractTarByExe(file: string, dest: string, flags = ["--st
// https://github.com/heroku/heroku-slugs/issues/3

try {
await execa("tar", ["xf", file, "-C", dest, ...flags], { stdio: "inherit" })
await execa("tar", ["xf", file, "-C", dest, `--strip-components=${stripComponents}`, ...flags], {
stdio: "inherit",
})
} catch (e) {
if (process.platform === "win32" && (e as Error).message.includes("Can't create '\\\\?\\C:")) {
warning(`Failed to extract symlink ${file} to ${dest}. Ignoring this symlink.`)
Expand Down
5 changes: 4 additions & 1 deletion src/utils/setup/setupBin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { tmpdir } from "os"
import { GITHUB_ACTIONS } from "ci-info"
import { pathExists } from "path-exists"
import retry from "retry-as-promised"
import { maybeGetInput } from "../../cli-options"
import { hasDnf } from "../env/hasDnf"
import { isArch } from "../env/isArch"
import { isUbuntu } from "../env/isUbuntu"
Expand Down Expand Up @@ -132,7 +133,9 @@ export async function setupBin(

// check if inside Github Actions. If so, cache the installation
if (GITHUB_ACTIONS && typeof process.env.RUNNER_TOOL_CACHE === "string") {
await cacheDir(setupDir, name, version)
if (maybeGetInput("cache-tools") === "true" || process.env.CACHE_TOOLS === "true") {
await cacheDir(setupDir, name, version)
}
}

return { installDir, binDir }
Expand Down

0 comments on commit 3774e9b

Please sign in to comment.