Skip to content

Commit

Permalink
make version configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tsawada committed Nov 1, 2024
1 parent efd47b3 commit baa5ba3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
6 changes: 6 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: bazel-github-actions-cache
description: Github Actions cache for Bazel
inputs:
version:
description: A string to identify the key namespace in Github Actions cache
required: false
default: '7562522d0ae9a33373e8d759b6d20a810f959412ae8f80278a433f2f7eb2de78'
runs:
using: 'node20'
main: 'dist/main.js'
post: 'dist/post.js'

22 changes: 11 additions & 11 deletions dist/main.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/ActionsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ function isSuccessfulStatusCode(statusCode?: number): boolean {
export class ActionsCache {
baseUrl: string
token: string
version: string
httpClient: HttpClient

constructor(baseUrl: string, token: string) {
constructor(baseUrl: string, token: string, version: string) {
this.baseUrl = baseUrl
this.token = token
this.version = version
this.httpClient = new HttpClient(
'bazel-github-actions-cache',
[new BearerCredentialHandler(token)],
Expand All @@ -50,10 +52,9 @@ export class ActionsCache {

async putCache(type: string, hash: string, size: number, stream: NodeJS.ReadableStream): Promise<boolean> {
const key = `${type}-${hash}`
const version = 'b'
const reserveCacheRequest: ReserveCacheRequest = {
key: key,
version: version,
version: this.version,
cacheSize: size
}
const r = await this.httpClient.postJson<ReserveCacheResponse>(`${this.baseUrl}caches`, reserveCacheRequest)
Expand Down Expand Up @@ -83,9 +84,8 @@ export class ActionsCache {

async getCache(type: string, hash: string): Promise<NodeJS.ReadableStream | null> {
const key = `${type}-${hash}`
const version = 'b'

const r = await this.httpClient.getJson<ArtifactCacheEntry>(`${this.baseUrl}cache?keys=${key}&version=${version}`)
const r = await this.httpClient.getJson<ArtifactCacheEntry>(`${this.baseUrl}cache?keys=${key}&version=${this.version}`)
const archiveLocation = r?.result?.archiveLocation
if (!archiveLocation) {
// debug(`Entry failed: ${r.statusCode}`)
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ function main() {
const actions_cache_url = process.env.ACTIONS_CACHE_URL || 'http://localhost:3056/';
const baseUrl = `${ actions_cache_url }_apis/artifactcache/`;
const token = process.env.ACTIONS_RUNTIME_TOKEN ?? '';
const version = process.env.INPUT_VERSION ?? '7562522d0ae9a33373e8d759b6d20a810f959412ae8f80278a433f2f7eb2de78'

const actionsCache = new ActionsCache(baseUrl, token);
const actionsCache = new ActionsCache(baseUrl, token, version);
const httpServer = new HttpServer(actionsCache);

httpServer.on('close', () => {
Expand Down

0 comments on commit baa5ba3

Please sign in to comment.