From 648cbca3e0304b5c0c299a232f8e65362c45624c Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 23 May 2024 10:14:38 -0400 Subject: [PATCH] Remove features that were upstreamed into actions-utils --- bin/docs.mjs | 58 ---------------------------------------------- package-lock.json | 44 +++++++++++++++++++---------------- package.json | 4 ++-- src/main.ts | 10 ++++---- src/util.ts | 38 +----------------------------- tests/util.test.ts | 24 +------------------ 6 files changed, 34 insertions(+), 144 deletions(-) delete mode 100644 bin/docs.mjs diff --git a/bin/docs.mjs b/bin/docs.mjs deleted file mode 100644 index 3ed0b2f..0000000 --- a/bin/docs.mjs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2024 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { readFile, writeFile } from 'fs/promises'; -import * as YAML from 'yaml'; - -async function run() { - const readmeContents = (await readFile('README.md', 'utf8')).split('\n'); - - const actionContents = await readFile('action.yml', 'utf8'); - const action = YAML.parse(actionContents); - - const inputs = []; - for (const [input, opts] of Object.entries(action.inputs)) { - const required = opts.required ? 'Required' : 'Optional'; - const description = opts.description - .split('\n') - .map((line) => (line.trim() === '' ? '' : ` ${line}`)) - .join('\n') - .trim(); - const def = opts.default ? `, default: \`${opts.default}\`` : ''; - const href = `input::${input}`; - inputs.push( - `- ${input}: _(${required}${def})_ ${description}\n`, - ); - } - const startInputs = readmeContents.indexOf(''); - const endInputs = readmeContents.indexOf(''); - readmeContents.splice(startInputs + 1, endInputs - startInputs - 1, '', ...inputs, ''); - - const outputs = []; - for (const [output, opts] of Object.entries(action.outputs)) { - const description = opts.description - .split('\n') - .map((line) => (line.trim() === '' ? '' : ` ${line}`)) - .join('\n') - .trim(); - outputs.push(`- \`${output}\`: ${description}\n`); - } - const startOutputs = readmeContents.indexOf(''); - const endOutputs = readmeContents.indexOf(''); - readmeContents.splice(startOutputs + 1, endOutputs - startOutputs - 1, '', ...outputs, ''); - - await writeFile('README.md', readmeContents.join('\n'), 'utf8'); -} - -await run(); diff --git a/package-lock.json b/package-lock.json index 2060c8f..a2368d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,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" @@ -148,11 +148,14 @@ } }, "node_modules/@google-github-actions/actions-utils": { - "version": "0.7.6", - "resolved": "https://registry.npmjs.org/@google-github-actions/actions-utils/-/actions-utils-0.7.6.tgz", - "integrity": "sha512-X7dwiA9uC4qjRrxufjSNC2Tqds8PZ3PwM0LmLjB4EMljJEEgSwu493n/nQIqNNUaK0JGBKW1dHnxFxAnCm1Q+w==", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@google-github-actions/actions-utils/-/actions-utils-0.8.0.tgz", + "integrity": "sha512-o6QIMH0HbBnTe8nBkfl1Qom8VdqSvVr5rhfZYX8+eM+ufD81nlFOPgmEJRroB6B58XLA/Z9bLHJPwyC9GlrrPg==", "dependencies": { - "yaml": "^2.4.1" + "yaml": "^2.4.2" + }, + "bin": { + "actions-gen-readme": "bin/actions-gen-readme.mjs" } }, "node_modules/@humanwhocodes/config-array": { @@ -1440,12 +1443,12 @@ } }, "node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.3.16", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.16.tgz", + "integrity": "sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==", "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", + "jackspeak": "^3.1.2", "minimatch": "^9.0.1", "minipass": "^7.0.4", "path-scurry": "^1.11.0" @@ -1623,6 +1626,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", "dev": true, "dependencies": { "once": "^1.3.0", @@ -1703,9 +1707,9 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "node_modules/jackspeak": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", - "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.1.2.tgz", + "integrity": "sha512-kWmLKn2tRtfYMF/BakihVVRzBKOxz4gJMiL2Rj91WnAB5TPZumSH99R/Yf1qE1u4uRimvCSJfm6hnxohXeEXjQ==", "dependencies": { "@isaacs/cliui": "^8.0.2" }, @@ -1886,13 +1890,13 @@ } }, "node_modules/micromatch": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.6.tgz", - "integrity": "sha512-Y4Ypn3oujJYxJcMacVgcs92wofTHxp9FzfDpQON4msDefoC0lb3ETvQLOdLcbhSwU1bz8HrL/1sygfBIHudrkQ==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", "dev": true, "dependencies": { "braces": "^3.0.3", - "picomatch": "^4.0.2" + "picomatch": "^2.3.1" }, "engines": { "node": ">=8.6" @@ -2090,12 +2094,12 @@ } }, "node_modules/picomatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", - "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true, "engines": { - "node": ">=12" + "node": ">=8.6" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" diff --git a/package.json b/package.json index c3c8373..83d831b 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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" diff --git a/src/main.ts b/src/main.ts index 9a467ab..5d6beec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,7 +20,9 @@ import { errorMessage, parseBoolean, parseDuration, + parseKVString, presence, + toEnum, } from '@google-github-actions/actions-utils'; import { @@ -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 { @@ -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')); @@ -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, diff --git a/src/util.ts b/src/util.ts index ae7ebb0..ad2fb14 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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'; @@ -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: 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; - 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 @@ -173,18 +149,6 @@ 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. @@ -192,7 +156,7 @@ export function parseKVWithEmpty(s: string): KVPair | undefined { export function parseSecrets( val: string, ): [SecretEnvVar[] | undefined, SecretVolume[] | undefined] { - const kv = parseKVWithEmpty(val); + const kv = parseKVString(val); if (kv === undefined) { return [undefined, undefined]; } diff --git a/tests/util.test.ts b/tests/util.test.ts index 4c3bdaf..aa5e224 100644 --- a/tests/util.test.ts +++ b/tests/util.test.ts @@ -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 = [