Skip to content

Commit dd672b8

Browse files
committed
Remove features that were upstreamed into actions-utils
1 parent 8a1e165 commit dd672b8

File tree

6 files changed

+34
-144
lines changed

6 files changed

+34
-144
lines changed

bin/docs.mjs

Lines changed: 0 additions & 58 deletions
This file was deleted.

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "ncc build -m src/main.ts",
8-
"docs": "node ./bin/docs.mjs",
8+
"docs": "./node_modules/.bin/actions-gen-readme",
99
"lint": "eslint . --ext .ts,.tsx",
1010
"format": "prettier --write **/*.ts",
1111
"test": "node --require ts-node/register --test-reporter spec --test tests/client.test.ts tests/secret.test.ts tests/util.test.ts"
@@ -31,7 +31,7 @@
3131
"dependencies": {
3232
"@actions/core": "^1.10.1",
3333
"@actions/http-client": "^2.2.1",
34-
"@google-github-actions/actions-utils": "^0.7.6",
34+
"@google-github-actions/actions-utils": "^0.8.0",
3535
"archiver": "^7.0.1",
3636
"google-auth-library": "^9.10.0",
3737
"ignore": "^5.3.1"

src/main.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
errorMessage,
2121
parseBoolean,
2222
parseDuration,
23+
parseKVString,
2324
presence,
25+
toEnum,
2426
} from '@google-github-actions/actions-utils';
2527

2628
import {
@@ -31,7 +33,7 @@ import {
3133
RetryPolicy,
3234
VpcConnectorEgressSettings,
3335
} from './client';
34-
import { formatEntry, parseKVWithEmpty, parseSecrets, stringToInt, toEnum } from './util';
36+
import { formatEntry, parseSecrets, stringToInt } from './util';
3537

3638
async function run() {
3739
try {
@@ -45,12 +47,12 @@ async function run() {
4547
const description = presence(getInput('description'));
4648
const environment = toEnum(Environment, getInput('environment') || Environment.GEN_2);
4749
const kmsKeyName = presence(getInput('kms_key_name'));
48-
const labels = parseKVWithEmpty(getInput('labels'));
50+
const labels = parseKVString(getInput('labels'));
4951
const sourceDir = presence(getInput('source_dir')) || process.cwd();
5052

5153
// buildConfig
5254
const runtime = getInput('runtime', { required: true });
53-
const buildEnvironmentVariables = parseKVWithEmpty(getInput('build_environment_variables'));
55+
const buildEnvironmentVariables = parseKVString(getInput('build_environment_variables'));
5456
const buildServiceAccount = presence(getInput('build_service_account'));
5557
const buildWorkerPool = presence(getInput('build_worker_pool'));
5658
const dockerRepository = presence(getInput('docker_repository'));
@@ -63,7 +65,7 @@ async function run() {
6365
);
6466
const availableCpu = presence(getInput('available_cpu'));
6567
const availableMemory = presence(getInput('memory')) || '256Mi';
66-
const environmentVariables = parseKVWithEmpty(getInput('environment_variables'));
68+
const environmentVariables = parseKVString(getInput('environment_variables'));
6769
const ingressSettings = toEnum(
6870
IngressSettings,
6971
getInput('ingress_settings') || IngressSettings.ALLOW_ALL,

src/util.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ import * as path from 'path';
2020

2121
import * as Archiver from 'archiver';
2222
import {
23-
KVPair,
2423
parseGcloudIgnore,
2524
parseKVString,
26-
presence,
2725
toPlatformPath,
2826
} from '@google-github-actions/actions-utils';
2927
import ignore from 'ignore';
@@ -130,28 +128,6 @@ export function formatEntry(entry: RealEntryData): string {
130128
return `[${type}] (${mode}) ${name} => ${sourcePath}`;
131129
}
132130

133-
/**
134-
* toEnum converts the input value to the best enum value. If no enum value
135-
* exists, it throws an error.
136-
*
137-
* @param e Enum to check against.
138-
* @param s String to enumerize.
139-
* @returns string
140-
*/
141-
export function toEnum<E extends Record<string, string>>(e: E, s: string): E[keyof E] {
142-
const originalValue = (s || '').toUpperCase();
143-
const mutatedValue = originalValue.replace(/[\s-]+/g, '_');
144-
145-
if (originalValue in e) {
146-
return e[originalValue] as E[keyof E];
147-
} else if (mutatedValue in e) {
148-
return e[mutatedValue] as E[keyof E];
149-
} else {
150-
const keys = Object.keys(e) as Array<keyof E>;
151-
throw new Error(`Invalid value ${s}, valid values are ${JSON.stringify(keys)}`);
152-
}
153-
}
154-
155131
/**
156132
* stringToInt is a helper that converts the given string into an integer. If
157133
* the given string is empty, it returns undefined. If the string is not empty
@@ -173,26 +149,14 @@ export function stringToInt(str: string): number | undefined {
173149
}
174150
return result;
175151
}
176-
177-
/**
178-
* parseKVWithEmpty parses the given string as a KEY=VALUE string and the given
179-
* file as a KV file. As a special case, if the given string is the literal
180-
* "{}", it returns the empty object. This allows callers to explicitly remove
181-
* all environment variables.
182-
*/
183-
export function parseKVWithEmpty(s: string): KVPair | undefined {
184-
const sp = presence(s) === '{}' ? '' : presence(s);
185-
if (sp !== undefined) return parseKVString(sp);
186-
}
187-
188152
/**
189153
* parseSecrets parses the input as environment variable and volume mounted
190154
* secrets.
191155
*/
192156
export function parseSecrets(
193157
val: string,
194158
): [SecretEnvVar[] | undefined, SecretVolume[] | undefined] {
195-
const kv = parseKVWithEmpty(val);
159+
const kv = parseKVString(val);
196160
if (kv === undefined) {
197161
return [undefined, undefined];
198162
}

tests/util.test.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,7 @@ import assert from 'node:assert';
2020
import StreamZip from 'node-stream-zip';
2121
import { assertMembers, randomFilepath } from '@google-github-actions/actions-utils';
2222

23-
import { parseKVWithEmpty, stringToInt, zipDir } from '../src/util';
24-
25-
test('#parseKVWithEmpty', { concurrency: true }, async (suite) => {
26-
const cases = [
27-
{
28-
name: 'both empty',
29-
s: '',
30-
expected: undefined,
31-
},
32-
{
33-
name: 'braces {}',
34-
s: '{}',
35-
expected: {},
36-
},
37-
];
38-
39-
for await (const tc of cases) {
40-
await suite.test(tc.name, async () => {
41-
const actual = parseKVWithEmpty(tc.s);
42-
assert.deepStrictEqual(actual, tc.expected);
43-
});
44-
}
45-
});
23+
import { stringToInt, zipDir } from '../src/util';
4624

4725
test('#zipDir', { concurrency: true }, async (suite) => {
4826
const cases = [

0 commit comments

Comments
 (0)