Skip to content

Commit

Permalink
toolkit for env
Browse files Browse the repository at this point in the history
  • Loading branch information
manquer committed Sep 16, 2024
1 parent 25f545a commit 5225158
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ jobs:
with:
SERVICE_PREFIX: DEFAULT
env:
DEFAULT_TEST_KEY: TEST_SECRET
DEFAULT_TEST_KEY: DEFAULT_TEST_KEY
AZURE_CLIENT_ID: 6b37a34b-4496-47e2-ab31-1bc31926e797
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: 5a7d1f14-292f-4043-a73a-d0339418a1e1
AZURE_VAULT_URI: https://tvkv-dev-top-01.vault.azure.net/
- name: check
run: echo ${{ env.TEST_KEY }}
- name: check
run: echo $TEST_KEY
10 changes: 4 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82108,7 +82108,6 @@ class KeyVaultClient {
core.info(`fetching... ${k}`);
const secret = await this.#client.getSecret(`${prefix}-${k}`);
value = (0,lodash.get)(secret, 'value');
core.info(value);
if (!value)
throw new Error(`Secret ${k} not found in service ${prefix}`);
this.#keys = (0,lodash.set)(this.#keys, key, value);
Expand All @@ -82122,16 +82121,15 @@ class KeyVaultClient {




async function setup(prefix) {
const items = (0,lodash.filter)(Object.keys(process.env), (i) => (0,lodash.startsWith)(i, `${prefix}_`));
const res = await PromiseExtended.map(items, async (k) => {
await PromiseExtended.map(items, async (k) => {
const key = k.split(`${prefix}_`)[1];
const value = await kv.getSecret(prefix, key);
return `\n${key}=${value}`;
core.exportVariable(key, value);
core.setSecret(`${value}`);
});
const env = (0,lodash.reduce)(res, (acc, i) => `${acc}${i}`);
const current = process.env.GITHUB_ENV;
process.env.GITHUB_ENV = `${current}${env}`;
}

;// CONCATENATED MODULE: ./src/main.ts
Expand Down
10 changes: 4 additions & 6 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { reduce, filter, startsWith } from 'lodash'
import * as core from '@actions/core'
import { PromiseExtended } from './promise'
import Kv from './kv'

export async function setup(prefix: string): Promise<void> {
const items = filter(Object.keys(process.env), (i: string) => startsWith(i, `${prefix}_`))
const res = await PromiseExtended.map(items, async (k: string): Promise<string> => {
await PromiseExtended.map(items, async (k: string): Promise<void> => {
const key = k.split(`${prefix}_`)[1]
const value: string = await Kv.getSecret(prefix, key)
return `\n${key}=${value}`
core.exportVariable(key, value)
core.setSecret(`${value}`)
})
const env = reduce(res, (acc, i) => `${acc}${i}`)
const current = process.env.GITHUB_ENV
process.env.GITHUB_ENV = `${current}${env}`
console.log(process.env.GITHUB_ENV)
}

0 comments on commit 5225158

Please sign in to comment.