Skip to content

Commit 9a1c277

Browse files
authored
feat: add support for docker_registry option (#331)
1 parent f0c912e commit 9a1c277

File tree

9 files changed

+303
-185
lines changed

9 files changed

+303
-185
lines changed

action.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ inputs:
205205
syntax.
206206
required: false
207207

208+
docker_registry:
209+
description: |-
210+
Registry to use for storing Docker containers. This must be one of
211+
"artifact-registry" or "container-registry".
212+
default: "container-registry"
213+
required: false
214+
208215
docker_repository:
209216
description: |-
210217
User managed repository created in Artifact Registry.

dist/index.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 221 additions & 174 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"author": "Google LLC",
3232
"license": "Apache-2.0",
3333
"dependencies": {
34-
"@actions/core": "^1.8.0",
35-
"@actions/http-client": "^2.0.0",
34+
"@actions/core": "^1.8.2",
35+
"@actions/http-client": "^2.0.1",
3636
"@google-github-actions/actions-utils": "^0.3.0",
3737
"archiver": "^5.3.1",
3838
"google-auth-library": "^8.0.2",
@@ -42,9 +42,9 @@
4242
"@types/archiver": "^5.3.1",
4343
"@types/chai": "^4.3.1",
4444
"@types/mocha": "^9.1.1",
45-
"@types/node": "^17.0.32",
46-
"@typescript-eslint/eslint-plugin": "^5.23.0",
47-
"@typescript-eslint/parser": "^5.23.0",
45+
"@types/node": "^17.0.35",
46+
"@typescript-eslint/eslint-plugin": "^5.25.0",
47+
"@typescript-eslint/parser": "^5.25.0",
4848
"@vercel/ncc": "^0.33.4",
4949
"chai": "^4.3.6",
5050
"eslint-config-prettier": "^8.5.0",

src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export type CloudFunction = {
7979
availableMemoryMb?: number;
8080
buildEnvironmentVariables?: KVPair;
8181
buildWorkerPool?: string;
82+
dockerRegistry?: string;
8283
dockerRepository?: string;
8384
entryPoint?: string;
8485
environmentVariables?: KVPair;
@@ -382,6 +383,7 @@ export class CloudFunctionsClient {
382383
'buildEnvironmentVariables',
383384
'buildWorkerPool',
384385
'description',
386+
'dockerRegistry',
385387
'dockerRepository',
386388
'entryPoint',
387389
'environmentVariables',

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939

4040
import { CloudFunction, CloudFunctionsClient, SecretEnvVar, SecretVolume } from './client';
4141
import { SecretName } from './secret';
42-
import { formatEntry } from './util';
42+
import { formatEntry, toEnum } from './util';
4343

4444
async function run(): Promise<void> {
4545
try {
@@ -77,6 +77,7 @@ async function run(): Promise<void> {
7777
const secretEnvVars = parseKVString(getInput('secret_environment_variables'));
7878
const secretVols = parseKVString(getInput('secret_volumes'));
7979

80+
const dockerRegistry = presence(toEnum(getInput('docker_registry')));
8081
const dockerRepository = presence(getInput('docker_repository'));
8182
const kmsKeyName = presence(getInput('kms_key_name'));
8283

@@ -191,6 +192,7 @@ async function run(): Promise<void> {
191192
availableMemoryMb: availableMemoryMb ? +availableMemoryMb : undefined,
192193
buildEnvironmentVariables: buildEnvironmentVariables,
193194
buildWorkerPool: buildWorkerPool,
195+
dockerRegistry: dockerRegistry,
194196
dockerRepository: dockerRepository,
195197
entryPoint: entryPoint,
196198
environmentVariables: environmentVariables,

src/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,15 @@ export function formatEntry(entry: RealEntryData): string {
106106
const type = (entry.type || 'unknown').toUpperCase()[0];
107107
return `[${type}] (${mode}) ${name} => ${sourcePath}`;
108108
}
109+
110+
/**
111+
* toEnum converts the input value to the closest enum-string equivalent. It
112+
* does this by replacing any dashes or spaces with underscores, and returning
113+
* the uppercase result.
114+
*
115+
* @param s String to enumerize.
116+
* @returns string
117+
*/
118+
export function toEnum(s: string): string {
119+
return (s || '').replace(/[\s-]+/g, '_').toUpperCase();
120+
}

tests/client.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe('CloudFunctionsClient', () => {
7777
availableMemoryMb: 512,
7878
buildEnvironmentVariables: { BUILDKEY1: 'VALUE1', BUILDKEY2: 'VALUE2' },
7979
// buildWorkerPool: string,
80+
dockerRegistry: 'ARTIFACT_REGISTRY',
8081
// dockerRepository: string,
8182
entryPoint: 'helloWorld',
8283
environmentVariables: { KEY1: 'VALUE1', KEY2: 'VALUE2' },
@@ -177,6 +178,7 @@ describe('CloudFunctionsClient', () => {
177178
availableMemoryMb: 256,
178179
buildEnvironmentVariables: { BUILDKEY3: 'VALUE3', BUILDKEY4: 'VALUE4' },
179180
// buildWorkerPool: string,
181+
dockerRegistry: 'CONTAINER_REGISTRY',
180182
// dockerRepository: string,
181183
entryPoint: 'helloWorld',
182184
environmentVariables: { KEY3: 'VALUE3', KEY4: 'VALUE4' },

tests/util.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { expect } from 'chai';
66
import StreamZip from 'node-stream-zip';
77
import { randomFilepath } from '@google-github-actions/actions-utils';
88

9-
import { zipDir } from '../src/util';
9+
import { toEnum, zipDir } from '../src/util';
1010

1111
describe('Util', () => {
1212
describe('#zipDir', () => {
@@ -59,6 +59,52 @@ describe('Util', () => {
5959
});
6060
});
6161
});
62+
63+
describe('#toEnum', () => {
64+
const cases: {
65+
name: string;
66+
str: string;
67+
exp: string;
68+
}[] = [
69+
{
70+
name: 'empty',
71+
str: '',
72+
exp: '',
73+
},
74+
{
75+
name: 'uppers',
76+
str: 'foo',
77+
exp: 'FOO',
78+
},
79+
{
80+
name: 'spaces',
81+
str: 'foo bar',
82+
exp: 'FOO_BAR',
83+
},
84+
{
85+
name: 'dashes',
86+
str: 'foo-bar',
87+
exp: 'FOO_BAR',
88+
},
89+
{
90+
name: 'multiple spaces',
91+
str: 'foo bar baz',
92+
exp: 'FOO_BAR_BAZ',
93+
},
94+
{
95+
name: 'multiple dashes',
96+
str: 'foo-bar--baz',
97+
exp: 'FOO_BAR_BAZ',
98+
},
99+
];
100+
101+
cases.forEach((tc) => {
102+
it(tc.name, () => {
103+
const e = toEnum(tc.str);
104+
expect(e).to.eql(tc.exp);
105+
});
106+
});
107+
});
62108
});
63109

64110
/**

0 commit comments

Comments
 (0)