Skip to content

Commit 3399f02

Browse files
committed
Revert microsoft#1662 , add initial skeleton for github-actions-cache-adapter
1 parent a549532 commit 3399f02

File tree

10 files changed

+1183
-20
lines changed

10 files changed

+1183
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CMakeLists.txt.user
1313
.cache
1414
/vcpkg-artifacts/node_modules/
15+
/github-actions-cache-adapter/node_modules/
1516
**/dist/
1617
/vcpkg-root
1718
/CMakeUserPresets.json

CMakeLists.txt

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ option(VCPKG_BUILD_TLS12_DOWNLOADER "Enable building the tls12-downloader" OFF)
2222
option(VCPKG_BUILD_FUZZING "Option for enabling vcpkg-fuzz support" OFF)
2323
option(VCPKG_EMBED_GIT_SHA "Option for to fill in the Git SHA version; off by default to avoid privacy concerns out of official builds" OFF)
2424
option(VCPKG_ADD_SOURCELINK "Option for enabling SourceLink in debug information on Windows/MSVC builds" "${VCPKG_EMBED_GIT_SHA}")
25-
option(VCPKG_ARTIFACTS_DEVELOPMENT "Hard code path to artifacts TypeScript. Requires node.js and npm." OFF)
25+
option(VCPKG_NODEJS_DEPENDENCIES "Hard code path to artifacts TypeScript. Requires node.js and npm." OFF)
2626
option(VCPKG_OFFICIAL_BUILD "Option to cause immediate failure if variables required for official builds are unset." OFF)
2727
set(VCPKG_PDB_SUFFIX "" CACHE STRING "Append this string to the name of the PDB for shipping vcpkg binaries.")
2828

@@ -246,7 +246,8 @@ elseif(VCPKG_OFFICIAL_BUILD)
246246
endif()
247247

248248
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg-artifacts" VCPKG_ARTIFACTS_SOURCE_DIR)
249-
if (VCPKG_ARTIFACTS_DEVELOPMENT)
249+
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/github-actions-cache-adapter" VCPKG_GITHUB_ACTIONS_CACHE_ADAPTER_SOURCE_DIR)
250+
if (VCPKG_NODEJS_DEPENDENCIES)
250251
# The directory constructed by this portion of the build script needs to be kept in sync with
251252
# that created by azure-pipelines/signing.yml
252253

@@ -259,7 +260,7 @@ if (VCPKG_ARTIFACTS_DEVELOPMENT)
259260
find_program(NODEJS "node")
260261
find_program(NPM "npm${NPM_SUFFIX}")
261262
if (NOT NODEJS OR NOT NPM)
262-
message(FATAL_ERROR "node.js and npm must be installed when VCPKG_ARTIFACTS_DEVELOPMENT is set")
263+
message(FATAL_ERROR "node.js and npm must be installed when VCPKG_NODEJS_DEPENDENCIES is set")
263264
endif()
264265

265266
add_custom_command(
@@ -269,21 +270,44 @@ if (VCPKG_ARTIFACTS_DEVELOPMENT)
269270
WORKING_DIRECTORY
270271
"${VCPKG_ARTIFACTS_SOURCE_DIR}"
271272
COMMENT
272-
"Running npm install..."
273+
"Running npm install for artifacts..."
273274
MAIN_DEPENDENCY
274275
"${VCPKG_ARTIFACTS_SOURCE_DIR}/package-lock.json"
275276
VERBATIM
276277
)
277278

278-
add_custom_target(npm-restore
279+
add_custom_target(npm-restore-artifacts
279280
ALL
280281
DEPENDS
281282
"${VCPKG_ARTIFACTS_SOURCE_DIR}/node_modules"
282-
)
283-
set_target_properties(npm-restore
283+
)
284+
set_target_properties(npm-restore-artifacts
284285
PROPERTIES
285286
ADDITIONAL_CLEAN_FILES "${VCPKG_ARTIFACTS_SOURCE_DIR}/node_modules"
286-
)
287+
)
288+
289+
add_custom_command(
290+
OUTPUT
291+
"${VCPKG_GITHUB_ACTIONS_CACHE_ADAPTER_SOURCE_DIR}/node_modules"
292+
COMMAND "${NPM}" ARGS "ci" "--include=dev"
293+
WORKING_DIRECTORY
294+
"${VCPKG_GITHUB_ACTIONS_CACHE_ADAPTER_SOURCE_DIR}"
295+
COMMENT
296+
"Running npm install for @actions/cache adapter..."
297+
MAIN_DEPENDENCY
298+
"${VCPKG_GITHUB_ACTIONS_CACHE_ADAPTER_SOURCE_DIR}/package-lock.json"
299+
VERBATIM
300+
)
301+
302+
add_custom_target(npm-restore-actions-cache-adapter
303+
ALL
304+
DEPENDS
305+
"${VCPKG_GITHUB_ACTIONS_CACHE_ADAPTER_SOURCE_DIR}/node_modules"
306+
)
307+
set_target_properties(npm-restore-actions-cache-adapter
308+
PROPERTIES
309+
ADDITIONAL_CLEAN_FILES "${VCPKG_GITHUB_ACTIONS_CACHE_ADAPTER_SOURCE_DIR}/node_modules"
310+
)
287311

