From 60e292adf793c0024c131a231988c1486270caf7 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Tue, 7 Jan 2020 15:01:47 -0500 Subject: [PATCH 01/11] Update cache limits (#140) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 02cf6fe..8772244 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us ## Cache Limits -Individual caches are limited to 400MB and a repository can have up to 2GB of caches. Once the 2GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted. +A repository can have up to 2GB of caches. Once the 2GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted. ## Skipping steps based on cache-hit From d1991bb4c552e5ea8208312537c8b93c5a0886fb Mon Sep 17 00:00:00 2001 From: Flavio Corpa Date: Fri, 10 Jan 2020 23:07:52 +0100 Subject: [PATCH 02/11] Add Haskell - Cabal example (#148) * Add Haskell - Cabal example * Add link in main readme.md --- README.md | 1 + examples.md | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 8772244..510dbaf 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us - [C# - Nuget](./examples.md#c---nuget) - [Elixir - Mix](./examples.md#elixir---mix) - [Go - Modules](./examples.md#go---modules) +- [Haskell - Cabal](./examples.md#haskell---cabal) - [Java - Gradle](./examples.md#java---gradle) - [Java - Maven](./examples.md#java---maven) - [Node - npm](./examples.md#node---npm) diff --git a/examples.md b/examples.md index 948179c..6b16320 100644 --- a/examples.md +++ b/examples.md @@ -3,6 +3,7 @@ - [C# - NuGet](#c---nuget) - [Elixir - Mix](#elixir---mix) - [Go - Modules](#go---modules) +- [Haskell - Cabal](#haskell---cabal) - [Java - Gradle](#java---gradle) - [Java - Maven](#java---maven) - [Node - npm](#node---npm) @@ -62,6 +63,28 @@ steps: ${{ runner.os }}-go- ``` +## Haskell - Cabal + +We cache the elements of the Cabal store separately, as the entirety of `~/.cabal` can grow very large for projects with many dependencies. + +```yaml +- uses: actions/cache@v1 + name: Cache ~/.cabal/packages + with: + path: ~/.cabal/packages + key: ${{ runner.os }}-${{ matrix.ghc }}-cabal-packages +- uses: actions/cache@v1 + name: Cache ~/.cabal/store + with: + path: ~/.cabal/store + key: ${{ runner.os }}-${{ matrix.ghc }}-cabal-store +- uses: actions/cache@v1 + name: Cache dist-newstyle + with: + path: dist-newstyle + key: ${{ runner.os }}-${{ matrix.ghc }}-dist-newstyle +``` + ## Java - Gradle ```yaml From c33bff8d72bfb4f494de6aaa84545b1933a63247 Mon Sep 17 00:00:00 2001 From: Daniel Shuy Date: Sat, 11 Jan 2020 06:09:06 +0800 Subject: [PATCH 03/11] Add Scala - SBT example (#134) * Add Scala - SBT example * Add Scala - SBT example to README --- README.md | 1 + examples.md | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 510dbaf..3ff78d8 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us - [Python - pip](./examples.md#python---pip) - [Ruby - Gem](./examples.md#ruby---gem) - [Rust - Cargo](./examples.md#rust---cargo) +- [Scala - SBT](./examples.md#scala---sbt) - [Swift, Objective-C - Carthage](./examples.md#swift-objective-c---carthage) - [Swift, Objective-C - CocoaPods](./examples.md#swift-objective-c---cocoapods) diff --git a/examples.md b/examples.md index 6b16320..b824dbe 100644 --- a/examples.md +++ b/examples.md @@ -12,6 +12,7 @@ - [Python - pip](#python---pip) - [Ruby - Gem](#ruby---gem) - [Rust - Cargo](#rust---cargo) +- [Scala - SBT](#scala---sbt) - [Swift, Objective-C - Carthage](#swift-objective-c---carthage) - [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods) @@ -286,6 +287,21 @@ When dependencies are installed later in the workflow, we must specify the same key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} ``` +## Scala - SBT + +```yaml +- name: Cache SBT ivy cache + uses: actions/cache@v1 + with: + path: ~/.ivy2/cache + key: ${{ runner.os }}-sbt-ivy-cache-${{ hashFiles('**/build.sbt') }} +- name: Cache SBT + uses: actions/cache@v1 + with: + path: ~/.sbt + key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} +``` + ## Swift, Objective-C - Carthage ```yaml From 6c11532937e5550a63c85a71f630921f73b1eea8 Mon Sep 17 00:00:00 2001 From: Mike Coutermarsh Date: Sun, 12 Jan 2020 15:48:43 -0800 Subject: [PATCH 04/11] Update Ruby docs. "Gem" -> "Bundler" (#150) * Use "Bundler" which is the package manager "Gem" isn't wrong, but not typically what a Ruby developer would think of. * Update links * Update links --- README.md | 2 +- examples.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3ff78d8..ad6cf5c 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us - [Node - Yarn](./examples.md#node---yarn) - [PHP - Composer](./examples.md#php---composer) - [Python - pip](./examples.md#python---pip) -- [Ruby - Gem](./examples.md#ruby---gem) +- [Ruby - Bundler](./examples.md#ruby---bundler) - [Rust - Cargo](./examples.md#rust---cargo) - [Scala - SBT](./examples.md#scala---sbt) - [Swift, Objective-C - Carthage](./examples.md#swift-objective-c---carthage) diff --git a/examples.md b/examples.md index b824dbe..a2b3b92 100644 --- a/examples.md +++ b/examples.md @@ -10,7 +10,7 @@ - [Node - Yarn](#node---yarn) - [PHP - Composer](#php---composer) - [Python - pip](#python---pip) -- [Ruby - Gem](#ruby---gem) +- [Ruby - Bundler](#ruby---bundler) - [Rust - Cargo](#rust---cargo) - [Scala - SBT](#scala---sbt) - [Swift, Objective-C - Carthage](#swift-objective-c---carthage) @@ -248,15 +248,15 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu. ${{ runner.os }}-pip- ``` -## Ruby - Gem +## Ruby - Bundler ```yaml - uses: actions/cache@v1 with: path: vendor/bundle - key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }} + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} restore-keys: | - ${{ runner.os }}-gem- + ${{ runner.os }}-gems- ``` When dependencies are installed later in the workflow, we must specify the same path for the bundler. From 296374f6c987cb6cc35648dd9a1c7c3f61e2c3b6 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 14 Jan 2020 15:11:41 +0000 Subject: [PATCH 05/11] Update action's description (#75) * README: clarify case on the action * Update description --- README.md | 2 +- action.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ad6cf5c..2436630 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # cache -This GitHub Action allows caching dependencies and build outputs to improve workflow execution time. +This action allows caching dependencies and build outputs to improve workflow execution time. GitHub Actions status diff --git a/action.yml b/action.yml index bbe6089..cc77f1b 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ -name: 'Cache' -description: 'Cache dependencies and build outputs to improve workflow execution time' +name: 'Cache Artifacts' +description: 'Cache artifacts like dependencies and build outputs to improve workflow execution time' author: 'GitHub' inputs: path: @@ -21,4 +21,4 @@ runs: post-if: 'success()' branding: icon: 'archive' - color: 'gray-dark' \ No newline at end of file + color: 'gray-dark' From b6d538e2aa7eba2db114c6dfd9457137cafe8902 Mon Sep 17 00:00:00 2001 From: Shinya Uryu Date: Wed, 22 Jan 2020 09:22:40 +0900 Subject: [PATCH 06/11] Add renv examples (#151) * Add renv examples * Add link in main readme.md --- README.md | 1 + examples.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/README.md b/README.md index 2436630..b719854 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us - [Node - Yarn](./examples.md#node---yarn) - [PHP - Composer](./examples.md#php---composer) - [Python - pip](./examples.md#python---pip) +- [R - renv](./examples.md#r---renv) - [Ruby - Bundler](./examples.md#ruby---bundler) - [Rust - Cargo](./examples.md#rust---cargo) - [Scala - SBT](./examples.md#scala---sbt) diff --git a/examples.md b/examples.md index a2b3b92..f729bea 100644 --- a/examples.md +++ b/examples.md @@ -10,6 +10,7 @@ - [Node - Yarn](#node---yarn) - [PHP - Composer](#php---composer) - [Python - pip](#python---pip) +- [R - renv](#r---renv) - [Ruby - Bundler](#ruby---bundler) - [Rust - Cargo](#rust---cargo) - [Scala - SBT](#scala---sbt) @@ -248,6 +249,55 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu. ${{ runner.os }}-pip- ``` +## R - renv + +For renv, the cache directory will vary by OS. Look at https://rstudio.github.io/renv/articles/renv.html#cache + +Locations: + - Ubuntu: `~/.local/share/renv` + - macOS: `~/Library/Application Support/renv` + - Windows: `%LOCALAPPDATA%/renv` + +### Simple example +```yaml +- uses: actions/cache@v1 + with: + path: ~/.local/share/renv + key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} + restore-keys: | + ${{ runner.os }}-renv- +``` + +Replace `~/.local/share/renv` with the correct `path` if not using Ubuntu. + +### Multiple OS's in a workflow + +```yaml +- uses: actions/cache@v1 + if: startsWith(runner.os, 'Linux') + with: + path: ~/.local/share/renv + key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} + restore-keys: | + ${{ runner.os }}-renv- + +- uses: actions/cache@v1 + if: startsWith(runner.os, 'macOS') + with: + path: ~/Library/Application Support/renv + key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} + restore-keys: | + ${{ runner.os }}-renv- + +- uses: actions/cache@v1 + if: startsWith(runner.os, 'Windows') + with: + path: ~\AppData\Local\renv + key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} + restore-keys: | + ${{ runner.os }}-renv- +``` + ## Ruby - Bundler ```yaml From e43776276fc1bf0f5f1b462661f341691905b2df Mon Sep 17 00:00:00 2001 From: Florian Kostenzer Date: Wed, 29 Jan 2020 17:13:59 +0100 Subject: [PATCH 07/11] Add Swift Package Manager (SPM) example (#159) * Add Swift - SPM to examples * Add link SPM example link to readme * remove extra newline * remove another extra newline --- README.md | 2 +- examples.md | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b719854..f5ed930 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us - [Scala - SBT](./examples.md#scala---sbt) - [Swift, Objective-C - Carthage](./examples.md#swift-objective-c---carthage) - [Swift, Objective-C - CocoaPods](./examples.md#swift-objective-c---cocoapods) - +- [Swift - Swift Package Manager](./examples.md#swift---swift-package-manager) ## Cache Limits diff --git a/examples.md b/examples.md index f729bea..cb092dd 100644 --- a/examples.md +++ b/examples.md @@ -16,6 +16,7 @@ - [Scala - SBT](#scala---sbt) - [Swift, Objective-C - Carthage](#swift-objective-c---carthage) - [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods) +- [Swift - Swift Package Manager](#swift---swift-package-manager) ## C# - NuGet Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies): @@ -373,3 +374,14 @@ When dependencies are installed later in the workflow, we must specify the same restore-keys: | ${{ runner.os }}-pods- ``` + +## Swift - Swift Package Manager + +```yaml +- uses: actions/cache@v1 + with: + path: .build + key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} + restore-keys: | + ${{ runner.os }}-spm- +``` From 23e301d35cb55b348f1f4524e353b1fc29567e5f Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Wed, 29 Jan 2020 20:34:56 -0500 Subject: [PATCH 08/11] Disable fail-fast to get full coverage of failures --- .github/workflows/workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b31fdc1..f6c5448 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -19,6 +19,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] + fail-fast: false runs-on: ${{ matrix.os }} From f9c9166ecbcf2d4d7d9d99905a26ae6623cb282c Mon Sep 17 00:00:00 2001 From: David Hadka Date: Sat, 1 Feb 2020 15:11:02 -0600 Subject: [PATCH 09/11] Increase cache limit to 5 GBs (#168) * Increase cache limit to 5 GBs * Fix test to use new size limit * Update src/save.ts Co-Authored-By: Josh Gross Co-authored-by: Josh Gross --- __tests__/save.test.ts | 4 ++-- src/save.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index b355076..2c297bd 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -194,7 +194,7 @@ test("save with large cache outputs warning", async () => { const createTarMock = jest.spyOn(tar, "createTar"); - const cacheSize = 4 * 1024 * 1024 * 1024; //~4GB, over the 2GB limit + const cacheSize = 6 * 1024 * 1024 * 1024; //~6GB, over the 5GB limit jest.spyOn(actionUtils, "getArchiveFileSize").mockImplementationOnce(() => { return cacheSize; }); @@ -208,7 +208,7 @@ test("save with large cache outputs warning", async () => { expect(logWarningMock).toHaveBeenCalledTimes(1); expect(logWarningMock).toHaveBeenCalledWith( - "Cache size of ~4096 MB (4294967296 B) is over the 2GB limit, not saving cache." + "Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache." ); expect(failedMock).toHaveBeenCalledTimes(0); diff --git a/src/save.ts b/src/save.ts index ee64e42..de03856 100644 --- a/src/save.ts +++ b/src/save.ts @@ -56,14 +56,14 @@ async function run(): Promise { await createTar(archivePath, cachePath); - const fileSizeLimit = 2 * 1024 * 1024 * 1024; // 2GB per repo limit + const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit const archiveFileSize = utils.getArchiveFileSize(archivePath); core.debug(`File Size: ${archiveFileSize}`); if (archiveFileSize > fileSizeLimit) { utils.logWarning( `Cache size of ~${Math.round( archiveFileSize / (1024 * 1024) - )} MB (${archiveFileSize} B) is over the 2GB limit, not saving cache.` + )} MB (${archiveFileSize} B) is over the 5GB limit, not saving cache.` ); return; } From 4887979af80ed6f9edf3f14cb4ac23155c266d60 Mon Sep 17 00:00:00 2001 From: David Kale Date: Wed, 5 Feb 2020 09:24:37 -0500 Subject: [PATCH 10/11] proxy support (#166) * Replace typed rest client with new http-client * Send Content-Type: application/json and fix up some types * Lint * Consume @actions/http-client:1.0.5 * Consume @actions/http-client:1.0.6 * Dont send headers manually, http-client automatically will --- .gitignore | 3 ++ package-lock.json | 28 +++++------ package.json | 2 +- src/cacheHttpClient.ts | 105 +++++++++++++++++++++-------------------- 4 files changed, 70 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index 4917f3f..696edbe 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,6 @@ typings/ # DynamoDB Local files .dynamodb/ + +# Text editor files +.vscode/ diff --git a/package-lock.json b/package-lock.json index d60f8ae..3ca4841 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,14 @@ "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz", "integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ==" }, + "@actions/http-client": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.6.tgz", + "integrity": "sha512-LGmio4w98UyGX33b/W6V6Nx/sQHRXZ859YlMkn36wPsXPB82u8xTVlA/Dq2DXrm6lEq9RVmisRJa1c+HETAIJA==", + "requires": { + "tunnel": "0.0.6" + } + }, "@actions/io": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.1.tgz", @@ -5933,9 +5941,9 @@ } }, "tunnel": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.4.tgz", - "integrity": "sha1-LTeFoVjBdMmhbcLARuxfxfF0IhM=" + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" }, "tunnel-agent": { "version": "0.6.0", @@ -5973,15 +5981,6 @@ "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==", "dev": true }, - "typed-rest-client": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.5.0.tgz", - "integrity": "sha512-DVZRlmsfnTjp6ZJaatcdyvvwYwbWvR4YDNFDqb+qdTxpvaVP99YCpBkA8rxsLtAPjBVoDe4fNsnMIdZTiPuKWg==", - "requires": { - "tunnel": "0.0.4", - "underscore": "1.8.3" - } - }, "typescript": { "version": "3.7.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", @@ -5999,11 +5998,6 @@ "source-map": "~0.6.1" } }, - "underscore": { - "version": "1.8.3", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", - "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=" - }, "union-value": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", diff --git a/package.json b/package.json index 7de321b..476b675 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "dependencies": { "@actions/core": "^1.2.0", "@actions/exec": "^1.0.1", + "@actions/http-client": "^1.0.6", "@actions/io": "^1.0.1", - "typed-rest-client": "^1.5.0", "uuid": "^3.3.3" }, "devDependencies": { diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts index 97c9672..62ae2c1 100644 --- a/src/cacheHttpClient.ts +++ b/src/cacheHttpClient.ts @@ -1,13 +1,12 @@ import * as core from "@actions/core"; import * as fs from "fs"; -import { BearerCredentialHandler } from "typed-rest-client/Handlers"; -import { HttpClient, HttpCodes } from "typed-rest-client/HttpClient"; -import { IHttpClientResponse } from "typed-rest-client/Interfaces"; +import { BearerCredentialHandler } from "@actions/http-client/auth"; +import { HttpClient, HttpCodes } from "@actions/http-client"; import { + IHttpClientResponse, IRequestOptions, - RestClient, - IRestResponse -} from "typed-rest-client/RestClient"; + ITypedResponse +} from "@actions/http-client/interfaces"; import { ArtifactCacheEntry, CommitCacheRequest, @@ -16,11 +15,17 @@ import { } from "./contracts"; import * as utils from "./utils/actionUtils"; -function isSuccessStatusCode(statusCode: number): boolean { +function isSuccessStatusCode(statusCode?: number): boolean { + if (!statusCode) { + return false; + } return statusCode >= 200 && statusCode < 300; } -function isRetryableStatusCode(statusCode: number): boolean { +function isRetryableStatusCode(statusCode?: number): boolean { + if (!statusCode) { + return false; + } const retryableStatusCodes = [ HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, @@ -29,7 +34,7 @@ function isRetryableStatusCode(statusCode: number): boolean { return retryableStatusCodes.includes(statusCode); } -function getCacheApiUrl(): string { +function getCacheApiUrl(resource: string): string { // Ideally we just use ACTIONS_CACHE_URL const baseUrl: string = ( process.env["ACTIONS_CACHE_URL"] || @@ -42,8 +47,9 @@ function getCacheApiUrl(): string { ); } - core.debug(`Cache Url: ${baseUrl}`); - return `${baseUrl}_apis/artifactcache/`; + const url = `${baseUrl}_apis/artifactcache/${resource}`; + core.debug(`Resource Url: ${url}`); + return url; } function createAcceptHeader(type: string, apiVersion: string): string { @@ -52,30 +58,33 @@ function createAcceptHeader(type: string, apiVersion: string): string { function getRequestOptions(): IRequestOptions { const requestOptions: IRequestOptions = { - acceptHeader: createAcceptHeader("application/json", "6.0-preview.1") + headers: { + Accept: createAcceptHeader("application/json", "6.0-preview.1") + } }; return requestOptions; } -function createRestClient(): RestClient { +function createHttpClient(): HttpClient { const token = process.env["ACTIONS_RUNTIME_TOKEN"] || ""; const bearerCredentialHandler = new BearerCredentialHandler(token); - return new RestClient("actions/cache", getCacheApiUrl(), [ - bearerCredentialHandler - ]); + return new HttpClient( + "actions/cache", + [bearerCredentialHandler], + getRequestOptions() + ); } export async function getCacheEntry( keys: string[] ): Promise { - const restClient = createRestClient(); + const httpClient = createHttpClient(); const resource = `cache?keys=${encodeURIComponent(keys.join(","))}`; - const response = await restClient.get( - resource, - getRequestOptions() + const response = await httpClient.getJson( + getCacheApiUrl(resource) ); if (response.statusCode === 204) { return null; @@ -83,6 +92,7 @@ export async function getCacheEntry( if (!isSuccessStatusCode(response.statusCode)) { throw new Error(`Cache service responded with ${response.statusCode}`); } + const cacheResult = response.result; const cacheDownloadUrl = cacheResult?.archiveLocation; if (!cacheDownloadUrl) { @@ -118,17 +128,15 @@ export async function downloadCache( // Reserve Cache export async function reserveCache(key: string): Promise { - const restClient = createRestClient(); + const httpClient = createHttpClient(); const reserveCacheRequest: ReserveCacheRequest = { key }; - const response = await restClient.create( - "caches", - reserveCacheRequest, - getRequestOptions() + const response = await httpClient.postJson( + getCacheApiUrl("caches"), + reserveCacheRequest ); - return response?.result?.cacheId ?? -1; } @@ -142,7 +150,7 @@ function getContentRange(start: number, end: number): string { } async function uploadChunk( - restClient: RestClient, + httpClient: HttpClient, resourceUrl: string, data: NodeJS.ReadableStream, start: number, @@ -156,38 +164,37 @@ async function uploadChunk( end )}` ); - const requestOptions = getRequestOptions(); - requestOptions.additionalHeaders = { + const additionalHeaders = { "Content-Type": "application/octet-stream", "Content-Range": getContentRange(start, end) }; - const uploadChunkRequest = async (): Promise> => { - return await restClient.uploadStream( + const uploadChunkRequest = async (): Promise => { + return await httpClient.sendStream( "PATCH", resourceUrl, data, - requestOptions + additionalHeaders ); }; const response = await uploadChunkRequest(); - if (isSuccessStatusCode(response.statusCode)) { + if (isSuccessStatusCode(response.message.statusCode)) { return; } - if (isRetryableStatusCode(response.statusCode)) { + if (isRetryableStatusCode(response.message.statusCode)) { core.debug( - `Received ${response.statusCode}, retrying chunk at offset ${start}.` + `Received ${response.message.statusCode}, retrying chunk at offset ${start}.` ); const retryResponse = await uploadChunkRequest(); - if (isSuccessStatusCode(retryResponse.statusCode)) { + if (isSuccessStatusCode(retryResponse.message.statusCode)) { return; } } throw new Error( - `Cache service responded with ${response.statusCode} during chunk upload.` + `Cache service responded with ${response.message.statusCode} during chunk upload.` ); } @@ -200,13 +207,13 @@ function parseEnvNumber(key: string): number | undefined { } async function uploadFile( - restClient: RestClient, + httpClient: HttpClient, cacheId: number, archivePath: string ): Promise { // Upload Chunks const fileSize = fs.statSync(archivePath).size; - const resourceUrl = getCacheApiUrl() + "caches/" + cacheId.toString(); + const resourceUrl = getCacheApiUrl(`caches/${cacheId.toString()}`); const fd = fs.openSync(archivePath, "r"); const concurrency = parseEnvNumber("CACHE_UPLOAD_CONCURRENCY") ?? 4; // # of HTTP requests in parallel @@ -237,7 +244,7 @@ async function uploadFile( }); await uploadChunk( - restClient, + httpClient, resourceUrl, chunk, start, @@ -253,16 +260,14 @@ async function uploadFile( } async function commitCache( - restClient: RestClient, + httpClient: HttpClient, cacheId: number, filesize: number -): Promise> { - const requestOptions = getRequestOptions(); +): Promise> { const commitCacheRequest: CommitCacheRequest = { size: filesize }; - return await restClient.create( - `caches/${cacheId.toString()}`, - commitCacheRequest, - requestOptions + return await httpClient.postJson( + getCacheApiUrl(`caches/${cacheId.toString()}`), + commitCacheRequest ); } @@ -270,16 +275,16 @@ export async function saveCache( cacheId: number, archivePath: string ): Promise { - const restClient = createRestClient(); + const httpClient = createHttpClient(); core.debug("Upload cache"); - await uploadFile(restClient, cacheId, archivePath); + await uploadFile(httpClient, cacheId, archivePath); // Commit Cache core.debug("Commiting cache"); const cacheSize = utils.getArchiveFileSize(archivePath); const commitCacheResponse = await commitCache( - restClient, + httpClient, cacheId, cacheSize ); From fab26f3f4f28dcae662273647b17191565ced922 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Wed, 5 Feb 2020 09:55:35 -0500 Subject: [PATCH 11/11] Bump version to 1.1.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3ca4841..b811f3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 476b675..86ce13f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "1.1.0", + "version": "1.1.1", "private": true, "description": "Cache dependencies and build outputs", "main": "dist/restore/index.js",