diff --git a/package-lock.json b/package-lock.json index 4bc6fcf8..b97deae9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4936,20 +4936,6 @@ "proxy-from-env": "^1.1.0" } }, - "node_modules/axios/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -7554,6 +7540,20 @@ "is-callable": "^1.1.3" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", @@ -10647,12 +10647,13 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, + "license": "MIT", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { diff --git a/packages/artifact/package-lock.json b/packages/artifact/package-lock.json index 8608ac3d..8ad6369c 100644 --- a/packages/artifact/package-lock.json +++ b/packages/artifact/package-lock.json @@ -839,9 +839,10 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", diff --git a/packages/cache/__tests__/cacheHttpClient.test.ts b/packages/cache/__tests__/cacheHttpClient.test.ts index 21c5ae86..e2201cd1 100644 --- a/packages/cache/__tests__/cacheHttpClient.test.ts +++ b/packages/cache/__tests__/cacheHttpClient.test.ts @@ -1,4 +1,5 @@ -import {downloadCache, getCacheVersion} from '../src/internal/cacheHttpClient' +import {downloadCache} from '../src/internal/cacheHttpClient' +import {getCacheVersion} from '../src/internal/cacheUtils' import {CompressionMethod} from '../src/internal/constants' import * as downloadUtils from '../src/internal/downloadUtils' import {DownloadOptions, getDownloadOptions} from '../src/options' diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index 4388026a..fad045b4 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -42,23 +42,3 @@ test('resolvePaths works on github workspace directory', async () => { const paths = await cacheUtils.resolvePaths([workspace]) expect(paths.length).toBeGreaterThan(0) }) - -test('isGhes returns false for github.com', async () => { - process.env.GITHUB_SERVER_URL = 'https://github.com' - expect(cacheUtils.isGhes()).toBe(false) -}) - -test('isGhes returns false for ghe.com', async () => { - process.env.GITHUB_SERVER_URL = 'https://somedomain.ghe.com' - expect(cacheUtils.isGhes()).toBe(false) -}) - -test('isGhes returns true for enterprise URL', async () => { - process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com' - expect(cacheUtils.isGhes()).toBe(true) -}) - -test('isGhes returns false for ghe.localhost', () => { - process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost' - expect(cacheUtils.isGhes()).toBe(false) -}) diff --git a/packages/cache/__tests__/config.test.ts b/packages/cache/__tests__/config.test.ts new file mode 100644 index 00000000..52d86d36 --- /dev/null +++ b/packages/cache/__tests__/config.test.ts @@ -0,0 +1,25 @@ +import * as config from '../src/internal/config' + +beforeEach(() => { + jest.resetModules() +}) + +test('isGhes returns false for github.com', async () => { + process.env.GITHUB_SERVER_URL = 'https://github.com' + expect(config.isGhes()).toBe(false) +}) + +test('isGhes returns false for ghe.com', async () => { + process.env.GITHUB_SERVER_URL = 'https://somedomain.ghe.com' + expect(config.isGhes()).toBe(false) +}) + +test('isGhes returns true for enterprise URL', async () => { + process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com' + expect(config.isGhes()).toBe(true) +}) + +test('isGhes returns false for ghe.localhost', () => { + process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost' + expect(config.isGhes()).toBe(false) +}) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 4d0027be..81049e0a 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -3,6 +3,7 @@ import * as path from 'path' import {saveCache} from '../src/cache' import * as cacheHttpClient from '../src/internal/cacheHttpClient' import * as cacheUtils from '../src/internal/cacheUtils' +import * as config from '../src/internal/config' import {CacheFilename, CompressionMethod} from '../src/internal/constants' import * as tar from '../src/internal/tar' import {TypedResponse} from '@actions/http-client/lib/interfaces' @@ -14,6 +15,7 @@ import {HttpClientError} from '@actions/http-client' jest.mock('../src/internal/cacheHttpClient') jest.mock('../src/internal/cacheUtils') +jest.mock('../src/internal/config') jest.mock('../src/internal/tar') beforeAll(() => { @@ -94,7 +96,7 @@ test('save with large cache outputs should fail in GHES with error message', asy .spyOn(cacheUtils, 'getCompressionMethod') .mockReturnValueOnce(Promise.resolve(compression)) - jest.spyOn(cacheUtils, 'isGhes').mockReturnValueOnce(true) + jest.spyOn(config, 'isGhes').mockReturnValueOnce(true) const reserveCacheMock = jest .spyOn(cacheHttpClient, 'reserveCache') @@ -146,7 +148,7 @@ test('save with large cache outputs should fail in GHES without error message', .spyOn(cacheUtils, 'getCompressionMethod') .mockReturnValueOnce(Promise.resolve(compression)) - jest.spyOn(cacheUtils, 'isGhes').mockReturnValueOnce(true) + jest.spyOn(config, 'isGhes').mockReturnValueOnce(true) const reserveCacheMock = jest .spyOn(cacheHttpClient, 'reserveCache') diff --git a/packages/cache/package-lock.json b/packages/cache/package-lock.json index 724f674a..beb23a68 100644 --- a/packages/cache/package-lock.json +++ b/packages/cache/package-lock.json @@ -17,7 +17,9 @@ "@azure/abort-controller": "^1.1.0", "@azure/ms-rest-js": "^2.6.0", "@azure/storage-blob": "^12.13.0", - "semver": "^6.3.1" + "@protobuf-ts/plugin": "^2.9.4", + "semver": "^6.3.1", + "twirp-ts": "^2.5.0" }, "devDependencies": { "@types/semver": "^6.0.0", @@ -245,6 +247,83 @@ "node": ">=8.0.0" } }, + "node_modules/@protobuf-ts/plugin": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/plugin/-/plugin-2.9.4.tgz", + "integrity": "sha512-Db5Laq5T3mc6ERZvhIhkj1rn57/p8gbWiCKxQWbZBBl20wMuqKoHbRw4tuD7FyXi+IkwTToaNVXymv5CY3E8Rw==", + "license": "Apache-2.0", + "dependencies": { + "@protobuf-ts/plugin-framework": "^2.9.4", + "@protobuf-ts/protoc": "^2.9.4", + "@protobuf-ts/runtime": "^2.9.4", + "@protobuf-ts/runtime-rpc": "^2.9.4", + "typescript": "^3.9" + }, + "bin": { + "protoc-gen-dump": "bin/protoc-gen-dump", + "protoc-gen-ts": "bin/protoc-gen-ts" + } + }, + "node_modules/@protobuf-ts/plugin-framework": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/plugin-framework/-/plugin-framework-2.9.4.tgz", + "integrity": "sha512-9nuX1kjdMliv+Pes8dQCKyVhjKgNNfwxVHg+tx3fLXSfZZRcUHMc1PMwB9/vTvc6gBKt9QGz5ERqSqZc0++E9A==", + "license": "(Apache-2.0 AND BSD-3-Clause)", + "dependencies": { + "@protobuf-ts/runtime": "^2.9.4", + "typescript": "^3.9" + } + }, + "node_modules/@protobuf-ts/plugin-framework/node_modules/typescript": { + "version": "3.9.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", + "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/@protobuf-ts/plugin/node_modules/typescript": { + "version": "3.9.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", + "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/@protobuf-ts/protoc": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/protoc/-/protoc-2.9.4.tgz", + "integrity": "sha512-hQX+nOhFtrA+YdAXsXEDrLoGJqXHpgv4+BueYF0S9hy/Jq0VRTVlJS1Etmf4qlMt/WdigEes5LOd/LDzui4GIQ==", + "license": "Apache-2.0", + "bin": { + "protoc": "protoc.js" + } + }, + "node_modules/@protobuf-ts/runtime": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/runtime/-/runtime-2.9.4.tgz", + "integrity": "sha512-vHRFWtJJB/SiogWDF0ypoKfRIZ41Kq+G9cEFj6Qm1eQaAhJ1LDFvgZ7Ja4tb3iLOQhz0PaoPnnOijF1qmEqTxg==", + "license": "(Apache-2.0 AND BSD-3-Clause)" + }, + "node_modules/@protobuf-ts/runtime-rpc": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/runtime-rpc/-/runtime-rpc-2.9.4.tgz", + "integrity": "sha512-y9L9JgnZxXFqH5vD4d7j9duWvIJ7AShyBRoNKJGhu9Q27qIbchfzli66H9RvrQNIFk5ER7z1Twe059WZGqERcA==", + "license": "Apache-2.0", + "dependencies": { + "@protobuf-ts/runtime": "^2.9.4" + } + }, "node_modules/@types/node": { "version": "20.4.6", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.6.tgz", @@ -316,6 +395,16 @@ "concat-map": "0.0.1" } }, + "node_modules/camel-case": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-4.1.2.tgz", + "integrity": "sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==", + "license": "MIT", + "dependencies": { + "pascal-case": "^3.1.2", + "tslib": "^2.0.3" + } + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -327,6 +416,15 @@ "node": ">= 0.8" } }, + "node_modules/commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -340,6 +438,19 @@ "node": ">=0.4.0" } }, + "node_modules/dot-object": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/dot-object/-/dot-object-2.1.5.tgz", + "integrity": "sha512-xHF8EP4XH/Ba9fvAF2LDd5O3IITVolerVV6xvkxoM8zlGEiCUrggpAnHyOoKJKCrhvPcGATFAUwIujj7bRG5UA==", + "license": "MIT", + "dependencies": { + "commander": "^6.1.0", + "glob": "^7.1.6" + }, + "bin": { + "dot-object": "bin/dot-object" + } + }, "node_modules/event-target-shim": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", @@ -369,6 +480,65 @@ "node": ">= 0.12" } }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "license": "ISC" + }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", + "license": "ISC", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "license": "MIT" + }, + "node_modules/lower-case": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", + "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", + "license": "MIT", + "dependencies": { + "tslib": "^2.0.3" + } + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -399,6 +569,16 @@ "node": "*" } }, + "node_modules/no-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", + "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", + "license": "MIT", + "dependencies": { + "lower-case": "^2.0.2", + "tslib": "^2.0.3" + } + }, "node_modules/node-fetch": { "version": "2.6.12", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", @@ -418,6 +598,55 @@ } } }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/pascal-case": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz", + "integrity": "sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==", + "license": "MIT", + "dependencies": { + "no-case": "^3.0.4", + "tslib": "^2.0.3" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-to-regexp": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", + "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==", + "license": "MIT" + }, + "node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "license": "MIT", + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/process": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", @@ -444,6 +673,16 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/ts-poet": { + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/ts-poet/-/ts-poet-4.15.0.tgz", + "integrity": "sha512-sLLR8yQBvHzi9d4R1F4pd+AzQxBfzOSSjfxiJxQhkUoH5bL7RsAC6wgvtVUQdGqiCsyS9rT6/8X2FI7ipdir5g==", + "license": "Apache-2.0", + "dependencies": { + "lodash": "^4.17.15", + "prettier": "^2.5.1" + } + }, "node_modules/tslib": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz", @@ -457,6 +696,35 @@ "node": ">=0.6.11 <=0.7.0 || >=0.7.3" } }, + "node_modules/twirp-ts": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/twirp-ts/-/twirp-ts-2.5.0.tgz", + "integrity": "sha512-JTKIK5Pf/+3qCrmYDFlqcPPUx+ohEWKBaZy8GL8TmvV2VvC0SXVyNYILO39+GCRbqnuP6hBIF+BVr8ZxRz+6fw==", + "license": "MIT", + "dependencies": { + "@protobuf-ts/plugin-framework": "^2.0.7", + "camel-case": "^4.1.2", + "dot-object": "^2.1.4", + "path-to-regexp": "^6.2.0", + "ts-poet": "^4.5.0", + "yaml": "^1.10.2" + }, + "bin": { + "protoc-gen-twirp_ts": "protoc-gen-twirp_ts" + }, + "peerDependencies": { + "@protobuf-ts/plugin": "^2.5.0", + "ts-proto": "^1.81.3" + }, + "peerDependenciesMeta": { + "@protobuf-ts/plugin": { + "optional": true + }, + "ts-proto": { + "optional": true + } + } + }, "node_modules/typescript": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", @@ -484,6 +752,12 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, "node_modules/xml2js": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz", @@ -503,6 +777,15 @@ "engines": { "node": ">=4.0" } + }, + "node_modules/yaml": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", + "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", + "license": "ISC", + "engines": { + "node": ">= 6" + } } }, "dependencies": { @@ -692,6 +975,59 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.4.1.tgz", "integrity": "sha512-O2yRJce1GOc6PAy3QxFM4NzFiWzvScDC1/5ihYBL6BUEVdq0XMWN01sppE+H6bBXbaFYipjwFLEWLg5PaSOThA==" }, + "@protobuf-ts/plugin": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/plugin/-/plugin-2.9.4.tgz", + "integrity": "sha512-Db5Laq5T3mc6ERZvhIhkj1rn57/p8gbWiCKxQWbZBBl20wMuqKoHbRw4tuD7FyXi+IkwTToaNVXymv5CY3E8Rw==", + "requires": { + "@protobuf-ts/plugin-framework": "^2.9.4", + "@protobuf-ts/protoc": "^2.9.4", + "@protobuf-ts/runtime": "^2.9.4", + "@protobuf-ts/runtime-rpc": "^2.9.4", + "typescript": "^3.9" + }, + "dependencies": { + "typescript": { + "version": "3.9.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", + "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==" + } + } + }, + "@protobuf-ts/plugin-framework": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/plugin-framework/-/plugin-framework-2.9.4.tgz", + "integrity": "sha512-9nuX1kjdMliv+Pes8dQCKyVhjKgNNfwxVHg+tx3fLXSfZZRcUHMc1PMwB9/vTvc6gBKt9QGz5ERqSqZc0++E9A==", + "requires": { + "@protobuf-ts/runtime": "^2.9.4", + "typescript": "^3.9" + }, + "dependencies": { + "typescript": { + "version": "3.9.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", + "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==" + } + } + }, + "@protobuf-ts/protoc": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/protoc/-/protoc-2.9.4.tgz", + "integrity": "sha512-hQX+nOhFtrA+YdAXsXEDrLoGJqXHpgv4+BueYF0S9hy/Jq0VRTVlJS1Etmf4qlMt/WdigEes5LOd/LDzui4GIQ==" + }, + "@protobuf-ts/runtime": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/runtime/-/runtime-2.9.4.tgz", + "integrity": "sha512-vHRFWtJJB/SiogWDF0ypoKfRIZ41Kq+G9cEFj6Qm1eQaAhJ1LDFvgZ7Ja4tb3iLOQhz0PaoPnnOijF1qmEqTxg==" + }, + "@protobuf-ts/runtime-rpc": { + "version": "2.9.4", + "resolved": "https://registry.npmjs.org/@protobuf-ts/runtime-rpc/-/runtime-rpc-2.9.4.tgz", + "integrity": "sha512-y9L9JgnZxXFqH5vD4d7j9duWvIJ7AShyBRoNKJGhu9Q27qIbchfzli66H9RvrQNIFk5ER7z1Twe059WZGqERcA==", + "requires": { + "@protobuf-ts/runtime": "^2.9.4" + } + }, "@types/node": { "version": "20.4.6", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.6.tgz", @@ -759,6 +1095,15 @@ "concat-map": "0.0.1" } }, + "camel-case": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-4.1.2.tgz", + "integrity": "sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==", + "requires": { + "pascal-case": "^3.1.2", + "tslib": "^2.0.3" + } + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -767,6 +1112,11 @@ "delayed-stream": "~1.0.0" } }, + "commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -777,6 +1127,15 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" }, + "dot-object": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/dot-object/-/dot-object-2.1.5.tgz", + "integrity": "sha512-xHF8EP4XH/Ba9fvAF2LDd5O3IITVolerVV6xvkxoM8zlGEiCUrggpAnHyOoKJKCrhvPcGATFAUwIujj7bRG5UA==", + "requires": { + "commander": "^6.1.0", + "glob": "^7.1.6" + } + }, "event-target-shim": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", @@ -797,6 +1156,51 @@ "mime-types": "^2.1.12" } }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "lower-case": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", + "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", + "requires": { + "tslib": "^2.0.3" + } + }, "mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -818,6 +1222,15 @@ "brace-expansion": "^1.1.7" } }, + "no-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", + "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", + "requires": { + "lower-case": "^2.0.2", + "tslib": "^2.0.3" + } + }, "node-fetch": { "version": "2.6.12", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", @@ -826,6 +1239,38 @@ "whatwg-url": "^5.0.0" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "requires": { + "wrappy": "1" + } + }, + "pascal-case": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz", + "integrity": "sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==", + "requires": { + "no-case": "^3.0.4", + "tslib": "^2.0.3" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==" + }, + "path-to-regexp": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", + "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==" + }, + "prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==" + }, "process": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", @@ -846,6 +1291,15 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "ts-poet": { + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/ts-poet/-/ts-poet-4.15.0.tgz", + "integrity": "sha512-sLLR8yQBvHzi9d4R1F4pd+AzQxBfzOSSjfxiJxQhkUoH5bL7RsAC6wgvtVUQdGqiCsyS9rT6/8X2FI7ipdir5g==", + "requires": { + "lodash": "^4.17.15", + "prettier": "^2.5.1" + } + }, "tslib": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz", @@ -856,6 +1310,19 @@ "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" }, + "twirp-ts": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/twirp-ts/-/twirp-ts-2.5.0.tgz", + "integrity": "sha512-JTKIK5Pf/+3qCrmYDFlqcPPUx+ohEWKBaZy8GL8TmvV2VvC0SXVyNYILO39+GCRbqnuP6hBIF+BVr8ZxRz+6fw==", + "requires": { + "@protobuf-ts/plugin-framework": "^2.0.7", + "camel-case": "^4.1.2", + "dot-object": "^2.1.4", + "path-to-regexp": "^6.2.0", + "ts-poet": "^4.5.0", + "yaml": "^1.10.2" + } + }, "typescript": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", @@ -876,6 +1343,11 @@ "webidl-conversions": "^3.0.0" } }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, "xml2js": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz", @@ -889,6 +1361,11 @@ "version": "11.0.1", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" + }, + "yaml": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", + "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==" } } } diff --git a/packages/cache/package.json b/packages/cache/package.json index a98c0bb6..e5332a92 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -45,10 +45,12 @@ "@azure/abort-controller": "^1.1.0", "@azure/ms-rest-js": "^2.6.0", "@azure/storage-blob": "^12.13.0", - "semver": "^6.3.1" + "@protobuf-ts/plugin": "^2.9.4", + "semver": "^6.3.1", + "twirp-ts": "^2.5.0" }, "devDependencies": { "@types/semver": "^6.0.0", "typescript": "^5.2.2" } -} +} \ No newline at end of file diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index f7fadb6f..1450c8ac 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -2,9 +2,19 @@ import * as core from '@actions/core' import * as path from 'path' import * as utils from './internal/cacheUtils' import * as cacheHttpClient from './internal/cacheHttpClient' -import {createTar, extractTar, listTar} from './internal/tar' +import * as cacheTwirpClient from './internal/shared/cacheTwirpClient' +import {getCacheServiceVersion, isGhes} from './internal/config' import {DownloadOptions, UploadOptions} from './options' - +import {createTar, extractTar, listTar} from './internal/tar' +import { + CreateCacheEntryRequest, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse, + GetCacheEntryDownloadURLRequest +} from './generated/results/api/v1/cache' +import {CacheFileSizeLimit} from './internal/constants' +import {uploadCacheFile} from './internal/blob/upload-cache' +import {downloadCacheFile} from './internal/blob/download-cache' export class ValidationError extends Error { constructor(message: string) { super(message) @@ -48,7 +58,6 @@ function checkKey(key: string): void { * * @returns boolean return true if Actions cache service feature is available, otherwise false */ - export function isFeatureAvailable(): boolean { return !!process.env['ACTIONS_CACHE_URL'] } @@ -72,6 +81,45 @@ export async function restoreCache( ): Promise { checkPaths(paths) + const cacheServiceVersion: string = getCacheServiceVersion() + switch (cacheServiceVersion) { + case 'v2': + return await restoreCacheV2( + paths, + primaryKey, + restoreKeys, + options, + enableCrossOsArchive + ) + case 'v1': + default: + return await restoreCacheV1( + paths, + primaryKey, + restoreKeys, + options, + enableCrossOsArchive + ) + } +} + +/** + * Restores cache using the legacy Cache Service + * + * @param paths + * @param primaryKey + * @param restoreKeys + * @param options + * @param enableCrossOsArchive + * @returns + */ +async function restoreCacheV1( + paths: string[], + primaryKey: string, + restoreKeys?: string[], + options?: DownloadOptions, + enableCrossOsArchive = false +): Promise { restoreKeys = restoreKeys || [] const keys = [primaryKey, ...restoreKeys] @@ -153,6 +201,104 @@ export async function restoreCache( return undefined } +/** + * Restores cache using the new Cache Service + * + * @param paths a list of file paths to restore from the cache + * @param primaryKey an explicit key for restoring the cache + * @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key + * @param downloadOptions cache download options + * @param enableCrossOsArchive an optional boolean enabled to restore on windows any cache created on any platform + * @returns string returns the key for the cache hit, otherwise returns undefined + */ +async function restoreCacheV2( + paths: string[], + primaryKey: string, + restoreKeys?: string[], + options?: DownloadOptions, + enableCrossOsArchive = false +): Promise { + restoreKeys = restoreKeys || [] + const keys = [primaryKey, ...restoreKeys] + + core.debug('Resolved Keys:') + core.debug(JSON.stringify(keys)) + + if (keys.length > 10) { + throw new ValidationError( + `Key Validation Error: Keys are limited to a maximum of 10.` + ) + } + for (const key of keys) { + checkKey(key) + } + + let archivePath = '' + try { + const twirpClient = cacheTwirpClient.internalCacheTwirpClient() + const compressionMethod = await utils.getCompressionMethod() + + const request: GetCacheEntryDownloadURLRequest = { + key: primaryKey, + restoreKeys, + version: utils.getCacheVersion( + paths, + compressionMethod, + enableCrossOsArchive + ) + } + + const response = await twirpClient.GetCacheEntryDownloadURL(request) + + if (!response.ok) { + core.warning(`Cache not found for keys: ${keys.join(', ')}`) + return undefined + } + + core.info(`Cache hit for: ${request.key}`) + + if (options?.lookupOnly) { + core.info('Lookup only - skipping download') + return request.key + } + + archivePath = path.join( + await utils.createTempDirectory(), + utils.getCacheFileName(compressionMethod) + ) + core.debug(`Archive path: ${archivePath}`) + core.debug(`Starting download of archive to: ${archivePath}`) + + await downloadCacheFile(response.signedDownloadUrl, archivePath) + + const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath) + core.info( + `Cache Size: ~${Math.round( + archiveFileSize / (1024 * 1024) + )} MB (${archiveFileSize} B)` + ) + + if (core.isDebug()) { + await listTar(archivePath, compressionMethod) + } + + await extractTar(archivePath, compressionMethod) + core.info('Cache restored successfully') + + return request.key + } catch (error) { + throw new Error(`Failed to restore: ${error.message}`) + } finally { + try { + if (archivePath) { + await utils.unlinkFile(archivePath) + } + } catch (error) { + core.debug(`Failed to delete archive: ${error}`) + } + } +} + /** * Saves a list of files with the specified key * @@ -171,6 +317,31 @@ export async function saveCache( checkPaths(paths) checkKey(key) + const cacheServiceVersion: string = getCacheServiceVersion() + switch (cacheServiceVersion) { + case 'v2': + return await saveCacheV2(paths, key, options, enableCrossOsArchive) + case 'v1': + default: + return await saveCacheV1(paths, key, options, enableCrossOsArchive) + } +} + +/** + * Save cache using the legacy Cache Service + * + * @param paths + * @param key + * @param options + * @param enableCrossOsArchive + * @returns + */ +async function saveCacheV1( + paths: string[], + key: string, + options?: UploadOptions, + enableCrossOsArchive = false +): Promise { const compressionMethod = await utils.getCompressionMethod() let cacheId = -1 @@ -202,7 +373,7 @@ export async function saveCache( core.debug(`File Size: ${archiveFileSize}`) // For GHES, this check will take place in ReserveCache API with enterprise file size limit - if (archiveFileSize > fileSizeLimit && !utils.isGhes()) { + if (archiveFileSize > fileSizeLimit && !isGhes()) { throw new Error( `Cache size of ~${Math.round( archiveFileSize / (1024 * 1024) @@ -258,3 +429,111 @@ export async function saveCache( return cacheId } + +/** + * Save cache using the new Cache Service + * + * @param paths + * @param key + * @param options + * @param enableCrossOsArchive + * @returns + */ +async function saveCacheV2( + paths: string[], + key: string, + options?: UploadOptions, + enableCrossOsArchive = false +): Promise { + const compressionMethod = await utils.getCompressionMethod() + const twirpClient = cacheTwirpClient.internalCacheTwirpClient() + let cacheId = -1 + + const cachePaths = await utils.resolvePaths(paths) + core.debug('Cache Paths:') + core.debug(`${JSON.stringify(cachePaths)}`) + + if (cachePaths.length === 0) { + throw new Error( + `Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.` + ) + } + + const archiveFolder = await utils.createTempDirectory() + const archivePath = path.join( + archiveFolder, + utils.getCacheFileName(compressionMethod) + ) + + core.debug(`Archive Path: ${archivePath}`) + + try { + await createTar(archiveFolder, cachePaths, compressionMethod) + if (core.isDebug()) { + await listTar(archivePath, compressionMethod) + } + + const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath) + core.debug(`File Size: ${archiveFileSize}`) + + // For GHES, this check will take place in ReserveCache API with enterprise file size limit + if (archiveFileSize > CacheFileSizeLimit && !isGhes()) { + throw new Error( + `Cache size of ~${Math.round( + archiveFileSize / (1024 * 1024) + )} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.` + ) + } + + core.debug('Reserving Cache') + const version = utils.getCacheVersion( + paths, + compressionMethod, + enableCrossOsArchive + ) + const request: CreateCacheEntryRequest = { + key, + version + } + + const response = await twirpClient.CreateCacheEntry(request) + if (!response.ok) { + throw new ReserveCacheError( + `Unable to reserve cache with key ${key}, another job may be creating this cache.` + ) + } + + core.debug(`Attempting to upload cache located at: ${archivePath}`) + await uploadCacheFile(response.signedUploadUrl, archivePath) + + const finalizeRequest: FinalizeCacheEntryUploadRequest = { + key, + version, + sizeBytes: `${archiveFileSize}` + } + + const finalizeResponse: FinalizeCacheEntryUploadResponse = + await twirpClient.FinalizeCacheEntryUpload(finalizeRequest) + core.debug(`FinalizeCacheEntryUploadResponse: ${finalizeResponse.ok}`) + + if (!finalizeResponse.ok) { + throw new Error( + `Unable to finalize cache with key ${key}, another job may be finalizing this cache.` + ) + } + + cacheId = parseInt(finalizeResponse.entryId) + } catch (error) { + const typedError = error as Error + core.warning(`Failed to save: ${typedError.message}`) + } finally { + // Try to delete the archive to save space + try { + await utils.unlinkFile(archivePath) + } catch (error) { + core.debug(`Failed to delete archive: ${error}`) + } + } + + return cacheId +} diff --git a/packages/cache/src/generated/google/protobuf/timestamp.ts b/packages/cache/src/generated/google/protobuf/timestamp.ts new file mode 100644 index 00000000..3ef86d56 --- /dev/null +++ b/packages/cache/src/generated/google/protobuf/timestamp.ts @@ -0,0 +1,290 @@ +// @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_none,generate_dependencies +// @generated from protobuf file "google/protobuf/timestamp.proto" (package "google.protobuf", syntax proto3) +// tslint:disable +// +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; +import type { IBinaryWriter } from "@protobuf-ts/runtime"; +import { WireType } from "@protobuf-ts/runtime"; +import type { BinaryReadOptions } from "@protobuf-ts/runtime"; +import type { IBinaryReader } from "@protobuf-ts/runtime"; +import { UnknownFieldHandler } from "@protobuf-ts/runtime"; +import type { PartialMessage } from "@protobuf-ts/runtime"; +import { reflectionMergePartial } from "@protobuf-ts/runtime"; +import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; +import { typeofJsonValue } from "@protobuf-ts/runtime"; +import type { JsonValue } from "@protobuf-ts/runtime"; +import type { JsonReadOptions } from "@protobuf-ts/runtime"; +import type { JsonWriteOptions } from "@protobuf-ts/runtime"; +import { PbLong } from "@protobuf-ts/runtime"; +import { MessageType } from "@protobuf-ts/runtime"; +/** + * A Timestamp represents a point in time independent of any time zone or local + * calendar, encoded as a count of seconds and fractions of seconds at + * nanosecond resolution. The count is relative to an epoch at UTC midnight on + * January 1, 1970, in the proleptic Gregorian calendar which extends the + * Gregorian calendar backwards to year one. + * + * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + * second table is needed for interpretation, using a [24-hour linear + * smear](https://developers.google.com/time/smear). + * + * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + * restricting to that range, we ensure that we can convert to and from [RFC + * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + * + * # Examples + * + * Example 1: Compute Timestamp from POSIX `time()`. + * + * Timestamp timestamp; + * timestamp.set_seconds(time(NULL)); + * timestamp.set_nanos(0); + * + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. + * + * struct timeval tv; + * gettimeofday(&tv, NULL); + * + * Timestamp timestamp; + * timestamp.set_seconds(tv.tv_sec); + * timestamp.set_nanos(tv.tv_usec * 1000); + * + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + * + * FILETIME ft; + * GetSystemTimeAsFileTime(&ft); + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + * + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + * Timestamp timestamp; + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + * + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + * + * long millis = System.currentTimeMillis(); + * + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + * .setNanos((int) ((millis % 1000) * 1000000)).build(); + * + * + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * + * Example 6: Compute Timestamp from current time in Python. + * + * timestamp = Timestamp() + * timestamp.GetCurrentTime() + * + * # JSON Mapping + * + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required. A proto3 JSON serializer should always use UTC (as indicated by + * "Z") when printing the Timestamp type and a proto3 JSON parser should be + * able to accept both UTC and other timezones (as indicated by an offset). + * + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * + * In JavaScript, one can convert a Date object to this format using the + * standard + * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using + * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + * the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D + * ) to obtain a formatter capable of generating timestamps in this format. + * + * + * + * @generated from protobuf message google.protobuf.Timestamp + */ +export interface Timestamp { + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * @generated from protobuf field: int64 seconds = 1; + */ + seconds: string; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * @generated from protobuf field: int32 nanos = 2; + */ + nanos: number; +} +// @generated message type with reflection information, may provide speed optimized methods +class Timestamp$Type extends MessageType { + constructor() { + super("google.protobuf.Timestamp", [ + { no: 1, name: "seconds", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, + { no: 2, name: "nanos", kind: "scalar", T: 5 /*ScalarType.INT32*/ } + ]); + } + /** + * Creates a new `Timestamp` for the current time. + */ + now(): Timestamp { + const msg = this.create(); + const ms = Date.now(); + msg.seconds = PbLong.from(Math.floor(ms / 1000)).toString(); + msg.nanos = (ms % 1000) * 1000000; + return msg; + } + /** + * Converts a `Timestamp` to a JavaScript Date. + */ + toDate(message: Timestamp): Date { + return new Date(PbLong.from(message.seconds).toNumber() * 1000 + Math.ceil(message.nanos / 1000000)); + } + /** + * Converts a JavaScript Date to a `Timestamp`. + */ + fromDate(date: Date): Timestamp { + const msg = this.create(); + const ms = date.getTime(); + msg.seconds = PbLong.from(Math.floor(ms / 1000)).toString(); + msg.nanos = (ms % 1000) * 1000000; + return msg; + } + /** + * In JSON format, the `Timestamp` type is encoded as a string + * in the RFC 3339 format. + */ + internalJsonWrite(message: Timestamp, options: JsonWriteOptions): JsonValue { + let ms = PbLong.from(message.seconds).toNumber() * 1000; + if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) + throw new Error("Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."); + if (message.nanos < 0) + throw new Error("Unable to encode invalid Timestamp to JSON. Nanos must not be negative."); + let z = "Z"; + if (message.nanos > 0) { + let nanosStr = (message.nanos + 1000000000).toString().substring(1); + if (nanosStr.substring(3) === "000000") + z = "." + nanosStr.substring(0, 3) + "Z"; + else if (nanosStr.substring(6) === "000") + z = "." + nanosStr.substring(0, 6) + "Z"; + else + z = "." + nanosStr + "Z"; + } + return new Date(ms).toISOString().replace(".000Z", z); + } + /** + * In JSON format, the `Timestamp` type is encoded as a string + * in the RFC 3339 format. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Timestamp): Timestamp { + if (typeof json !== "string") + throw new Error("Unable to parse Timestamp from JSON " + typeofJsonValue(json) + "."); + let matches = json.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/); + if (!matches) + throw new Error("Unable to parse Timestamp from JSON. Invalid format."); + let ms = Date.parse(matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z")); + if (Number.isNaN(ms)) + throw new Error("Unable to parse Timestamp from JSON. Invalid value."); + if (ms < Date.parse("0001-01-01T00:00:00Z") || ms > Date.parse("9999-12-31T23:59:59Z")) + throw new globalThis.Error("Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive."); + if (!target) + target = this.create(); + target.seconds = PbLong.from(ms / 1000).toString(); + target.nanos = 0; + if (matches[7]) + target.nanos = (parseInt("1" + matches[7] + "0".repeat(9 - matches[7].length)) - 1000000000); + return target; + } + create(value?: PartialMessage): Timestamp { + const message = { seconds: "0", nanos: 0 }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Timestamp): Timestamp { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* int64 seconds */ 1: + message.seconds = reader.int64().toString(); + break; + case /* int32 nanos */ 2: + message.nanos = reader.int32(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: Timestamp, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* int64 seconds = 1; */ + if (message.seconds !== "0") + writer.tag(1, WireType.Varint).int64(message.seconds); + /* int32 nanos = 2; */ + if (message.nanos !== 0) + writer.tag(2, WireType.Varint).int32(message.nanos); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.Timestamp + */ +export const Timestamp = new Timestamp$Type(); diff --git a/packages/cache/src/generated/google/protobuf/wrappers.ts b/packages/cache/src/generated/google/protobuf/wrappers.ts new file mode 100644 index 00000000..d60e2416 --- /dev/null +++ b/packages/cache/src/generated/google/protobuf/wrappers.ts @@ -0,0 +1,753 @@ +// @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_none,generate_dependencies +// @generated from protobuf file "google/protobuf/wrappers.proto" (package "google.protobuf", syntax proto3) +// tslint:disable +// +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// +// Wrappers for primitive (non-message) types. These types are useful +// for embedding primitives in the `google.protobuf.Any` type and for places +// where we need to distinguish between the absence of a primitive +// typed field and its default value. +// +// These wrappers have no meaningful use within repeated fields as they lack +// the ability to detect presence on individual elements. +// These wrappers have no meaningful use within a map or a oneof since +// individual entries of a map or fields of a oneof can already detect presence. +// +import { ScalarType } from "@protobuf-ts/runtime"; +import { LongType } from "@protobuf-ts/runtime"; +import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; +import type { IBinaryWriter } from "@protobuf-ts/runtime"; +import { WireType } from "@protobuf-ts/runtime"; +import type { BinaryReadOptions } from "@protobuf-ts/runtime"; +import type { IBinaryReader } from "@protobuf-ts/runtime"; +import { UnknownFieldHandler } from "@protobuf-ts/runtime"; +import type { PartialMessage } from "@protobuf-ts/runtime"; +import { reflectionMergePartial } from "@protobuf-ts/runtime"; +import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; +import type { JsonValue } from "@protobuf-ts/runtime"; +import type { JsonReadOptions } from "@protobuf-ts/runtime"; +import type { JsonWriteOptions } from "@protobuf-ts/runtime"; +import { MessageType } from "@protobuf-ts/runtime"; +/** + * Wrapper message for `double`. + * + * The JSON representation for `DoubleValue` is JSON number. + * + * @generated from protobuf message google.protobuf.DoubleValue + */ +export interface DoubleValue { + /** + * The double value. + * + * @generated from protobuf field: double value = 1; + */ + value: number; +} +/** + * Wrapper message for `float`. + * + * The JSON representation for `FloatValue` is JSON number. + * + * @generated from protobuf message google.protobuf.FloatValue + */ +export interface FloatValue { + /** + * The float value. + * + * @generated from protobuf field: float value = 1; + */ + value: number; +} +/** + * Wrapper message for `int64`. + * + * The JSON representation for `Int64Value` is JSON string. + * + * @generated from protobuf message google.protobuf.Int64Value + */ +export interface Int64Value { + /** + * The int64 value. + * + * @generated from protobuf field: int64 value = 1; + */ + value: string; +} +/** + * Wrapper message for `uint64`. + * + * The JSON representation for `UInt64Value` is JSON string. + * + * @generated from protobuf message google.protobuf.UInt64Value + */ +export interface UInt64Value { + /** + * The uint64 value. + * + * @generated from protobuf field: uint64 value = 1; + */ + value: string; +} +/** + * Wrapper message for `int32`. + * + * The JSON representation for `Int32Value` is JSON number. + * + * @generated from protobuf message google.protobuf.Int32Value + */ +export interface Int32Value { + /** + * The int32 value. + * + * @generated from protobuf field: int32 value = 1; + */ + value: number; +} +/** + * Wrapper message for `uint32`. + * + * The JSON representation for `UInt32Value` is JSON number. + * + * @generated from protobuf message google.protobuf.UInt32Value + */ +export interface UInt32Value { + /** + * The uint32 value. + * + * @generated from protobuf field: uint32 value = 1; + */ + value: number; +} +/** + * Wrapper message for `bool`. + * + * The JSON representation for `BoolValue` is JSON `true` and `false`. + * + * @generated from protobuf message google.protobuf.BoolValue + */ +export interface BoolValue { + /** + * The bool value. + * + * @generated from protobuf field: bool value = 1; + */ + value: boolean; +} +/** + * Wrapper message for `string`. + * + * The JSON representation for `StringValue` is JSON string. + * + * @generated from protobuf message google.protobuf.StringValue + */ +export interface StringValue { + /** + * The string value. + * + * @generated from protobuf field: string value = 1; + */ + value: string; +} +/** + * Wrapper message for `bytes`. + * + * The JSON representation for `BytesValue` is JSON string. + * + * @generated from protobuf message google.protobuf.BytesValue + */ +export interface BytesValue { + /** + * The bytes value. + * + * @generated from protobuf field: bytes value = 1; + */ + value: Uint8Array; +} +// @generated message type with reflection information, may provide speed optimized methods +class DoubleValue$Type extends MessageType { + constructor() { + super("google.protobuf.DoubleValue", [ + { no: 1, name: "value", kind: "scalar", T: 1 /*ScalarType.DOUBLE*/ } + ]); + } + /** + * Encode `DoubleValue` to JSON number. + */ + internalJsonWrite(message: DoubleValue, options: JsonWriteOptions): JsonValue { + return this.refJsonWriter.scalar(2, message.value, "value", false, true); + } + /** + * Decode `DoubleValue` from JSON number. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: DoubleValue): DoubleValue { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, 1, undefined, "value") as number; + return target; + } + create(value?: PartialMessage): DoubleValue { + const message = { value: 0 }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: DoubleValue): DoubleValue { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* double value */ 1: + message.value = reader.double(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: DoubleValue, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* double value = 1; */ + if (message.value !== 0) + writer.tag(1, WireType.Bit64).double(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.DoubleValue + */ +export const DoubleValue = new DoubleValue$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class FloatValue$Type extends MessageType { + constructor() { + super("google.protobuf.FloatValue", [ + { no: 1, name: "value", kind: "scalar", T: 2 /*ScalarType.FLOAT*/ } + ]); + } + /** + * Encode `FloatValue` to JSON number. + */ + internalJsonWrite(message: FloatValue, options: JsonWriteOptions): JsonValue { + return this.refJsonWriter.scalar(1, message.value, "value", false, true); + } + /** + * Decode `FloatValue` from JSON number. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: FloatValue): FloatValue { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, 1, undefined, "value") as number; + return target; + } + create(value?: PartialMessage): FloatValue { + const message = { value: 0 }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: FloatValue): FloatValue { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* float value */ 1: + message.value = reader.float(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: FloatValue, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* float value = 1; */ + if (message.value !== 0) + writer.tag(1, WireType.Bit32).float(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.FloatValue + */ +export const FloatValue = new FloatValue$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class Int64Value$Type extends MessageType { + constructor() { + super("google.protobuf.Int64Value", [ + { no: 1, name: "value", kind: "scalar", T: 3 /*ScalarType.INT64*/ } + ]); + } + /** + * Encode `Int64Value` to JSON string. + */ + internalJsonWrite(message: Int64Value, options: JsonWriteOptions): JsonValue { + return this.refJsonWriter.scalar(ScalarType.INT64, message.value, "value", false, true); + } + /** + * Decode `Int64Value` from JSON string. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Int64Value): Int64Value { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, ScalarType.INT64, LongType.STRING, "value") as any; + return target; + } + create(value?: PartialMessage): Int64Value { + const message = { value: "0" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Int64Value): Int64Value { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* int64 value */ 1: + message.value = reader.int64().toString(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: Int64Value, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* int64 value = 1; */ + if (message.value !== "0") + writer.tag(1, WireType.Varint).int64(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.Int64Value + */ +export const Int64Value = new Int64Value$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class UInt64Value$Type extends MessageType { + constructor() { + super("google.protobuf.UInt64Value", [ + { no: 1, name: "value", kind: "scalar", T: 4 /*ScalarType.UINT64*/ } + ]); + } + /** + * Encode `UInt64Value` to JSON string. + */ + internalJsonWrite(message: UInt64Value, options: JsonWriteOptions): JsonValue { + return this.refJsonWriter.scalar(ScalarType.UINT64, message.value, "value", false, true); + } + /** + * Decode `UInt64Value` from JSON string. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: UInt64Value): UInt64Value { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, ScalarType.UINT64, LongType.STRING, "value") as any; + return target; + } + create(value?: PartialMessage): UInt64Value { + const message = { value: "0" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: UInt64Value): UInt64Value { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* uint64 value */ 1: + message.value = reader.uint64().toString(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: UInt64Value, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* uint64 value = 1; */ + if (message.value !== "0") + writer.tag(1, WireType.Varint).uint64(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.UInt64Value + */ +export const UInt64Value = new UInt64Value$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class Int32Value$Type extends MessageType { + constructor() { + super("google.protobuf.Int32Value", [ + { no: 1, name: "value", kind: "scalar", T: 5 /*ScalarType.INT32*/ } + ]); + } + /** + * Encode `Int32Value` to JSON string. + */ + internalJsonWrite(message: Int32Value, options: JsonWriteOptions): JsonValue { + return this.refJsonWriter.scalar(5, message.value, "value", false, true); + } + /** + * Decode `Int32Value` from JSON string. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Int32Value): Int32Value { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, 5, undefined, "value") as number; + return target; + } + create(value?: PartialMessage): Int32Value { + const message = { value: 0 }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Int32Value): Int32Value { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* int32 value */ 1: + message.value = reader.int32(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: Int32Value, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* int32 value = 1; */ + if (message.value !== 0) + writer.tag(1, WireType.Varint).int32(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.Int32Value + */ +export const Int32Value = new Int32Value$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class UInt32Value$Type extends MessageType { + constructor() { + super("google.protobuf.UInt32Value", [ + { no: 1, name: "value", kind: "scalar", T: 13 /*ScalarType.UINT32*/ } + ]); + } + /** + * Encode `UInt32Value` to JSON string. + */ + internalJsonWrite(message: UInt32Value, options: JsonWriteOptions): JsonValue { + return this.refJsonWriter.scalar(13, message.value, "value", false, true); + } + /** + * Decode `UInt32Value` from JSON string. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: UInt32Value): UInt32Value { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, 13, undefined, "value") as number; + return target; + } + create(value?: PartialMessage): UInt32Value { + const message = { value: 0 }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: UInt32Value): UInt32Value { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* uint32 value */ 1: + message.value = reader.uint32(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: UInt32Value, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* uint32 value = 1; */ + if (message.value !== 0) + writer.tag(1, WireType.Varint).uint32(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.UInt32Value + */ +export const UInt32Value = new UInt32Value$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class BoolValue$Type extends MessageType { + constructor() { + super("google.protobuf.BoolValue", [ + { no: 1, name: "value", kind: "scalar", T: 8 /*ScalarType.BOOL*/ } + ]); + } + /** + * Encode `BoolValue` to JSON bool. + */ + internalJsonWrite(message: BoolValue, options: JsonWriteOptions): JsonValue { + return message.value; + } + /** + * Decode `BoolValue` from JSON bool. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: BoolValue): BoolValue { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, 8, undefined, "value") as boolean; + return target; + } + create(value?: PartialMessage): BoolValue { + const message = { value: false }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: BoolValue): BoolValue { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* bool value */ 1: + message.value = reader.bool(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: BoolValue, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* bool value = 1; */ + if (message.value !== false) + writer.tag(1, WireType.Varint).bool(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.BoolValue + */ +export const BoolValue = new BoolValue$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class StringValue$Type extends MessageType { + constructor() { + super("google.protobuf.StringValue", [ + { no: 1, name: "value", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + /** + * Encode `StringValue` to JSON string. + */ + internalJsonWrite(message: StringValue, options: JsonWriteOptions): JsonValue { + return message.value; + } + /** + * Decode `StringValue` from JSON string. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: StringValue): StringValue { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, 9, undefined, "value") as string; + return target; + } + create(value?: PartialMessage): StringValue { + const message = { value: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: StringValue): StringValue { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string value */ 1: + message.value = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: StringValue, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* string value = 1; */ + if (message.value !== "") + writer.tag(1, WireType.LengthDelimited).string(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.StringValue + */ +export const StringValue = new StringValue$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class BytesValue$Type extends MessageType { + constructor() { + super("google.protobuf.BytesValue", [ + { no: 1, name: "value", kind: "scalar", T: 12 /*ScalarType.BYTES*/ } + ]); + } + /** + * Encode `BytesValue` to JSON string. + */ + internalJsonWrite(message: BytesValue, options: JsonWriteOptions): JsonValue { + return this.refJsonWriter.scalar(12, message.value, "value", false, true); + } + /** + * Decode `BytesValue` from JSON string. + */ + internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: BytesValue): BytesValue { + if (!target) + target = this.create(); + target.value = this.refJsonReader.scalar(json, 12, undefined, "value") as Uint8Array; + return target; + } + create(value?: PartialMessage): BytesValue { + const message = { value: new Uint8Array(0) }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: BytesValue): BytesValue { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* bytes value */ 1: + message.value = reader.bytes(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: BytesValue, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* bytes value = 1; */ + if (message.value.length) + writer.tag(1, WireType.LengthDelimited).bytes(message.value); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message google.protobuf.BytesValue + */ +export const BytesValue = new BytesValue$Type(); diff --git a/packages/cache/src/generated/results/api/v1/cache.ts b/packages/cache/src/generated/results/api/v1/cache.ts new file mode 100644 index 00000000..0736c7ad --- /dev/null +++ b/packages/cache/src/generated/results/api/v1/cache.ts @@ -0,0 +1,1247 @@ +// @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_none,generate_dependencies +// @generated from protobuf file "results/api/v1/cache.proto" (package "github.actions.results.api.v1", syntax proto3) +// tslint:disable +import { ServiceType } from "@protobuf-ts/runtime-rpc"; +import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; +import type { IBinaryWriter } from "@protobuf-ts/runtime"; +import { WireType } from "@protobuf-ts/runtime"; +import type { BinaryReadOptions } from "@protobuf-ts/runtime"; +import type { IBinaryReader } from "@protobuf-ts/runtime"; +import { UnknownFieldHandler } from "@protobuf-ts/runtime"; +import type { PartialMessage } from "@protobuf-ts/runtime"; +import { reflectionMergePartial } from "@protobuf-ts/runtime"; +import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; +import { MessageType } from "@protobuf-ts/runtime"; +import { Timestamp } from "../../../google/protobuf/timestamp"; +import { CacheMetadata } from "../../entities/v1/cachemetadata"; +/** + * @generated from protobuf message github.actions.results.api.v1.CreateCacheEntryRequest + */ +export interface CreateCacheEntryRequest { + /** + * Scope and other metadata for the cache entry + * + * @generated from protobuf field: github.actions.results.entities.v1.CacheMetadata metadata = 1; + */ + metadata?: CacheMetadata; + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 2; + */ + key: string; + /** + * Hash of the compression tool, runner OS and paths cached + * + * @generated from protobuf field: string version = 3; + */ + version: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.CreateCacheEntryResponse + */ +export interface CreateCacheEntryResponse { + /** + * @generated from protobuf field: bool ok = 1; + */ + ok: boolean; + /** + * SAS URL to upload the cache archive + * + * @generated from protobuf field: string signed_upload_url = 2; + */ + signedUploadUrl: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.FinalizeCacheEntryUploadRequest + */ +export interface FinalizeCacheEntryUploadRequest { + /** + * Scope and other metadata for the cache entry + * + * @generated from protobuf field: github.actions.results.entities.v1.CacheMetadata metadata = 1; + */ + metadata?: CacheMetadata; + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 2; + */ + key: string; + /** + * Size of the cache archive in Bytes + * + * @generated from protobuf field: int64 size_bytes = 3; + */ + sizeBytes: string; + /** + * Hash of the compression tool, runner OS and paths cached + * + * @generated from protobuf field: string version = 4; + */ + version: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.FinalizeCacheEntryUploadResponse + */ +export interface FinalizeCacheEntryUploadResponse { + /** + * @generated from protobuf field: bool ok = 1; + */ + ok: boolean; + /** + * Cache entry database ID + * + * @generated from protobuf field: int64 entry_id = 2; + */ + entryId: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.GetCacheEntryDownloadURLRequest + */ +export interface GetCacheEntryDownloadURLRequest { + /** + * Scope and other metadata for the cache entry + * + * @generated from protobuf field: github.actions.results.entities.v1.CacheMetadata metadata = 1; + */ + metadata?: CacheMetadata; + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 2; + */ + key: string; + /** + * Restore keys used for prefix searching + * + * @generated from protobuf field: repeated string restore_keys = 3; + */ + restoreKeys: string[]; + /** + * Hash of the compression tool, runner OS and paths cached + * + * @generated from protobuf field: string version = 4; + */ + version: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.GetCacheEntryDownloadURLResponse + */ +export interface GetCacheEntryDownloadURLResponse { + /** + * @generated from protobuf field: bool ok = 1; + */ + ok: boolean; + /** + * SAS URL to download the cache archive + * + * @generated from protobuf field: string signed_download_url = 2; + */ + signedDownloadUrl: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.DeleteCacheEntryRequest + */ +export interface DeleteCacheEntryRequest { + /** + * Scope and other metadata for the cache entry + * + * @generated from protobuf field: github.actions.results.entities.v1.CacheMetadata metadata = 1; + */ + metadata?: CacheMetadata; + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 2; + */ + key: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.DeleteCacheEntryResponse + */ +export interface DeleteCacheEntryResponse { + /** + * @generated from protobuf field: bool ok = 1; + */ + ok: boolean; + /** + * Cache entry database ID + * + * @generated from protobuf field: int64 entry_id = 2; + */ + entryId: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.ListCacheEntriesRequest + */ +export interface ListCacheEntriesRequest { + /** + * Scope and other metadata for the cache entry + * + * @generated from protobuf field: github.actions.results.entities.v1.CacheMetadata metadata = 1; + */ + metadata?: CacheMetadata; + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 2; + */ + key: string; + /** + * Restore keys used for prefix searching + * + * @generated from protobuf field: repeated string restore_keys = 3; + */ + restoreKeys: string[]; +} +/** + * @generated from protobuf message github.actions.results.api.v1.ListCacheEntriesResponse + */ +export interface ListCacheEntriesResponse { + /** + * @generated from protobuf field: repeated github.actions.results.api.v1.ListCacheEntriesResponse.CacheEntry entries = 1; + */ + entries: ListCacheEntriesResponse_CacheEntry[]; +} +/** + * @generated from protobuf message github.actions.results.api.v1.ListCacheEntriesResponse.CacheEntry + */ +export interface ListCacheEntriesResponse_CacheEntry { + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 1; + */ + key: string; + /** + * SHA256 hex digest of the cache archive + * + * @generated from protobuf field: string hash = 2; + */ + hash: string; + /** + * Cache entry size in bytes + * + * @generated from protobuf field: int64 size_bytes = 3; + */ + sizeBytes: string; + /** + * Access scope + * + * @generated from protobuf field: string scope = 4; + */ + scope: string; + /** + * Version SHA256 hex digest + * + * @generated from protobuf field: string version = 5; + */ + version: string; + /** + * When the cache entry was created + * + * @generated from protobuf field: google.protobuf.Timestamp created_at = 6; + */ + createdAt?: Timestamp; + /** + * When the cache entry was last accessed + * + * @generated from protobuf field: google.protobuf.Timestamp last_accessed_at = 7; + */ + lastAccessedAt?: Timestamp; + /** + * When the cache entry is set to expire + * + * @generated from protobuf field: google.protobuf.Timestamp expires_at = 8; + */ + expiresAt?: Timestamp; +} +/** + * @generated from protobuf message github.actions.results.api.v1.LookupCacheEntryRequest + */ +export interface LookupCacheEntryRequest { + /** + * Scope and other metadata for the cache entry + * + * @generated from protobuf field: github.actions.results.entities.v1.CacheMetadata metadata = 1; + */ + metadata?: CacheMetadata; + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 2; + */ + key: string; + /** + * Restore keys used for prefix searching + * + * @generated from protobuf field: repeated string restore_keys = 3; + */ + restoreKeys: string[]; + /** + * Hash of the compression tool, runner OS and paths cached + * + * @generated from protobuf field: string version = 4; + */ + version: string; +} +/** + * @generated from protobuf message github.actions.results.api.v1.LookupCacheEntryResponse + */ +export interface LookupCacheEntryResponse { + /** + * Indicates whether the cache entry exists or not + * + * @generated from protobuf field: bool exists = 1; + */ + exists: boolean; +} +/** + * Matched cache entry metadata + * + * @generated from protobuf message github.actions.results.api.v1.LookupCacheEntryResponse.CacheEntry + */ +export interface LookupCacheEntryResponse_CacheEntry { + /** + * An explicit key for a cache entry + * + * @generated from protobuf field: string key = 1; + */ + key: string; + /** + * SHA256 hex digest of the cache archive + * + * @generated from protobuf field: string hash = 2; + */ + hash: string; + /** + * Cache entry size in bytes + * + * @generated from protobuf field: int64 size_bytes = 3; + */ + sizeBytes: string; + /** + * Access scope + * + * @generated from protobuf field: string scope = 4; + */ + scope: string; + /** + * Version SHA256 hex digest + * + * @generated from protobuf field: string version = 5; + */ + version: string; + /** + * When the cache entry was created + * + * @generated from protobuf field: google.protobuf.Timestamp created_at = 6; + */ + createdAt?: Timestamp; + /** + * When the cache entry was last accessed + * + * @generated from protobuf field: google.protobuf.Timestamp last_accessed_at = 7; + */ + lastAccessedAt?: Timestamp; + /** + * When the cache entry is set to expire + * + * @generated from protobuf field: google.protobuf.Timestamp expires_at = 8; + */ + expiresAt?: Timestamp; +} +// @generated message type with reflection information, may provide speed optimized methods +class CreateCacheEntryRequest$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.CreateCacheEntryRequest", [ + { no: 1, name: "metadata", kind: "message", T: () => CacheMetadata }, + { no: 2, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): CreateCacheEntryRequest { + const message = { key: "", version: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: CreateCacheEntryRequest): CreateCacheEntryRequest { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* github.actions.results.entities.v1.CacheMetadata metadata */ 1: + message.metadata = CacheMetadata.internalBinaryRead(reader, reader.uint32(), options, message.metadata); + break; + case /* string key */ 2: + message.key = reader.string(); + break; + case /* string version */ 3: + message.version = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: CreateCacheEntryRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* github.actions.results.entities.v1.CacheMetadata metadata = 1; */ + if (message.metadata) + CacheMetadata.internalBinaryWrite(message.metadata, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); + /* string key = 2; */ + if (message.key !== "") + writer.tag(2, WireType.LengthDelimited).string(message.key); + /* string version = 3; */ + if (message.version !== "") + writer.tag(3, WireType.LengthDelimited).string(message.version); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.CreateCacheEntryRequest + */ +export const CreateCacheEntryRequest = new CreateCacheEntryRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class CreateCacheEntryResponse$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.CreateCacheEntryResponse", [ + { no: 1, name: "ok", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }, + { no: 2, name: "signed_upload_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): CreateCacheEntryResponse { + const message = { ok: false, signedUploadUrl: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: CreateCacheEntryResponse): CreateCacheEntryResponse { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* bool ok */ 1: + message.ok = reader.bool(); + break; + case /* string signed_upload_url */ 2: + message.signedUploadUrl = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: CreateCacheEntryResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* bool ok = 1; */ + if (message.ok !== false) + writer.tag(1, WireType.Varint).bool(message.ok); + /* string signed_upload_url = 2; */ + if (message.signedUploadUrl !== "") + writer.tag(2, WireType.LengthDelimited).string(message.signedUploadUrl); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.CreateCacheEntryResponse + */ +export const CreateCacheEntryResponse = new CreateCacheEntryResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class FinalizeCacheEntryUploadRequest$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.FinalizeCacheEntryUploadRequest", [ + { no: 1, name: "metadata", kind: "message", T: () => CacheMetadata }, + { no: 2, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "size_bytes", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, + { no: 4, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): FinalizeCacheEntryUploadRequest { + const message = { key: "", sizeBytes: "0", version: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: FinalizeCacheEntryUploadRequest): FinalizeCacheEntryUploadRequest { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* github.actions.results.entities.v1.CacheMetadata metadata */ 1: + message.metadata = CacheMetadata.internalBinaryRead(reader, reader.uint32(), options, message.metadata); + break; + case /* string key */ 2: + message.key = reader.string(); + break; + case /* int64 size_bytes */ 3: + message.sizeBytes = reader.int64().toString(); + break; + case /* string version */ 4: + message.version = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: FinalizeCacheEntryUploadRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* github.actions.results.entities.v1.CacheMetadata metadata = 1; */ + if (message.metadata) + CacheMetadata.internalBinaryWrite(message.metadata, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); + /* string key = 2; */ + if (message.key !== "") + writer.tag(2, WireType.LengthDelimited).string(message.key); + /* int64 size_bytes = 3; */ + if (message.sizeBytes !== "0") + writer.tag(3, WireType.Varint).int64(message.sizeBytes); + /* string version = 4; */ + if (message.version !== "") + writer.tag(4, WireType.LengthDelimited).string(message.version); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.FinalizeCacheEntryUploadRequest + */ +export const FinalizeCacheEntryUploadRequest = new FinalizeCacheEntryUploadRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class FinalizeCacheEntryUploadResponse$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.FinalizeCacheEntryUploadResponse", [ + { no: 1, name: "ok", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }, + { no: 2, name: "entry_id", kind: "scalar", T: 3 /*ScalarType.INT64*/ } + ]); + } + create(value?: PartialMessage): FinalizeCacheEntryUploadResponse { + const message = { ok: false, entryId: "0" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: FinalizeCacheEntryUploadResponse): FinalizeCacheEntryUploadResponse { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* bool ok */ 1: + message.ok = reader.bool(); + break; + case /* int64 entry_id */ 2: + message.entryId = reader.int64().toString(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: FinalizeCacheEntryUploadResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* bool ok = 1; */ + if (message.ok !== false) + writer.tag(1, WireType.Varint).bool(message.ok); + /* int64 entry_id = 2; */ + if (message.entryId !== "0") + writer.tag(2, WireType.Varint).int64(message.entryId); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.FinalizeCacheEntryUploadResponse + */ +export const FinalizeCacheEntryUploadResponse = new FinalizeCacheEntryUploadResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class GetCacheEntryDownloadURLRequest$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.GetCacheEntryDownloadURLRequest", [ + { no: 1, name: "metadata", kind: "message", T: () => CacheMetadata }, + { no: 2, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "restore_keys", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ }, + { no: 4, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): GetCacheEntryDownloadURLRequest { + const message = { key: "", restoreKeys: [], version: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: GetCacheEntryDownloadURLRequest): GetCacheEntryDownloadURLRequest { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* github.actions.results.entities.v1.CacheMetadata metadata */ 1: + message.metadata = CacheMetadata.internalBinaryRead(reader, reader.uint32(), options, message.metadata); + break; + case /* string key */ 2: + message.key = reader.string(); + break; + case /* repeated string restore_keys */ 3: + message.restoreKeys.push(reader.string()); + break; + case /* string version */ 4: + message.version = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: GetCacheEntryDownloadURLRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* github.actions.results.entities.v1.CacheMetadata metadata = 1; */ + if (message.metadata) + CacheMetadata.internalBinaryWrite(message.metadata, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); + /* string key = 2; */ + if (message.key !== "") + writer.tag(2, WireType.LengthDelimited).string(message.key); + /* repeated string restore_keys = 3; */ + for (let i = 0; i < message.restoreKeys.length; i++) + writer.tag(3, WireType.LengthDelimited).string(message.restoreKeys[i]); + /* string version = 4; */ + if (message.version !== "") + writer.tag(4, WireType.LengthDelimited).string(message.version); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.GetCacheEntryDownloadURLRequest + */ +export const GetCacheEntryDownloadURLRequest = new GetCacheEntryDownloadURLRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class GetCacheEntryDownloadURLResponse$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.GetCacheEntryDownloadURLResponse", [ + { no: 1, name: "ok", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }, + { no: 2, name: "signed_download_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): GetCacheEntryDownloadURLResponse { + const message = { ok: false, signedDownloadUrl: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: GetCacheEntryDownloadURLResponse): GetCacheEntryDownloadURLResponse { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* bool ok */ 1: + message.ok = reader.bool(); + break; + case /* string signed_download_url */ 2: + message.signedDownloadUrl = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: GetCacheEntryDownloadURLResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* bool ok = 1; */ + if (message.ok !== false) + writer.tag(1, WireType.Varint).bool(message.ok); + /* string signed_download_url = 2; */ + if (message.signedDownloadUrl !== "") + writer.tag(2, WireType.LengthDelimited).string(message.signedDownloadUrl); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.GetCacheEntryDownloadURLResponse + */ +export const GetCacheEntryDownloadURLResponse = new GetCacheEntryDownloadURLResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class DeleteCacheEntryRequest$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.DeleteCacheEntryRequest", [ + { no: 1, name: "metadata", kind: "message", T: () => CacheMetadata }, + { no: 2, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): DeleteCacheEntryRequest { + const message = { key: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: DeleteCacheEntryRequest): DeleteCacheEntryRequest { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* github.actions.results.entities.v1.CacheMetadata metadata */ 1: + message.metadata = CacheMetadata.internalBinaryRead(reader, reader.uint32(), options, message.metadata); + break; + case /* string key */ 2: + message.key = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: DeleteCacheEntryRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* github.actions.results.entities.v1.CacheMetadata metadata = 1; */ + if (message.metadata) + CacheMetadata.internalBinaryWrite(message.metadata, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); + /* string key = 2; */ + if (message.key !== "") + writer.tag(2, WireType.LengthDelimited).string(message.key); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.DeleteCacheEntryRequest + */ +export const DeleteCacheEntryRequest = new DeleteCacheEntryRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class DeleteCacheEntryResponse$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.DeleteCacheEntryResponse", [ + { no: 1, name: "ok", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }, + { no: 2, name: "entry_id", kind: "scalar", T: 3 /*ScalarType.INT64*/ } + ]); + } + create(value?: PartialMessage): DeleteCacheEntryResponse { + const message = { ok: false, entryId: "0" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: DeleteCacheEntryResponse): DeleteCacheEntryResponse { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* bool ok */ 1: + message.ok = reader.bool(); + break; + case /* int64 entry_id */ 2: + message.entryId = reader.int64().toString(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: DeleteCacheEntryResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* bool ok = 1; */ + if (message.ok !== false) + writer.tag(1, WireType.Varint).bool(message.ok); + /* int64 entry_id = 2; */ + if (message.entryId !== "0") + writer.tag(2, WireType.Varint).int64(message.entryId); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.DeleteCacheEntryResponse + */ +export const DeleteCacheEntryResponse = new DeleteCacheEntryResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class ListCacheEntriesRequest$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.ListCacheEntriesRequest", [ + { no: 1, name: "metadata", kind: "message", T: () => CacheMetadata }, + { no: 2, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "restore_keys", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): ListCacheEntriesRequest { + const message = { key: "", restoreKeys: [] }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ListCacheEntriesRequest): ListCacheEntriesRequest { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* github.actions.results.entities.v1.CacheMetadata metadata */ 1: + message.metadata = CacheMetadata.internalBinaryRead(reader, reader.uint32(), options, message.metadata); + break; + case /* string key */ 2: + message.key = reader.string(); + break; + case /* repeated string restore_keys */ 3: + message.restoreKeys.push(reader.string()); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: ListCacheEntriesRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* github.actions.results.entities.v1.CacheMetadata metadata = 1; */ + if (message.metadata) + CacheMetadata.internalBinaryWrite(message.metadata, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); + /* string key = 2; */ + if (message.key !== "") + writer.tag(2, WireType.LengthDelimited).string(message.key); + /* repeated string restore_keys = 3; */ + for (let i = 0; i < message.restoreKeys.length; i++) + writer.tag(3, WireType.LengthDelimited).string(message.restoreKeys[i]); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.ListCacheEntriesRequest + */ +export const ListCacheEntriesRequest = new ListCacheEntriesRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class ListCacheEntriesResponse$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.ListCacheEntriesResponse", [ + { no: 1, name: "entries", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => ListCacheEntriesResponse_CacheEntry } + ]); + } + create(value?: PartialMessage): ListCacheEntriesResponse { + const message = { entries: [] }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ListCacheEntriesResponse): ListCacheEntriesResponse { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* repeated github.actions.results.api.v1.ListCacheEntriesResponse.CacheEntry entries */ 1: + message.entries.push(ListCacheEntriesResponse_CacheEntry.internalBinaryRead(reader, reader.uint32(), options)); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: ListCacheEntriesResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* repeated github.actions.results.api.v1.ListCacheEntriesResponse.CacheEntry entries = 1; */ + for (let i = 0; i < message.entries.length; i++) + ListCacheEntriesResponse_CacheEntry.internalBinaryWrite(message.entries[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join(); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.ListCacheEntriesResponse + */ +export const ListCacheEntriesResponse = new ListCacheEntriesResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class ListCacheEntriesResponse_CacheEntry$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.ListCacheEntriesResponse.CacheEntry", [ + { no: 1, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 2, name: "hash", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "size_bytes", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, + { no: 4, name: "scope", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 5, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 6, name: "created_at", kind: "message", T: () => Timestamp }, + { no: 7, name: "last_accessed_at", kind: "message", T: () => Timestamp }, + { no: 8, name: "expires_at", kind: "message", T: () => Timestamp } + ]); + } + create(value?: PartialMessage): ListCacheEntriesResponse_CacheEntry { + const message = { key: "", hash: "", sizeBytes: "0", scope: "", version: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: ListCacheEntriesResponse_CacheEntry): ListCacheEntriesResponse_CacheEntry { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string key */ 1: + message.key = reader.string(); + break; + case /* string hash */ 2: + message.hash = reader.string(); + break; + case /* int64 size_bytes */ 3: + message.sizeBytes = reader.int64().toString(); + break; + case /* string scope */ 4: + message.scope = reader.string(); + break; + case /* string version */ 5: + message.version = reader.string(); + break; + case /* google.protobuf.Timestamp created_at */ 6: + message.createdAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.createdAt); + break; + case /* google.protobuf.Timestamp last_accessed_at */ 7: + message.lastAccessedAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.lastAccessedAt); + break; + case /* google.protobuf.Timestamp expires_at */ 8: + message.expiresAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.expiresAt); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: ListCacheEntriesResponse_CacheEntry, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* string key = 1; */ + if (message.key !== "") + writer.tag(1, WireType.LengthDelimited).string(message.key); + /* string hash = 2; */ + if (message.hash !== "") + writer.tag(2, WireType.LengthDelimited).string(message.hash); + /* int64 size_bytes = 3; */ + if (message.sizeBytes !== "0") + writer.tag(3, WireType.Varint).int64(message.sizeBytes); + /* string scope = 4; */ + if (message.scope !== "") + writer.tag(4, WireType.LengthDelimited).string(message.scope); + /* string version = 5; */ + if (message.version !== "") + writer.tag(5, WireType.LengthDelimited).string(message.version); + /* google.protobuf.Timestamp created_at = 6; */ + if (message.createdAt) + Timestamp.internalBinaryWrite(message.createdAt, writer.tag(6, WireType.LengthDelimited).fork(), options).join(); + /* google.protobuf.Timestamp last_accessed_at = 7; */ + if (message.lastAccessedAt) + Timestamp.internalBinaryWrite(message.lastAccessedAt, writer.tag(7, WireType.LengthDelimited).fork(), options).join(); + /* google.protobuf.Timestamp expires_at = 8; */ + if (message.expiresAt) + Timestamp.internalBinaryWrite(message.expiresAt, writer.tag(8, WireType.LengthDelimited).fork(), options).join(); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.ListCacheEntriesResponse.CacheEntry + */ +export const ListCacheEntriesResponse_CacheEntry = new ListCacheEntriesResponse_CacheEntry$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class LookupCacheEntryRequest$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.LookupCacheEntryRequest", [ + { no: 1, name: "metadata", kind: "message", T: () => CacheMetadata }, + { no: 2, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "restore_keys", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 9 /*ScalarType.STRING*/ }, + { no: 4, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value?: PartialMessage): LookupCacheEntryRequest { + const message = { key: "", restoreKeys: [], version: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: LookupCacheEntryRequest): LookupCacheEntryRequest { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* github.actions.results.entities.v1.CacheMetadata metadata */ 1: + message.metadata = CacheMetadata.internalBinaryRead(reader, reader.uint32(), options, message.metadata); + break; + case /* string key */ 2: + message.key = reader.string(); + break; + case /* repeated string restore_keys */ 3: + message.restoreKeys.push(reader.string()); + break; + case /* string version */ 4: + message.version = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: LookupCacheEntryRequest, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* github.actions.results.entities.v1.CacheMetadata metadata = 1; */ + if (message.metadata) + CacheMetadata.internalBinaryWrite(message.metadata, writer.tag(1, WireType.LengthDelimited).fork(), options).join(); + /* string key = 2; */ + if (message.key !== "") + writer.tag(2, WireType.LengthDelimited).string(message.key); + /* repeated string restore_keys = 3; */ + for (let i = 0; i < message.restoreKeys.length; i++) + writer.tag(3, WireType.LengthDelimited).string(message.restoreKeys[i]); + /* string version = 4; */ + if (message.version !== "") + writer.tag(4, WireType.LengthDelimited).string(message.version); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.LookupCacheEntryRequest + */ +export const LookupCacheEntryRequest = new LookupCacheEntryRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class LookupCacheEntryResponse$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.LookupCacheEntryResponse", [ + { no: 1, name: "exists", kind: "scalar", T: 8 /*ScalarType.BOOL*/ } + ]); + } + create(value?: PartialMessage): LookupCacheEntryResponse { + const message = { exists: false }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: LookupCacheEntryResponse): LookupCacheEntryResponse { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* bool exists */ 1: + message.exists = reader.bool(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: LookupCacheEntryResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* bool exists = 1; */ + if (message.exists !== false) + writer.tag(1, WireType.Varint).bool(message.exists); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.LookupCacheEntryResponse + */ +export const LookupCacheEntryResponse = new LookupCacheEntryResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class LookupCacheEntryResponse_CacheEntry$Type extends MessageType { + constructor() { + super("github.actions.results.api.v1.LookupCacheEntryResponse.CacheEntry", [ + { no: 1, name: "key", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 2, name: "hash", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "size_bytes", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, + { no: 4, name: "scope", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 5, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 6, name: "created_at", kind: "message", T: () => Timestamp }, + { no: 7, name: "last_accessed_at", kind: "message", T: () => Timestamp }, + { no: 8, name: "expires_at", kind: "message", T: () => Timestamp } + ]); + } + create(value?: PartialMessage): LookupCacheEntryResponse_CacheEntry { + const message = { key: "", hash: "", sizeBytes: "0", scope: "", version: "" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: LookupCacheEntryResponse_CacheEntry): LookupCacheEntryResponse_CacheEntry { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string key */ 1: + message.key = reader.string(); + break; + case /* string hash */ 2: + message.hash = reader.string(); + break; + case /* int64 size_bytes */ 3: + message.sizeBytes = reader.int64().toString(); + break; + case /* string scope */ 4: + message.scope = reader.string(); + break; + case /* string version */ 5: + message.version = reader.string(); + break; + case /* google.protobuf.Timestamp created_at */ 6: + message.createdAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.createdAt); + break; + case /* google.protobuf.Timestamp last_accessed_at */ 7: + message.lastAccessedAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.lastAccessedAt); + break; + case /* google.protobuf.Timestamp expires_at */ 8: + message.expiresAt = Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.expiresAt); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: LookupCacheEntryResponse_CacheEntry, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* string key = 1; */ + if (message.key !== "") + writer.tag(1, WireType.LengthDelimited).string(message.key); + /* string hash = 2; */ + if (message.hash !== "") + writer.tag(2, WireType.LengthDelimited).string(message.hash); + /* int64 size_bytes = 3; */ + if (message.sizeBytes !== "0") + writer.tag(3, WireType.Varint).int64(message.sizeBytes); + /* string scope = 4; */ + if (message.scope !== "") + writer.tag(4, WireType.LengthDelimited).string(message.scope); + /* string version = 5; */ + if (message.version !== "") + writer.tag(5, WireType.LengthDelimited).string(message.version); + /* google.protobuf.Timestamp created_at = 6; */ + if (message.createdAt) + Timestamp.internalBinaryWrite(message.createdAt, writer.tag(6, WireType.LengthDelimited).fork(), options).join(); + /* google.protobuf.Timestamp last_accessed_at = 7; */ + if (message.lastAccessedAt) + Timestamp.internalBinaryWrite(message.lastAccessedAt, writer.tag(7, WireType.LengthDelimited).fork(), options).join(); + /* google.protobuf.Timestamp expires_at = 8; */ + if (message.expiresAt) + Timestamp.internalBinaryWrite(message.expiresAt, writer.tag(8, WireType.LengthDelimited).fork(), options).join(); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.LookupCacheEntryResponse.CacheEntry + */ +export const LookupCacheEntryResponse_CacheEntry = new LookupCacheEntryResponse_CacheEntry$Type(); +/** + * @generated ServiceType for protobuf service github.actions.results.api.v1.CacheService + */ +export const CacheService = new ServiceType("github.actions.results.api.v1.CacheService", [ + { name: "CreateCacheEntry", options: {}, I: CreateCacheEntryRequest, O: CreateCacheEntryResponse }, + { name: "FinalizeCacheEntryUpload", options: {}, I: FinalizeCacheEntryUploadRequest, O: FinalizeCacheEntryUploadResponse }, + { name: "GetCacheEntryDownloadURL", options: {}, I: GetCacheEntryDownloadURLRequest, O: GetCacheEntryDownloadURLResponse }, + { name: "DeleteCacheEntry", options: {}, I: DeleteCacheEntryRequest, O: DeleteCacheEntryResponse }, + { name: "ListCacheEntries", options: {}, I: ListCacheEntriesRequest, O: ListCacheEntriesResponse }, + { name: "LookupCacheEntry", options: {}, I: LookupCacheEntryRequest, O: LookupCacheEntryResponse } +]); diff --git a/packages/cache/src/generated/results/api/v1/cache.twirp.ts b/packages/cache/src/generated/results/api/v1/cache.twirp.ts new file mode 100644 index 00000000..c8f1f633 --- /dev/null +++ b/packages/cache/src/generated/results/api/v1/cache.twirp.ts @@ -0,0 +1,1209 @@ +import { + TwirpContext, + TwirpServer, + RouterEvents, + TwirpError, + TwirpErrorCode, + Interceptor, + TwirpContentType, + chainInterceptors, +} from "twirp-ts"; +import { + CreateCacheEntryRequest, + CreateCacheEntryResponse, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse, + GetCacheEntryDownloadURLRequest, + GetCacheEntryDownloadURLResponse, + DeleteCacheEntryRequest, + DeleteCacheEntryResponse, + ListCacheEntriesRequest, + ListCacheEntriesResponse, + LookupCacheEntryRequest, + LookupCacheEntryResponse, +} from "./cache"; + +//==================================// +// Client Code // +//==================================// + +interface Rpc { + request( + service: string, + method: string, + contentType: "application/json" | "application/protobuf", + data: object | Uint8Array + ): Promise; +} + +export interface CacheServiceClient { + CreateCacheEntry( + request: CreateCacheEntryRequest + ): Promise; + FinalizeCacheEntryUpload( + request: FinalizeCacheEntryUploadRequest + ): Promise; + GetCacheEntryDownloadURL( + request: GetCacheEntryDownloadURLRequest + ): Promise; + DeleteCacheEntry( + request: DeleteCacheEntryRequest + ): Promise; + ListCacheEntries( + request: ListCacheEntriesRequest + ): Promise; + LookupCacheEntry( + request: LookupCacheEntryRequest + ): Promise; +} + +export class CacheServiceClientJSON implements CacheServiceClient { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + this.CreateCacheEntry.bind(this); + this.FinalizeCacheEntryUpload.bind(this); + this.GetCacheEntryDownloadURL.bind(this); + this.DeleteCacheEntry.bind(this); + this.ListCacheEntries.bind(this); + this.LookupCacheEntry.bind(this); + } + CreateCacheEntry( + request: CreateCacheEntryRequest + ): Promise { + const data = CreateCacheEntryRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "CreateCacheEntry", + "application/json", + data as object + ); + return promise.then((data) => + CreateCacheEntryResponse.fromJson(data as any, { + ignoreUnknownFields: true, + }) + ); + } + + FinalizeCacheEntryUpload( + request: FinalizeCacheEntryUploadRequest + ): Promise { + const data = FinalizeCacheEntryUploadRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "FinalizeCacheEntryUpload", + "application/json", + data as object + ); + return promise.then((data) => + FinalizeCacheEntryUploadResponse.fromJson(data as any, { + ignoreUnknownFields: true, + }) + ); + } + + GetCacheEntryDownloadURL( + request: GetCacheEntryDownloadURLRequest + ): Promise { + const data = GetCacheEntryDownloadURLRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "GetCacheEntryDownloadURL", + "application/json", + data as object + ); + return promise.then((data) => + GetCacheEntryDownloadURLResponse.fromJson(data as any, { + ignoreUnknownFields: true, + }) + ); + } + + DeleteCacheEntry( + request: DeleteCacheEntryRequest + ): Promise { + const data = DeleteCacheEntryRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "DeleteCacheEntry", + "application/json", + data as object + ); + return promise.then((data) => + DeleteCacheEntryResponse.fromJson(data as any, { + ignoreUnknownFields: true, + }) + ); + } + + ListCacheEntries( + request: ListCacheEntriesRequest + ): Promise { + const data = ListCacheEntriesRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "ListCacheEntries", + "application/json", + data as object + ); + return promise.then((data) => + ListCacheEntriesResponse.fromJson(data as any, { + ignoreUnknownFields: true, + }) + ); + } + + LookupCacheEntry( + request: LookupCacheEntryRequest + ): Promise { + const data = LookupCacheEntryRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "LookupCacheEntry", + "application/json", + data as object + ); + return promise.then((data) => + LookupCacheEntryResponse.fromJson(data as any, { + ignoreUnknownFields: true, + }) + ); + } +} + +export class CacheServiceClientProtobuf implements CacheServiceClient { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + this.CreateCacheEntry.bind(this); + this.FinalizeCacheEntryUpload.bind(this); + this.GetCacheEntryDownloadURL.bind(this); + this.DeleteCacheEntry.bind(this); + this.ListCacheEntries.bind(this); + this.LookupCacheEntry.bind(this); + } + CreateCacheEntry( + request: CreateCacheEntryRequest + ): Promise { + const data = CreateCacheEntryRequest.toBinary(request); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "CreateCacheEntry", + "application/protobuf", + data + ); + return promise.then((data) => + CreateCacheEntryResponse.fromBinary(data as Uint8Array) + ); + } + + FinalizeCacheEntryUpload( + request: FinalizeCacheEntryUploadRequest + ): Promise { + const data = FinalizeCacheEntryUploadRequest.toBinary(request); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "FinalizeCacheEntryUpload", + "application/protobuf", + data + ); + return promise.then((data) => + FinalizeCacheEntryUploadResponse.fromBinary(data as Uint8Array) + ); + } + + GetCacheEntryDownloadURL( + request: GetCacheEntryDownloadURLRequest + ): Promise { + const data = GetCacheEntryDownloadURLRequest.toBinary(request); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "GetCacheEntryDownloadURL", + "application/protobuf", + data + ); + return promise.then((data) => + GetCacheEntryDownloadURLResponse.fromBinary(data as Uint8Array) + ); + } + + DeleteCacheEntry( + request: DeleteCacheEntryRequest + ): Promise { + const data = DeleteCacheEntryRequest.toBinary(request); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "DeleteCacheEntry", + "application/protobuf", + data + ); + return promise.then((data) => + DeleteCacheEntryResponse.fromBinary(data as Uint8Array) + ); + } + + ListCacheEntries( + request: ListCacheEntriesRequest + ): Promise { + const data = ListCacheEntriesRequest.toBinary(request); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "ListCacheEntries", + "application/protobuf", + data + ); + return promise.then((data) => + ListCacheEntriesResponse.fromBinary(data as Uint8Array) + ); + } + + LookupCacheEntry( + request: LookupCacheEntryRequest + ): Promise { + const data = LookupCacheEntryRequest.toBinary(request); + const promise = this.rpc.request( + "github.actions.results.api.v1.CacheService", + "LookupCacheEntry", + "application/protobuf", + data + ); + return promise.then((data) => + LookupCacheEntryResponse.fromBinary(data as Uint8Array) + ); + } +} + +//==================================// +// Server Code // +//==================================// + +export interface CacheServiceTwirp { + CreateCacheEntry( + ctx: T, + request: CreateCacheEntryRequest + ): Promise; + FinalizeCacheEntryUpload( + ctx: T, + request: FinalizeCacheEntryUploadRequest + ): Promise; + GetCacheEntryDownloadURL( + ctx: T, + request: GetCacheEntryDownloadURLRequest + ): Promise; + DeleteCacheEntry( + ctx: T, + request: DeleteCacheEntryRequest + ): Promise; + ListCacheEntries( + ctx: T, + request: ListCacheEntriesRequest + ): Promise; + LookupCacheEntry( + ctx: T, + request: LookupCacheEntryRequest + ): Promise; +} + +export enum CacheServiceMethod { + CreateCacheEntry = "CreateCacheEntry", + FinalizeCacheEntryUpload = "FinalizeCacheEntryUpload", + GetCacheEntryDownloadURL = "GetCacheEntryDownloadURL", + DeleteCacheEntry = "DeleteCacheEntry", + ListCacheEntries = "ListCacheEntries", + LookupCacheEntry = "LookupCacheEntry", +} + +export const CacheServiceMethodList = [ + CacheServiceMethod.CreateCacheEntry, + CacheServiceMethod.FinalizeCacheEntryUpload, + CacheServiceMethod.GetCacheEntryDownloadURL, + CacheServiceMethod.DeleteCacheEntry, + CacheServiceMethod.ListCacheEntries, + CacheServiceMethod.LookupCacheEntry, +]; + +export function createCacheServiceServer( + service: CacheServiceTwirp +) { + return new TwirpServer({ + service, + packageName: "github.actions.results.api.v1", + serviceName: "CacheService", + methodList: CacheServiceMethodList, + matchRoute: matchCacheServiceRoute, + }); +} + +function matchCacheServiceRoute( + method: string, + events: RouterEvents +) { + switch (method) { + case "CreateCacheEntry": + return async ( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + CreateCacheEntryRequest, + CreateCacheEntryResponse + >[] + ) => { + ctx = { ...ctx, methodName: "CreateCacheEntry" }; + await events.onMatch(ctx); + return handleCacheServiceCreateCacheEntryRequest( + ctx, + service, + data, + interceptors + ); + }; + case "FinalizeCacheEntryUpload": + return async ( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse + >[] + ) => { + ctx = { ...ctx, methodName: "FinalizeCacheEntryUpload" }; + await events.onMatch(ctx); + return handleCacheServiceFinalizeCacheEntryUploadRequest( + ctx, + service, + data, + interceptors + ); + }; + case "GetCacheEntryDownloadURL": + return async ( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + GetCacheEntryDownloadURLRequest, + GetCacheEntryDownloadURLResponse + >[] + ) => { + ctx = { ...ctx, methodName: "GetCacheEntryDownloadURL" }; + await events.onMatch(ctx); + return handleCacheServiceGetCacheEntryDownloadURLRequest( + ctx, + service, + data, + interceptors + ); + }; + case "DeleteCacheEntry": + return async ( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + DeleteCacheEntryRequest, + DeleteCacheEntryResponse + >[] + ) => { + ctx = { ...ctx, methodName: "DeleteCacheEntry" }; + await events.onMatch(ctx); + return handleCacheServiceDeleteCacheEntryRequest( + ctx, + service, + data, + interceptors + ); + }; + case "ListCacheEntries": + return async ( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + ListCacheEntriesRequest, + ListCacheEntriesResponse + >[] + ) => { + ctx = { ...ctx, methodName: "ListCacheEntries" }; + await events.onMatch(ctx); + return handleCacheServiceListCacheEntriesRequest( + ctx, + service, + data, + interceptors + ); + }; + case "LookupCacheEntry": + return async ( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + LookupCacheEntryRequest, + LookupCacheEntryResponse + >[] + ) => { + ctx = { ...ctx, methodName: "LookupCacheEntry" }; + await events.onMatch(ctx); + return handleCacheServiceLookupCacheEntryRequest( + ctx, + service, + data, + interceptors + ); + }; + default: + events.onNotFound(); + const msg = `no handler found`; + throw new TwirpError(TwirpErrorCode.BadRoute, msg); + } +} + +function handleCacheServiceCreateCacheEntryRequest< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + CreateCacheEntryRequest, + CreateCacheEntryResponse + >[] +): Promise { + switch (ctx.contentType) { + case TwirpContentType.JSON: + return handleCacheServiceCreateCacheEntryJSON( + ctx, + service, + data, + interceptors + ); + case TwirpContentType.Protobuf: + return handleCacheServiceCreateCacheEntryProtobuf( + ctx, + service, + data, + interceptors + ); + default: + const msg = "unexpected Content-Type"; + throw new TwirpError(TwirpErrorCode.BadRoute, msg); + } +} + +function handleCacheServiceFinalizeCacheEntryUploadRequest< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse + >[] +): Promise { + switch (ctx.contentType) { + case TwirpContentType.JSON: + return handleCacheServiceFinalizeCacheEntryUploadJSON( + ctx, + service, + data, + interceptors + ); + case TwirpContentType.Protobuf: + return handleCacheServiceFinalizeCacheEntryUploadProtobuf( + ctx, + service, + data, + interceptors + ); + default: + const msg = "unexpected Content-Type"; + throw new TwirpError(TwirpErrorCode.BadRoute, msg); + } +} + +function handleCacheServiceGetCacheEntryDownloadURLRequest< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + GetCacheEntryDownloadURLRequest, + GetCacheEntryDownloadURLResponse + >[] +): Promise { + switch (ctx.contentType) { + case TwirpContentType.JSON: + return handleCacheServiceGetCacheEntryDownloadURLJSON( + ctx, + service, + data, + interceptors + ); + case TwirpContentType.Protobuf: + return handleCacheServiceGetCacheEntryDownloadURLProtobuf( + ctx, + service, + data, + interceptors + ); + default: + const msg = "unexpected Content-Type"; + throw new TwirpError(TwirpErrorCode.BadRoute, msg); + } +} + +function handleCacheServiceDeleteCacheEntryRequest< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + DeleteCacheEntryRequest, + DeleteCacheEntryResponse + >[] +): Promise { + switch (ctx.contentType) { + case TwirpContentType.JSON: + return handleCacheServiceDeleteCacheEntryJSON( + ctx, + service, + data, + interceptors + ); + case TwirpContentType.Protobuf: + return handleCacheServiceDeleteCacheEntryProtobuf( + ctx, + service, + data, + interceptors + ); + default: + const msg = "unexpected Content-Type"; + throw new TwirpError(TwirpErrorCode.BadRoute, msg); + } +} + +function handleCacheServiceListCacheEntriesRequest< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + ListCacheEntriesRequest, + ListCacheEntriesResponse + >[] +): Promise { + switch (ctx.contentType) { + case TwirpContentType.JSON: + return handleCacheServiceListCacheEntriesJSON( + ctx, + service, + data, + interceptors + ); + case TwirpContentType.Protobuf: + return handleCacheServiceListCacheEntriesProtobuf( + ctx, + service, + data, + interceptors + ); + default: + const msg = "unexpected Content-Type"; + throw new TwirpError(TwirpErrorCode.BadRoute, msg); + } +} + +function handleCacheServiceLookupCacheEntryRequest< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + LookupCacheEntryRequest, + LookupCacheEntryResponse + >[] +): Promise { + switch (ctx.contentType) { + case TwirpContentType.JSON: + return handleCacheServiceLookupCacheEntryJSON( + ctx, + service, + data, + interceptors + ); + case TwirpContentType.Protobuf: + return handleCacheServiceLookupCacheEntryProtobuf( + ctx, + service, + data, + interceptors + ); + default: + const msg = "unexpected Content-Type"; + throw new TwirpError(TwirpErrorCode.BadRoute, msg); + } +} +async function handleCacheServiceCreateCacheEntryJSON< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + CreateCacheEntryRequest, + CreateCacheEntryResponse + >[] +) { + let request: CreateCacheEntryRequest; + let response: CreateCacheEntryResponse; + + try { + const body = JSON.parse(data.toString() || "{}"); + request = CreateCacheEntryRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + CreateCacheEntryRequest, + CreateCacheEntryResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.CreateCacheEntry(ctx, inputReq); + }); + } else { + response = await service.CreateCacheEntry(ctx, request!); + } + + return JSON.stringify( + CreateCacheEntryResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string + ); +} + +async function handleCacheServiceFinalizeCacheEntryUploadJSON< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse + >[] +) { + let request: FinalizeCacheEntryUploadRequest; + let response: FinalizeCacheEntryUploadResponse; + + try { + const body = JSON.parse(data.toString() || "{}"); + request = FinalizeCacheEntryUploadRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.FinalizeCacheEntryUpload(ctx, inputReq); + }); + } else { + response = await service.FinalizeCacheEntryUpload(ctx, request!); + } + + return JSON.stringify( + FinalizeCacheEntryUploadResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string + ); +} + +async function handleCacheServiceGetCacheEntryDownloadURLJSON< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + GetCacheEntryDownloadURLRequest, + GetCacheEntryDownloadURLResponse + >[] +) { + let request: GetCacheEntryDownloadURLRequest; + let response: GetCacheEntryDownloadURLResponse; + + try { + const body = JSON.parse(data.toString() || "{}"); + request = GetCacheEntryDownloadURLRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + GetCacheEntryDownloadURLRequest, + GetCacheEntryDownloadURLResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.GetCacheEntryDownloadURL(ctx, inputReq); + }); + } else { + response = await service.GetCacheEntryDownloadURL(ctx, request!); + } + + return JSON.stringify( + GetCacheEntryDownloadURLResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string + ); +} + +async function handleCacheServiceDeleteCacheEntryJSON< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + DeleteCacheEntryRequest, + DeleteCacheEntryResponse + >[] +) { + let request: DeleteCacheEntryRequest; + let response: DeleteCacheEntryResponse; + + try { + const body = JSON.parse(data.toString() || "{}"); + request = DeleteCacheEntryRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + DeleteCacheEntryRequest, + DeleteCacheEntryResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.DeleteCacheEntry(ctx, inputReq); + }); + } else { + response = await service.DeleteCacheEntry(ctx, request!); + } + + return JSON.stringify( + DeleteCacheEntryResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string + ); +} + +async function handleCacheServiceListCacheEntriesJSON< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + ListCacheEntriesRequest, + ListCacheEntriesResponse + >[] +) { + let request: ListCacheEntriesRequest; + let response: ListCacheEntriesResponse; + + try { + const body = JSON.parse(data.toString() || "{}"); + request = ListCacheEntriesRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + ListCacheEntriesRequest, + ListCacheEntriesResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.ListCacheEntries(ctx, inputReq); + }); + } else { + response = await service.ListCacheEntries(ctx, request!); + } + + return JSON.stringify( + ListCacheEntriesResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string + ); +} + +async function handleCacheServiceLookupCacheEntryJSON< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + LookupCacheEntryRequest, + LookupCacheEntryResponse + >[] +) { + let request: LookupCacheEntryRequest; + let response: LookupCacheEntryResponse; + + try { + const body = JSON.parse(data.toString() || "{}"); + request = LookupCacheEntryRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + LookupCacheEntryRequest, + LookupCacheEntryResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.LookupCacheEntry(ctx, inputReq); + }); + } else { + response = await service.LookupCacheEntry(ctx, request!); + } + + return JSON.stringify( + LookupCacheEntryResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string + ); +} +async function handleCacheServiceCreateCacheEntryProtobuf< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + CreateCacheEntryRequest, + CreateCacheEntryResponse + >[] +) { + let request: CreateCacheEntryRequest; + let response: CreateCacheEntryResponse; + + try { + request = CreateCacheEntryRequest.fromBinary(data); + } catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + CreateCacheEntryRequest, + CreateCacheEntryResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.CreateCacheEntry(ctx, inputReq); + }); + } else { + response = await service.CreateCacheEntry(ctx, request!); + } + + return Buffer.from(CreateCacheEntryResponse.toBinary(response)); +} + +async function handleCacheServiceFinalizeCacheEntryUploadProtobuf< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse + >[] +) { + let request: FinalizeCacheEntryUploadRequest; + let response: FinalizeCacheEntryUploadResponse; + + try { + request = FinalizeCacheEntryUploadRequest.fromBinary(data); + } catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + FinalizeCacheEntryUploadRequest, + FinalizeCacheEntryUploadResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.FinalizeCacheEntryUpload(ctx, inputReq); + }); + } else { + response = await service.FinalizeCacheEntryUpload(ctx, request!); + } + + return Buffer.from(FinalizeCacheEntryUploadResponse.toBinary(response)); +} + +async function handleCacheServiceGetCacheEntryDownloadURLProtobuf< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + GetCacheEntryDownloadURLRequest, + GetCacheEntryDownloadURLResponse + >[] +) { + let request: GetCacheEntryDownloadURLRequest; + let response: GetCacheEntryDownloadURLResponse; + + try { + request = GetCacheEntryDownloadURLRequest.fromBinary(data); + } catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + GetCacheEntryDownloadURLRequest, + GetCacheEntryDownloadURLResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.GetCacheEntryDownloadURL(ctx, inputReq); + }); + } else { + response = await service.GetCacheEntryDownloadURL(ctx, request!); + } + + return Buffer.from(GetCacheEntryDownloadURLResponse.toBinary(response)); +} + +async function handleCacheServiceDeleteCacheEntryProtobuf< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + DeleteCacheEntryRequest, + DeleteCacheEntryResponse + >[] +) { + let request: DeleteCacheEntryRequest; + let response: DeleteCacheEntryResponse; + + try { + request = DeleteCacheEntryRequest.fromBinary(data); + } catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + DeleteCacheEntryRequest, + DeleteCacheEntryResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.DeleteCacheEntry(ctx, inputReq); + }); + } else { + response = await service.DeleteCacheEntry(ctx, request!); + } + + return Buffer.from(DeleteCacheEntryResponse.toBinary(response)); +} + +async function handleCacheServiceListCacheEntriesProtobuf< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + ListCacheEntriesRequest, + ListCacheEntriesResponse + >[] +) { + let request: ListCacheEntriesRequest; + let response: ListCacheEntriesResponse; + + try { + request = ListCacheEntriesRequest.fromBinary(data); + } catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + ListCacheEntriesRequest, + ListCacheEntriesResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.ListCacheEntries(ctx, inputReq); + }); + } else { + response = await service.ListCacheEntries(ctx, request!); + } + + return Buffer.from(ListCacheEntriesResponse.toBinary(response)); +} + +async function handleCacheServiceLookupCacheEntryProtobuf< + T extends TwirpContext = TwirpContext +>( + ctx: T, + service: CacheServiceTwirp, + data: Buffer, + interceptors?: Interceptor< + T, + LookupCacheEntryRequest, + LookupCacheEntryResponse + >[] +) { + let request: LookupCacheEntryRequest; + let response: LookupCacheEntryResponse; + + try { + request = LookupCacheEntryRequest.fromBinary(data); + } catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new TwirpError(TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + + if (interceptors && interceptors.length > 0) { + const interceptor = chainInterceptors(...interceptors) as Interceptor< + T, + LookupCacheEntryRequest, + LookupCacheEntryResponse + >; + response = await interceptor(ctx, request!, (ctx, inputReq) => { + return service.LookupCacheEntry(ctx, inputReq); + }); + } else { + response = await service.LookupCacheEntry(ctx, request!); + } + + return Buffer.from(LookupCacheEntryResponse.toBinary(response)); +} diff --git a/packages/cache/src/generated/results/entities/v1/cachemetadata.ts b/packages/cache/src/generated/results/entities/v1/cachemetadata.ts new file mode 100644 index 00000000..d7af1fe2 --- /dev/null +++ b/packages/cache/src/generated/results/entities/v1/cachemetadata.ts @@ -0,0 +1,85 @@ +// @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_none,generate_dependencies +// @generated from protobuf file "results/entities/v1/cachemetadata.proto" (package "github.actions.results.entities.v1", syntax proto3) +// tslint:disable +import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; +import type { IBinaryWriter } from "@protobuf-ts/runtime"; +import { WireType } from "@protobuf-ts/runtime"; +import type { BinaryReadOptions } from "@protobuf-ts/runtime"; +import type { IBinaryReader } from "@protobuf-ts/runtime"; +import { UnknownFieldHandler } from "@protobuf-ts/runtime"; +import type { PartialMessage } from "@protobuf-ts/runtime"; +import { reflectionMergePartial } from "@protobuf-ts/runtime"; +import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; +import { MessageType } from "@protobuf-ts/runtime"; +import { CacheScope } from "./cachescope"; +/** + * @generated from protobuf message github.actions.results.entities.v1.CacheMetadata + */ +export interface CacheMetadata { + /** + * Backend repository id + * + * @generated from protobuf field: int64 repository_id = 1; + */ + repositoryId: string; + /** + * Scopes for the cache entry + * + * @generated from protobuf field: repeated github.actions.results.entities.v1.CacheScope scope = 2; + */ + scope: CacheScope[]; +} +// @generated message type with reflection information, may provide speed optimized methods +class CacheMetadata$Type extends MessageType { + constructor() { + super("github.actions.results.entities.v1.CacheMetadata", [ + { no: 1, name: "repository_id", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, + { no: 2, name: "scope", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => CacheScope } + ]); + } + create(value?: PartialMessage): CacheMetadata { + const message = { repositoryId: "0", scope: [] }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: CacheMetadata): CacheMetadata { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* int64 repository_id */ 1: + message.repositoryId = reader.int64().toString(); + break; + case /* repeated github.actions.results.entities.v1.CacheScope scope */ 2: + message.scope.push(CacheScope.internalBinaryRead(reader, reader.uint32(), options)); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: CacheMetadata, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* int64 repository_id = 1; */ + if (message.repositoryId !== "0") + writer.tag(1, WireType.Varint).int64(message.repositoryId); + /* repeated github.actions.results.entities.v1.CacheScope scope = 2; */ + for (let i = 0; i < message.scope.length; i++) + CacheScope.internalBinaryWrite(message.scope[i], writer.tag(2, WireType.LengthDelimited).fork(), options).join(); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.entities.v1.CacheMetadata + */ +export const CacheMetadata = new CacheMetadata$Type(); diff --git a/packages/cache/src/generated/results/entities/v1/cachescope.ts b/packages/cache/src/generated/results/entities/v1/cachescope.ts new file mode 100644 index 00000000..248d9f36 --- /dev/null +++ b/packages/cache/src/generated/results/entities/v1/cachescope.ts @@ -0,0 +1,84 @@ +// @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_none,generate_dependencies +// @generated from protobuf file "results/entities/v1/cachescope.proto" (package "github.actions.results.entities.v1", syntax proto3) +// tslint:disable +import type { BinaryWriteOptions } from "@protobuf-ts/runtime"; +import type { IBinaryWriter } from "@protobuf-ts/runtime"; +import { WireType } from "@protobuf-ts/runtime"; +import type { BinaryReadOptions } from "@protobuf-ts/runtime"; +import type { IBinaryReader } from "@protobuf-ts/runtime"; +import { UnknownFieldHandler } from "@protobuf-ts/runtime"; +import type { PartialMessage } from "@protobuf-ts/runtime"; +import { reflectionMergePartial } from "@protobuf-ts/runtime"; +import { MESSAGE_TYPE } from "@protobuf-ts/runtime"; +import { MessageType } from "@protobuf-ts/runtime"; +/** + * @generated from protobuf message github.actions.results.entities.v1.CacheScope + */ +export interface CacheScope { + /** + * Determines the scope of the cache entry + * + * @generated from protobuf field: string scope = 1; + */ + scope: string; + /** + * None: 0 | Read: 1 | Write: 2 | All: (1|2) + * + * @generated from protobuf field: int64 permission = 2; + */ + permission: string; +} +// @generated message type with reflection information, may provide speed optimized methods +class CacheScope$Type extends MessageType { + constructor() { + super("github.actions.results.entities.v1.CacheScope", [ + { no: 1, name: "scope", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 2, name: "permission", kind: "scalar", T: 3 /*ScalarType.INT64*/ } + ]); + } + create(value?: PartialMessage): CacheScope { + const message = { scope: "", permission: "0" }; + globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + reflectionMergePartial(this, message, value); + return message; + } + internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: CacheScope): CacheScope { + let message = target ?? this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string scope */ 1: + message.scope = reader.string(); + break; + case /* int64 permission */ 2: + message.permission = reader.int64().toString(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message: CacheScope, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter { + /* string scope = 1; */ + if (message.scope !== "") + writer.tag(1, WireType.LengthDelimited).string(message.scope); + /* int64 permission = 2; */ + if (message.permission !== "0") + writer.tag(2, WireType.Varint).int64(message.permission); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.entities.v1.CacheScope + */ +export const CacheScope = new CacheScope$Type(); diff --git a/packages/cache/src/internal/blob/download-cache.ts b/packages/cache/src/internal/blob/download-cache.ts new file mode 100644 index 00000000..807c73a4 --- /dev/null +++ b/packages/cache/src/internal/blob/download-cache.ts @@ -0,0 +1,30 @@ +import * as core from '@actions/core' + +import { + BlobClient, + BlockBlobClient, + BlobDownloadOptions +} from '@azure/storage-blob' + +export async function downloadCacheFile( + signedUploadURL: string, + archivePath: string +): Promise<{}> { + const downloadOptions: BlobDownloadOptions = { + maxRetryRequests: 5 + } + + const blobClient: BlobClient = new BlobClient(signedUploadURL) + const blockBlobClient: BlockBlobClient = blobClient.getBlockBlobClient() + + core.debug( + `BlobClient: ${blobClient.name}:${blobClient.accountName}:${blobClient.containerName}` + ) + + return blockBlobClient.downloadToFile( + archivePath, + 0, + undefined, + downloadOptions + ) +} diff --git a/packages/cache/src/internal/blob/upload-cache.ts b/packages/cache/src/internal/blob/upload-cache.ts new file mode 100644 index 00000000..15c913ed --- /dev/null +++ b/packages/cache/src/internal/blob/upload-cache.ts @@ -0,0 +1,27 @@ +import * as core from '@actions/core' +import { + BlobClient, + BlockBlobClient, + BlockBlobParallelUploadOptions +} from '@azure/storage-blob' + +export async function uploadCacheFile( + signedUploadURL: string, + archivePath: string +): Promise<{}> { + // Specify data transfer options + const uploadOptions: BlockBlobParallelUploadOptions = { + blockSize: 4 * 1024 * 1024, // 4 MiB max block size + concurrency: 4, // maximum number of parallel transfer workers + maxSingleShotSize: 8 * 1024 * 1024 // 8 MiB initial transfer size + } + + const blobClient: BlobClient = new BlobClient(signedUploadURL) + const blockBlobClient: BlockBlobClient = blobClient.getBlockBlobClient() + + core.debug( + `BlobClient: ${blobClient.name}:${blobClient.accountName}:${blobClient.containerName}` + ) + + return blockBlobClient.uploadFile(archivePath, uploadOptions) +} diff --git a/packages/cache/src/internal/cacheHttpClient.ts b/packages/cache/src/internal/cacheHttpClient.ts index f96ca381..051348ec 100644 --- a/packages/cache/src/internal/cacheHttpClient.ts +++ b/packages/cache/src/internal/cacheHttpClient.ts @@ -5,12 +5,9 @@ import { RequestOptions, TypedResponse } from '@actions/http-client/lib/interfaces' -import * as crypto from 'crypto' import * as fs from 'fs' import {URL} from 'url' - import * as utils from './cacheUtils' -import {CompressionMethod} from './constants' import { ArtifactCacheEntry, InternalCacheOptions, @@ -36,11 +33,10 @@ import { retryHttpClientResponse, retryTypedResponse } from './requestUtils' - -const versionSalt = '1.0' +import {getCacheServiceURL} from './config' function getCacheApiUrl(resource: string): string { - const baseUrl: string = process.env['ACTIONS_CACHE_URL'] || '' + const baseUrl: string = getCacheServiceURL() if (!baseUrl) { throw new Error('Cache Service Url not found, unable to restore cache.') } @@ -75,42 +71,18 @@ function createHttpClient(): HttpClient { ) } -export function getCacheVersion( - paths: string[], - compressionMethod?: CompressionMethod, - enableCrossOsArchive = false -): string { - // don't pass changes upstream - const components = paths.slice() - - // Add compression method to cache version to restore - // compressed cache as per compression method - if (compressionMethod) { - components.push(compressionMethod) - } - - // Only check for windows platforms if enableCrossOsArchive is false - if (process.platform === 'win32' && !enableCrossOsArchive) { - components.push('windows-only') - } - - // Add salt to cache version to support breaking changes in cache entry - components.push(versionSalt) - - return crypto.createHash('sha256').update(components.join('|')).digest('hex') -} - export async function getCacheEntry( keys: string[], paths: string[], options?: InternalCacheOptions ): Promise { const httpClient = createHttpClient() - const version = getCacheVersion( + const version = utils.getCacheVersion( paths, options?.compressionMethod, options?.enableCrossOsArchive ) + const resource = `cache?keys=${encodeURIComponent( keys.join(',') )}&version=${version}` @@ -207,7 +179,7 @@ export async function reserveCache( options?: InternalCacheOptions ): Promise> { const httpClient = createHttpClient() - const version = getCacheVersion( + const version = utils.getCacheVersion( paths, options?.compressionMethod, options?.enableCrossOsArchive diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index 4c2a16f3..de9053ea 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/src/internal/cacheUtils.ts @@ -13,6 +13,8 @@ import { GnuTarPathOnWindows } from './constants' +const versionSalt = '1.0' + // From https://github.com/actions/toolkit/blob/main/packages/tool-cache/src/tool-cache.ts#L23 export async function createTempDirectory(): Promise { const IS_WINDOWS = process.platform === 'win32' @@ -131,15 +133,35 @@ export function assertDefined(name: string, value?: T): T { return value } -export function isGhes(): boolean { - const ghUrl = new URL( - process.env['GITHUB_SERVER_URL'] || 'https://github.com' - ) +export function getCacheVersion( + paths: string[], + compressionMethod?: CompressionMethod, + enableCrossOsArchive = false +): string { + // don't pass changes upstream + const components = paths.slice() - const hostname = ghUrl.hostname.trimEnd().toUpperCase() - const isGitHubHost = hostname === 'GITHUB.COM' - const isGheHost = - hostname.endsWith('.GHE.COM') || hostname.endsWith('.GHE.LOCALHOST') + // Add compression method to cache version to restore + // compressed cache as per compression method + if (compressionMethod) { + components.push(compressionMethod) + } - return !isGitHubHost && !isGheHost + // Only check for windows platforms if enableCrossOsArchive is false + if (process.platform === 'win32' && !enableCrossOsArchive) { + components.push('windows-only') + } + + // Add salt to cache version to support breaking changes in cache entry + components.push(versionSalt) + + return crypto.createHash('sha256').update(components.join('|')).digest('hex') +} + +export function getRuntimeToken(): string { + const token = process.env['ACTIONS_RUNTIME_TOKEN'] + if (!token) { + throw new Error('Unable to get the ACTIONS_RUNTIME_TOKEN env variable') + } + return token } diff --git a/packages/cache/src/internal/config.ts b/packages/cache/src/internal/config.ts new file mode 100644 index 00000000..24b9fa1a --- /dev/null +++ b/packages/cache/src/internal/config.ts @@ -0,0 +1,39 @@ +export function isGhes(): boolean { + const ghUrl = new URL( + process.env['GITHUB_SERVER_URL'] || 'https://github.com' + ) + + const hostname = ghUrl.hostname.trimEnd().toUpperCase() + const isGitHubHost = hostname === 'GITHUB.COM' + const isGheHost = hostname.endsWith('.GHE.COM') + const isLocalHost = hostname.endsWith('.LOCALHOST') + + return !isGitHubHost && !isGheHost && !isLocalHost +} + +export function getCacheServiceVersion(): string { + // Cache service v2 is not supported on GHES. We will default to + // cache service v1 even if the feature flag was enabled by user. + if (isGhes()) return 'v1' + + return process.env['ACTIONS_CACHE_SERVICE_V2'] ? 'v2' : 'v1' +} + +export function getCacheServiceURL(): string { + const version = getCacheServiceVersion() + + // Based on the version of the cache service, we will determine which + // URL to use. + switch (version) { + case 'v1': + return ( + process.env['ACTIONS_CACHE_URL'] || + process.env['ACTIONS_RESULTS_URL'] || + '' + ) + case 'v2': + return process.env['ACTIONS_RESULTS_URL'] || '' + default: + throw new Error(`Unsupported cache service version: ${version}`) + } +} diff --git a/packages/cache/src/internal/constants.ts b/packages/cache/src/internal/constants.ts index 4dbff574..8c5d1ee4 100644 --- a/packages/cache/src/internal/constants.ts +++ b/packages/cache/src/internal/constants.ts @@ -36,3 +36,5 @@ export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\S export const TarFilename = 'cache.tar' export const ManifestFilename = 'manifest.txt' + +export const CacheFileSizeLimit = 10 * Math.pow(1024, 3) // 10GiB per repository diff --git a/packages/cache/src/internal/shared/cacheTwirpClient.ts b/packages/cache/src/internal/shared/cacheTwirpClient.ts new file mode 100644 index 00000000..9394a08c --- /dev/null +++ b/packages/cache/src/internal/shared/cacheTwirpClient.ts @@ -0,0 +1,204 @@ +import {info, debug} from '@actions/core' +import {getUserAgentString} from './user-agent' +import {NetworkError, UsageError} from './errors' +import {getCacheServiceURL} from '../config' +import {getRuntimeToken} from '../cacheUtils' +import {BearerCredentialHandler} from '@actions/http-client/lib/auth' +import {HttpClient, HttpClientResponse, HttpCodes} from '@actions/http-client' +import {CacheServiceClientJSON} from '../../generated/results/api/v1/cache.twirp' + +// The twirp http client must implement this interface +interface Rpc { + request( + service: string, + method: string, + contentType: 'application/json' | 'application/protobuf', + data: object | Uint8Array + ): Promise +} + +/** + * This class is a wrapper around the CacheServiceClientJSON class generated by Twirp. + * + * It adds retry logic to the request method, which is not present in the generated client. + * + * This class is used to interact with cache service v2. + */ +class CacheServiceClient implements Rpc { + private httpClient: HttpClient + private baseUrl: string + private maxAttempts = 5 + private baseRetryIntervalMilliseconds = 3000 + private retryMultiplier = 1.5 + + constructor( + userAgent: string, + maxAttempts?: number, + baseRetryIntervalMilliseconds?: number, + retryMultiplier?: number + ) { + const token = getRuntimeToken() + this.baseUrl = getCacheServiceURL() + if (maxAttempts) { + this.maxAttempts = maxAttempts + } + if (baseRetryIntervalMilliseconds) { + this.baseRetryIntervalMilliseconds = baseRetryIntervalMilliseconds + } + if (retryMultiplier) { + this.retryMultiplier = retryMultiplier + } + + this.httpClient = new HttpClient(userAgent, [ + new BearerCredentialHandler(token) + ]) + } + + // This function satisfies the Rpc interface. It is compatible with the JSON + // JSON generated client. + async request( + service: string, + method: string, + contentType: 'application/json' | 'application/protobuf', + data: object | Uint8Array + ): Promise { + const url = new URL(`/twirp/${service}/${method}`, this.baseUrl).href + debug(`[Request] ${method} ${url}`) + const headers = { + 'Content-Type': contentType + } + try { + const {body} = await this.retryableRequest(async () => + this.httpClient.post(url, JSON.stringify(data), headers) + ) + + return body + } catch (error) { + throw new Error(`Failed to ${method}: ${error.message}`) + } + } + + async retryableRequest( + operation: () => Promise + ): Promise<{response: HttpClientResponse; body: object}> { + let attempt = 0 + let errorMessage = '' + let rawBody = '' + while (attempt < this.maxAttempts) { + let isRetryable = false + + try { + const response = await operation() + const statusCode = response.message.statusCode + rawBody = await response.readBody() + debug(`[Response] - ${response.message.statusCode}`) + debug(`Headers: ${JSON.stringify(response.message.headers, null, 2)}`) + const body = JSON.parse(rawBody) + debug(`Body: ${JSON.stringify(body, null, 2)}`) + if (this.isSuccessStatusCode(statusCode)) { + return {response, body} + } + isRetryable = this.isRetryableHttpStatusCode(statusCode) + errorMessage = `Failed request: (${statusCode}) ${response.message.statusMessage}` + if (body.msg) { + if (UsageError.isUsageErrorMessage(body.msg)) { + throw new UsageError() + } + + errorMessage = `${errorMessage}: ${body.msg}` + } + } catch (error) { + if (error instanceof SyntaxError) { + debug(`Raw Body: ${rawBody}`) + } + + if (error instanceof UsageError) { + throw error + } + + if (NetworkError.isNetworkErrorCode(error?.code)) { + throw new NetworkError(error?.code) + } + + isRetryable = true + errorMessage = error.message + } + + if (!isRetryable) { + throw new Error(`Received non-retryable error: ${errorMessage}`) + } + + if (attempt + 1 === this.maxAttempts) { + throw new Error( + `Failed to make request after ${this.maxAttempts} attempts: ${errorMessage}` + ) + } + + const retryTimeMilliseconds = + this.getExponentialRetryTimeMilliseconds(attempt) + info( + `Attempt ${attempt + 1} of ${ + this.maxAttempts + } failed with error: ${errorMessage}. Retrying request in ${retryTimeMilliseconds} ms...` + ) + await this.sleep(retryTimeMilliseconds) + attempt++ + } + + throw new Error(`Request failed`) + } + + isSuccessStatusCode(statusCode?: number): boolean { + if (!statusCode) return false + return statusCode >= 200 && statusCode < 300 + } + + isRetryableHttpStatusCode(statusCode?: number): boolean { + if (!statusCode) return false + + const retryableStatusCodes = [ + HttpCodes.BadGateway, + HttpCodes.GatewayTimeout, + HttpCodes.InternalServerError, + HttpCodes.ServiceUnavailable, + HttpCodes.TooManyRequests + ] + + return retryableStatusCodes.includes(statusCode) + } + + async sleep(milliseconds: number): Promise { + return new Promise(resolve => setTimeout(resolve, milliseconds)) + } + + getExponentialRetryTimeMilliseconds(attempt: number): number { + if (attempt < 0) { + throw new Error('attempt should be a positive integer') + } + + if (attempt === 0) { + return this.baseRetryIntervalMilliseconds + } + + const minTime = + this.baseRetryIntervalMilliseconds * this.retryMultiplier ** attempt + const maxTime = minTime * this.retryMultiplier + + // returns a random number between minTime and maxTime (exclusive) + return Math.trunc(Math.random() * (maxTime - minTime) + minTime) + } +} + +export function internalCacheTwirpClient(options?: { + maxAttempts?: number + retryIntervalMs?: number + retryMultiplier?: number +}): CacheServiceClientJSON { + const client = new CacheServiceClient( + getUserAgentString(), + options?.maxAttempts, + options?.retryIntervalMs, + options?.retryMultiplier + ) + return new CacheServiceClientJSON(client) +} diff --git a/packages/cache/src/internal/shared/errors.ts b/packages/cache/src/internal/shared/errors.ts new file mode 100644 index 00000000..9ec29f6b --- /dev/null +++ b/packages/cache/src/internal/shared/errors.ts @@ -0,0 +1,72 @@ +export class FilesNotFoundError extends Error { + files: string[] + + constructor(files: string[] = []) { + let message = 'No files were found to upload' + if (files.length > 0) { + message += `: ${files.join(', ')}` + } + + super(message) + this.files = files + this.name = 'FilesNotFoundError' + } +} + +export class InvalidResponseError extends Error { + constructor(message: string) { + super(message) + this.name = 'InvalidResponseError' + } +} + +export class CacheNotFoundError extends Error { + constructor(message = 'Cache not found') { + super(message) + this.name = 'CacheNotFoundError' + } +} + +export class GHESNotSupportedError extends Error { + constructor( + message = '@actions/cache v4.1.4+, actions/cache/save@v4+ and actions/cache/restore@v4+ are not currently supported on GHES.' + ) { + super(message) + this.name = 'GHESNotSupportedError' + } +} + +export class NetworkError extends Error { + code: string + + constructor(code: string) { + const message = `Unable to make request: ${code}\nIf you are using self-hosted runners, please make sure your runner has access to all GitHub endpoints: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#communication-between-self-hosted-runners-and-github` + super(message) + this.code = code + this.name = 'NetworkError' + } + + static isNetworkErrorCode = (code?: string): boolean => { + if (!code) return false + return [ + 'ECONNRESET', + 'ENOTFOUND', + 'ETIMEDOUT', + 'ECONNREFUSED', + 'EHOSTUNREACH' + ].includes(code) + } +} + +export class UsageError extends Error { + constructor() { + const message = `Cache storage quota has been hit. Unable to upload any new cache entries. Usage is recalculated every 6-12 hours.\nMore info on storage limits: https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#calculating-minute-and-storage-spending` + super(message) + this.name = 'UsageError' + } + + static isUsageErrorMessage = (msg?: string): boolean => { + if (!msg) return false + return msg.includes('insufficient usage') + } +} diff --git a/packages/cache/src/internal/shared/user-agent.ts b/packages/cache/src/internal/shared/user-agent.ts new file mode 100644 index 00000000..9d88a659 --- /dev/null +++ b/packages/cache/src/internal/shared/user-agent.ts @@ -0,0 +1,9 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports +const packageJson = require('../../../package.json') + +/** + * Ensure that this User Agent String is used in all HTTP calls so that we can monitor telemetry between different versions of this package + */ +export function getUserAgentString(): string { + return `@actions/cache-${packageJson.version}` +} diff --git a/packages/glob/package-lock.json b/packages/glob/package-lock.json index 17817543..665b11d5 100644 --- a/packages/glob/package-lock.json +++ b/packages/glob/package-lock.json @@ -21,7 +21,7 @@ "packages": { "": { "name": "@actions/glob", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "dependencies": { "@actions/core": "^1.9.1", diff --git a/packages/http-client/package-lock.json b/packages/http-client/package-lock.json index 823b38b7..c049b7c1 100644 --- a/packages/http-client/package-lock.json +++ b/packages/http-client/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@actions/http-client", - "version": "2.2.1", + "version": "2.2.3", "license": "MIT", "dependencies": { "tunnel": "^0.0.6",