From 4dadd612d6e122c49c46883d9c83d6f88cd3c975 Mon Sep 17 00:00:00 2001 From: Bassem Dghaidi <568794+Link-@users.noreply.github.com> Date: Mon, 25 Nov 2024 05:42:50 -0800 Subject: [PATCH] Add support for matching on restore key values --- .../cache/__tests__/restoreCacheV2.test.ts | 54 ++- packages/cache/src/cache.ts | 20 +- .../src/generated/results/api/v1/cache.ts | 342 ++---------------- .../results/entities/v1/cacheentry.ts | 163 +++++++++ 4 files changed, 249 insertions(+), 330 deletions(-) create mode 100644 packages/cache/src/generated/results/entities/v1/cacheentry.ts diff --git a/packages/cache/__tests__/restoreCacheV2.test.ts b/packages/cache/__tests__/restoreCacheV2.test.ts index 78b78aaa..f9fe0e9e 100644 --- a/packages/cache/__tests__/restoreCacheV2.test.ts +++ b/packages/cache/__tests__/restoreCacheV2.test.ts @@ -80,7 +80,13 @@ test('restore with no cache found', async () => { jest .spyOn(CacheServiceClientJSON.prototype, 'GetCacheEntryDownloadURL') - .mockReturnValue(Promise.resolve({ ok: false, signedDownloadUrl: '' })) + .mockReturnValue( + Promise.resolve({ + ok: false, + signedDownloadUrl: '', + matchedKey: '' + }) + ) const cacheKey = await restoreCache(paths, key) @@ -109,18 +115,24 @@ test('restore with server error should fail', async () => { test('restore with restore keys and no cache found', async () => { const paths = ['node_modules'] const key = 'node-test' - const restoreKey = 'node-' + const restoreKeys = ['node-'] const logWarningMock = jest.spyOn(core, 'warning') jest .spyOn(CacheServiceClientJSON.prototype, 'GetCacheEntryDownloadURL') - .mockReturnValue(Promise.resolve({ ok: false, signedDownloadUrl: '' })) + .mockReturnValue( + Promise.resolve({ + ok: false, + signedDownloadUrl: '', + matchedKey: '' + }) + ) - const cacheKey = await restoreCache(paths, key, [restoreKey]) + const cacheKey = await restoreCache(paths, key, restoreKeys) expect(cacheKey).toBe(undefined) expect(logWarningMock).toHaveBeenCalledWith( - `Cache not found for keys: ${[key, restoreKey].join(', ')}` + `Cache not found for keys: ${[key, ...restoreKeys].join(', ')}` ) }) @@ -143,7 +155,11 @@ test('restore with gzip compressed cache found', async () => { 'GetCacheEntryDownloadURL' ) getCacheDownloadURLMock.mockReturnValue( - Promise.resolve({ ok: true, signedDownloadUrl }) + Promise.resolve({ + ok: true, + signedDownloadUrl, + matchedKey: key + }) ) const tempPath = '/foo/bar' @@ -219,7 +235,11 @@ test('restore with zstd compressed cache found', async () => { 'GetCacheEntryDownloadURL' ) getCacheDownloadURLMock.mockReturnValue( - Promise.resolve({ ok: true, signedDownloadUrl }) + Promise.resolve({ + ok: true, + signedDownloadUrl, + matchedKey: key + }) ) const tempPath = '/foo/bar' @@ -279,7 +299,7 @@ test('restore with zstd compressed cache found', async () => { test('restore with cache found for restore key', async () => { const paths = ['node_modules'] const key = 'node-test' - const restoreKey = 'node-' + const restoreKeys = ['node-'] const compressionMethod = CompressionMethod.Gzip const signedDownloadUrl = 'https://blob-storage.local?signed=true' const cacheVersion = @@ -296,7 +316,11 @@ test('restore with cache found for restore key', async () => { 'GetCacheEntryDownloadURL' ) getCacheDownloadURLMock.mockReturnValue( - Promise.resolve({ ok: true, signedDownloadUrl }) + Promise.resolve({ + ok: true, + signedDownloadUrl, + matchedKey: restoreKeys[0] + }) ) const tempPath = '/foo/bar' @@ -323,9 +347,9 @@ test('restore with cache found for restore key', async () => { const extractTarMock = jest.spyOn(tar, 'extractTar') const unlinkFileMock = jest.spyOn(cacheUtils, 'unlinkFile') - const cacheKey = await restoreCache(paths, key, [restoreKey]) + const cacheKey = await restoreCache(paths, key, restoreKeys) - expect(cacheKey).toBe(restoreKey) + expect(cacheKey).toBe(restoreKeys[0]) expect(getCacheVersionMock).toHaveBeenCalledWith( paths, compressionMethod, @@ -333,7 +357,7 @@ test('restore with cache found for restore key', async () => { ) expect(getCacheDownloadURLMock).toHaveBeenCalledWith({ key, - restoreKeys: restoreKey, + restoreKeys: restoreKeys, version: cacheVersion }) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) @@ -373,7 +397,11 @@ test('restore with dry run', async () => { 'GetCacheEntryDownloadURL' ) getCacheDownloadURLMock.mockReturnValue( - Promise.resolve({ ok: true, signedDownloadUrl }) + Promise.resolve({ + ok: true, + signedDownloadUrl, + matchedKey: key + }) ) const createTempDirectoryMock = jest.spyOn(cacheUtils, 'createTempDirectory') diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index a2ce38f8..1f26e5ce 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -3,18 +3,18 @@ import * as path from 'path' import * as utils from './internal/cacheUtils' import * as cacheHttpClient from './internal/cacheHttpClient' 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 {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' +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) @@ -287,7 +287,7 @@ async function restoreCacheV2( await extractTar(archivePath, compressionMethod) core.info('Cache restored successfully') - return request.key + return response.matchedKey } catch (error) { const typedError = error as Error if (typedError.name === ValidationError.name) { @@ -407,9 +407,9 @@ async function saveCacheV1( } else if (reserveCacheResponse?.statusCode === 400) { throw new Error( reserveCacheResponse?.error?.message ?? - `Cache size of ~${Math.round( - archiveFileSize / (1024 * 1024) - )} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.` + `Cache size of ~${Math.round( + archiveFileSize / (1024 * 1024) + )} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.` ) } else { throw new ReserveCacheError( diff --git a/packages/cache/src/generated/results/api/v1/cache.ts b/packages/cache/src/generated/results/api/v1/cache.ts index 0736c7ad..387bbd15 100644 --- a/packages/cache/src/generated/results/api/v1/cache.ts +++ b/packages/cache/src/generated/results/api/v1/cache.ts @@ -12,7 +12,7 @@ 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 { CacheEntry } from "../../entities/v1/cacheentry"; import { CacheMetadata } from "../../entities/v1/cachemetadata"; /** * @generated from protobuf message github.actions.results.api.v1.CreateCacheEntryRequest @@ -139,6 +139,12 @@ export interface GetCacheEntryDownloadURLResponse { * @generated from protobuf field: string signed_download_url = 2; */ signedDownloadUrl: string; + /** + * Key or restore key that matches the lookup + * + * @generated from protobuf field: string matched_key = 3; + */ + matchedKey: string; } /** * @generated from protobuf message github.actions.results.api.v1.DeleteCacheEntryRequest @@ -200,62 +206,11 @@ export interface ListCacheEntriesRequest { */ 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 + * Cache entries in the defined scope * - * @generated from protobuf field: string key = 1; + * @generated from protobuf field: repeated github.actions.results.entities.v1.CacheEntry entries = 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; + entries: CacheEntry[]; } /** * @generated from protobuf message github.actions.results.api.v1.LookupCacheEntryRequest @@ -296,61 +251,12 @@ export interface LookupCacheEntryResponse { * @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 + * Matched cache entry metadata * - * @generated from protobuf field: string key = 1; + * @generated from protobuf field: github.actions.results.entities.v1.CacheEntry entry = 2; */ - 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; + entry?: CacheEntry; } // @generated message type with reflection information, may provide speed optimized methods class CreateCacheEntryRequest$Type extends MessageType { @@ -662,11 +568,12 @@ class GetCacheEntryDownloadURLResponse$Type extends MessageType): GetCacheEntryDownloadURLResponse { - const message = { ok: false, signedDownloadUrl: "" }; + const message = { ok: false, signedDownloadUrl: "", matchedKey: "" }; globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this }); if (value !== undefined) reflectionMergePartial(this, message, value); @@ -683,6 +590,9 @@ class GetCacheEntryDownloadURLResponse$Type extends MessageType { constructor() { super("github.actions.results.api.v1.ListCacheEntriesResponse", [ - { no: 1, name: "entries", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => ListCacheEntriesResponse_CacheEntry } + { no: 1, name: "entries", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => CacheEntry } ]); } create(value?: PartialMessage): ListCacheEntriesResponse { @@ -899,8 +812,8 @@ class ListCacheEntriesResponse$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", [ @@ -1095,7 +912,8 @@ export const LookupCacheEntryRequest = new LookupCacheEntryRequest$Type(); class LookupCacheEntryResponse$Type extends MessageType { constructor() { super("github.actions.results.api.v1.LookupCacheEntryResponse", [ - { no: 1, name: "exists", kind: "scalar", T: 8 /*ScalarType.BOOL*/ } + { no: 1, name: "exists", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }, + { no: 2, name: "entry", kind: "message", T: () => CacheEntry } ]); } create(value?: PartialMessage): LookupCacheEntryResponse { @@ -1113,6 +931,9 @@ class LookupCacheEntryResponse$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 */ diff --git a/packages/cache/src/generated/results/entities/v1/cacheentry.ts b/packages/cache/src/generated/results/entities/v1/cacheentry.ts new file mode 100644 index 00000000..b55b4afa --- /dev/null +++ b/packages/cache/src/generated/results/entities/v1/cacheentry.ts @@ -0,0 +1,163 @@ +// @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_none,generate_dependencies +// @generated from protobuf file "results/entities/v1/cacheentry.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 { Timestamp } from "../../../google/protobuf/timestamp"; +/** + * @generated from protobuf message github.actions.results.entities.v1.CacheEntry + */ +export interface 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 CacheEntry$Type extends MessageType { + constructor() { + super("github.actions.results.entities.v1.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): 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?: CacheEntry): 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: 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.entities.v1.CacheEntry + */ +export const CacheEntry = new CacheEntry$Type();