Skip to content

Remove features that were upstreamed into actions-utils #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions bin/docs.mjs

This file was deleted.

44 changes: 24 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index.js",
"scripts": {
"build": "ncc build -m src/main.ts",
"docs": "node ./bin/docs.mjs",
"docs": "./node_modules/.bin/actions-gen-readme",
"lint": "eslint . --ext .ts,.tsx",
"format": "prettier --write **/*.ts",
"test": "node --require ts-node/register --test-reporter spec --test tests/client.test.ts tests/secret.test.ts tests/util.test.ts"
Expand All @@ -31,7 +31,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/http-client": "^2.2.1",
"@google-github-actions/actions-utils": "^0.7.6",
"@google-github-actions/actions-utils": "^0.8.0",
"archiver": "^7.0.1",
"google-auth-library": "^9.10.0",
"ignore": "^5.3.1"
Expand Down
10 changes: 6 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
errorMessage,
parseBoolean,
parseDuration,
parseKVString,
presence,
toEnum,
} from '@google-github-actions/actions-utils';

import {
Expand All @@ -31,7 +33,7 @@ import {
RetryPolicy,
VpcConnectorEgressSettings,
} from './client';
import { formatEntry, parseKVWithEmpty, parseSecrets, stringToInt, toEnum } from './util';
import { formatEntry, parseSecrets, stringToInt } from './util';

async function run() {
try {
Expand All @@ -45,12 +47,12 @@ async function run() {
const description = presence(getInput('description'));
const environment = toEnum(Environment, getInput('environment') || Environment.GEN_2);
const kmsKeyName = presence(getInput('kms_key_name'));
const labels = parseKVWithEmpty(getInput('labels'));
const labels = parseKVString(getInput('labels'));
const sourceDir = presence(getInput('source_dir')) || process.cwd();

// buildConfig
const runtime = getInput('runtime', { required: true });
const buildEnvironmentVariables = parseKVWithEmpty(getInput('build_environment_variables'));
const buildEnvironmentVariables = parseKVString(getInput('build_environment_variables'));
const buildServiceAccount = presence(getInput('build_service_account'));
const buildWorkerPool = presence(getInput('build_worker_pool'));
const dockerRepository = presence(getInput('docker_repository'));
Expand All @@ -63,7 +65,7 @@ async function run() {
);
const availableCpu = presence(getInput('available_cpu'));
const availableMemory = presence(getInput('memory')) || '256Mi';
const environmentVariables = parseKVWithEmpty(getInput('environment_variables'));
const environmentVariables = parseKVString(getInput('environment_variables'));
const ingressSettings = toEnum(
IngressSettings,
getInput('ingress_settings') || IngressSettings.ALLOW_ALL,
Expand Down
38 changes: 1 addition & 37 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import * as path from 'path';

import * as Archiver from 'archiver';
import {
KVPair,
parseGcloudIgnore,
parseKVString,
presence,
toPlatformPath,
} from '@google-github-actions/actions-utils';
import ignore from 'ignore';
Expand Down Expand Up @@ -130,28 +128,6 @@ export function formatEntry(entry: RealEntryData): string {
return `[${type}] (${mode}) ${name} => ${sourcePath}`;
}

/**
* toEnum converts the input value to the best enum value. If no enum value
* exists, it throws an error.
*
* @param e Enum to check against.
* @param s String to enumerize.
* @returns string
*/
export function toEnum<E extends Record<string, string>>(e: E, s: string): E[keyof E] {
const originalValue = (s || '').toUpperCase();
const mutatedValue = originalValue.replace(/[\s-]+/g, '_');

if (originalValue in e) {
return e[originalValue] as E[keyof E];
} else if (mutatedValue in e) {
return e[mutatedValue] as E[keyof E];
} else {
const keys = Object.keys(e) as Array<keyof E>;
throw new Error(`Invalid value ${s}, valid values are ${JSON.stringify(keys)}`);
}
}

/**
* stringToInt is a helper that converts the given string into an integer. If
* the given string is empty, it returns undefined. If the string is not empty
Expand All @@ -173,26 +149,14 @@ export function stringToInt(str: string): number | undefined {
}
return result;
}

/**
* parseKVWithEmpty parses the given string as a KEY=VALUE string and the given
* file as a KV file. As a special case, if the given string is the literal
* "{}", it returns the empty object. This allows callers to explicitly remove
* all environment variables.
*/
export function parseKVWithEmpty(s: string): KVPair | undefined {
const sp = presence(s) === '{}' ? '' : presence(s);
if (sp !== undefined) return parseKVString(sp);
}

/**
* parseSecrets parses the input as environment variable and volume mounted
* secrets.
*/
export function parseSecrets(
val: string,
): [SecretEnvVar[] | undefined, SecretVolume[] | undefined] {
const kv = parseKVWithEmpty(val);
const kv = parseKVString(val);
if (kv === undefined) {
return [undefined, undefined];
}
Expand Down
24 changes: 1 addition & 23 deletions tests/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,7 @@ import assert from 'node:assert';
import StreamZip from 'node-stream-zip';
import { assertMembers, randomFilepath } from '@google-github-actions/actions-utils';

import { parseKVWithEmpty, stringToInt, zipDir } from '../src/util';

test('#parseKVWithEmpty', { concurrency: true }, async (suite) => {
const cases = [
{
name: 'both empty',
s: '',
expected: undefined,
},
{
name: 'braces {}',
s: '{}',
expected: {},
},
];

for await (const tc of cases) {
await suite.test(tc.name, async () => {
const actual = parseKVWithEmpty(tc.s);
assert.deepStrictEqual(actual, tc.expected);
});
}
});
import { stringToInt, zipDir } from '../src/util';

test('#zipDir', { concurrency: true }, async (suite) => {
const cases = [
Expand Down
Loading