288312
# === Target: vcpkg-artifacts-target ===
289313
# The suffix "-target" is added to avoid a conflict in CMake with the directory named vcpkg-artifacts and the target named vcpkg-artifacts.
@@ -333,7 +357,7 @@ if (VCPKG_ARTIFACTS_DEVELOPMENT)
333357
WORKING_DIRECTORY
334358
"${VCPKG_ARTIFACTS_SOURCE_DIR}"
335359
DEPENDS
336-
npm-restore
360+
npm-restore-artifacts
337361
${VCPKG_ARTIFACTS_SOURCES}
338362
"${VCPKG_ARTIFACTS_SOURCE_DIR}/tsconfig.json"
339363
"${VCPKG_ARTIFACTS_SOURCE_DIR}/package.json"
@@ -444,7 +468,7 @@ set_property(TARGET vcpkg PROPERTY PDB_NAME "vcpkg${VCPKG_PDB_SUFFIX}")
444468

445469
# === Target: generate-message-map ===
446470
set(GENERATE_MESSAGE_MAP_DEPENDENCIES vcpkg)
447-
if (VCPKG_ARTIFACTS_DEVELOPMENT)
471+
if (VCPKG_NODEJS_DEPENDENCIES)
448472
list(APPEND GENERATE_MESSAGE_MAP_DEPENDENCIES "${VCPKG_ARTIFACTS_SOURCE_DIR}/locales/messages.json")
449473
endif()
450474

@@ -484,7 +508,7 @@ if (BUILD_TESTING)
484508
if(VCPKG_BUILD_BENCHMARKING)
485509
target_compile_options(vcpkg-test PRIVATE -DCATCH_CONFIG_ENABLE_BENCHMARKING)
486510
endif()
487-
if(VCPKG_ARTIFACTS_DEVELOPMENT)
511+
if(VCPKG_NODEJS_DEPENDENCIES)
488512
add_test(NAME artifacts COMMAND "${NODEJS}" "${VCPKG_ARTIFACTS_SOURCE_DIR}/node_modules/mocha/bin/mocha.js" "--import=tsx" WORKING_DIRECTORY "${VCPKG_ARTIFACTS_SOURCE_DIR}")
489513
endif()
490514
endif()

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"name": "artifacts",
5454
"hidden": true,
5555
"cacheVariables": {
56-
"VCPKG_ARTIFACTS_DEVELOPMENT": true
56+
"VCPKG_NODEJS_DEPENDENCIES": true
5757
}
5858
},
5959
{

azure-pipelines/end-to-end-tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Param(
3131
[string]$StartAt,
3232
[Parameter(Mandatory = $false)]
3333
[string]$VcpkgExe,
34-
[Parameter(Mandatory = $false, HelpMessage="Run artifacts tests, only usable when vcpkg was built with VCPKG_ARTIFACTS_DEVELOPMENT=ON")]
34+
[Parameter(Mandatory = $false, HelpMessage="Run artifacts tests, only usable when vcpkg was built with VCPKG_NODEJS_DEPENDENCIES=ON")]
3535
[switch]$RunArtifactsTests
3636
)
3737

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const cache = require('@actions/cache');
2+
3+
// Parse command line arguments for a file to write to
4+
const args = process.argv.slice(2);
5+
if (args.length < 1) {
6+
console.error('Usage: node index.js <mode> <cache-key> <target-directory>');
7+
process.exit(1);
8+
}
9+
10+
const mode = args[0];
11+
if (mode === 'push-success') {
12+
const key = args[1];
13+
const directory = args[2];
14+
await cache.saveCache([directory], key);
15+
} else if (mode === 'restore') {
16+
const key = args[1];
17+
const directory = args[2];
18+
await cache.restoreCache([directory], key);
19+
} else {
20+
console.error('Invalid mode. Use "push-success" or "restore".');
21+
process.exit(1);
22+
}

0 commit comments

Comments
 (0)