Skip to content

Commit 3774e9b

Browse files
authored
Merge pull request #254 from aminya/cache
2 parents f7abbbc + e2c1dd3 commit 3774e9b

20 files changed

+157
-77
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ description: "Install all the tools required for building and testing C++/C proj
33
author: "Amin Yahyaabadi"
44

55
inputs:
6+
cache-tools:
7+
description: "If should cache the installed tools? (Default: false)"
8+
required: false
69
compiler:
710
description: "The compiler to use and its optional version separated by - e.g. llvm-13.0.0"
811
required: false

dist/actions/setup-cpp.js

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

dist/actions/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js

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

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/actions_python.21d1fd22.js

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

dist/modern/actions_python.21d1fd22.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/hdi.c45e802a.js

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

dist/modern/hdi.c45e802a.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js

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

dist/modern/setup-cpp.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@
2929
"scripts": {
3030
"build": "run-s clean build.packages && run-p lint.tsc build.parcel copy.matchers",
3131
"build.packages": "pnpm run -r build",
32-
"build.parcel": "cross-env NODE_ENV=production parcel build --detailed-report 10 && run-s build.babel",
32+
"build.parcel": "cross-env NODE_ENV=production parcel build && run-s build.babel && shx cp -r ./dist/actions/* ./dist/modern",
3333
"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",
3434
"bump": "ncu -u -x numerous,execa,prettier,@types/node,eslint,@types/eslint && pnpm update && pnpx typesync",
3535
"clean": "shx rm -rf ./dist ./exe ./packages/*/dist/ ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
36-
"copy.matchers": "run-p copy.matchers.legacy copy.matchers.actions copy.matchers.modern",
36+
"copy.matchers": "run-p copy.matchers.legacy copy.matchers.actions",
3737
"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/",
3838
"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/",
39-
"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/",
4039
"dev": "cross-env NODE_ENV=development parcel watch",
4140
"docs": "shx rm -rf packages/*/README.md && pnpm -r exec readme --path ../../dev/readme/template.md -y && pnpm -r exec ts-readme",
4241
"format": "run-s lint.dprint",
@@ -203,15 +202,6 @@
203202
"includeNodeModules": true,
204203
"optimize": true,
205204
"outputFormat": "commonjs"
206-
},
207-
"modern": {
208-
"context": "node",
209-
"engines": {
210-
"node": ">=20.x"
211-
},
212-
"includeNodeModules": true,
213-
"optimize": true,
214-
"outputFormat": "commonjs"
215205
}
216206
}
217207
}

src/cmake/__tests__/cmake.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe("setup-cmake", () => {
99
let directory: string
1010
beforeAll(async () => {
1111
directory = await setupTmpDir("cmake")
12+
process.env.CACHE_TOOLS = "true"
1213
})
1314

1415
it("should setup CMake", async () => {

src/cmake/cmake.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { extractTar } from "@actions/tool-cache"
21
import { addExeExt } from "patha"
32
import semverCoerce from "semver/functions/coerce"
43
import semverLte from "semver/functions/lte"
5-
import { extractZip } from "../utils/setup/extract"
4+
import { extractTarByExe, extractZip } from "../utils/setup/extract"
65
import { type InstallationInfo, type PackageInfo, setupBin } from "../utils/setup/setupBin"
76

87
/** Get the platform data for cmake */
@@ -34,7 +33,7 @@ function getCmakePackageInfo(version: string, platform: NodeJS.Platform, arch: s
3433
binRelativeDir: "CMake.app/Contents/bin/",
3534
binFileName: addExeExt("cmake"),
3635
extractedFolderName: folderName,
37-
extractFunction: extractTar,
36+
extractFunction: extractTarByExe,
3837
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
3938
}
4039
}
@@ -51,7 +50,7 @@ function getCmakePackageInfo(version: string, platform: NodeJS.Platform, arch: s
5150
binRelativeDir: "bin/",
5251
binFileName: addExeExt("cmake"),
5352
extractedFolderName: folderName,
54-
extractFunction: extractTar,
53+
extractFunction: extractTarByExe,
5554
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
5655
}
5756
}

src/kcov/kcov.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function getBuildKcovPackageInfo(version: string): PackageInfo {
3838
}
3939

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

4343
// build after extraction using CMake
4444
const cmake = await getCmake()

src/llvm/llvm_url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export async function getLLVMPackageInfo(
332332
extractFunction: platform === "win32"
333333
? extractExe
334334
: (file: string, dest: string) => {
335-
return extractTarByExe(file, dest, ["--strip-components=1"])
335+
return extractTarByExe(file, dest, 1)
336336
},
337337
}
338338
}

src/ninja/__tests__/ninja.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe("setup-ninja", () => {
1414
let directory: string
1515
beforeEach(async () => {
1616
directory = await setupTmpDir("ninja")
17+
process.env.CACHE_TOOLS = "true"
1718
})
1819

1920
it("should setup Ninja", async () => {

src/task/__tests__/task.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe("setup-task", () => {
88
let directory: string
99
beforeAll(async () => {
1010
directory = await setupTmpDir("task")
11+
process.env.CACHE_TOOLS = "true"
1112
})
1213

1314
it("should setup task", async () => {

src/utils/setup/extract.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function extractZip(file: string, dest: string) {
3737
return extract7Zip(file, dest)
3838
}
3939

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

5050
try {
51-
await execa("tar", ["xf", file, "-C", dest, ...flags], { stdio: "inherit" })
51+
await execa("tar", ["xf", file, "-C", dest, `--strip-components=${stripComponents}`, ...flags], {
52+
stdio: "inherit",
53+
})
5254
} catch (e) {
5355
if (process.platform === "win32" && (e as Error).message.includes("Can't create '\\\\?\\C:")) {
5456
warning(`Failed to extract symlink ${file} to ${dest}. Ignoring this symlink.`)

src/utils/setup/setupBin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { tmpdir } from "os"
77
import { GITHUB_ACTIONS } from "ci-info"
88
import { pathExists } from "path-exists"
99
import retry from "retry-as-promised"
10+
import { maybeGetInput } from "../../cli-options"
1011
import { hasDnf } from "../env/hasDnf"
1112
import { isArch } from "../env/isArch"
1213
import { isUbuntu } from "../env/isUbuntu"
@@ -132,7 +133,9 @@ export async function setupBin(
132133

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

138141
return { installDir, binDir }

0 commit comments

Comments
 (0)