Skip to content

Commit

Permalink
🐛 Set env for replacing (fixed upptime/upptime#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Apr 20, 2021
1 parent adc3b16 commit d1ac90c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/helpers/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const replaceEnvironmentVariables = (str: string) => {
Object.keys(process.env).forEach((key) => {
str = str.replace(`$${key}`, process.env[key] || `$${key}`);
});
const SECRETS_CONTEXT = process.env.SECRETS_CONTEXT || "{}";
const allSecrets: Record<string, string> = JSON.parse(SECRETS_CONTEXT);
const secrets: Record<string, any> = { ...JSON.parse(JSON.stringify(process.env)), allSecrets };
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { update } from "./update";
import { updateTemplate } from "./update-template";

const token = getSecret("GH_PAT") || getInput("token") || getSecret("GITHUB_TOKEN");
const SECRETS_CONTEXT = process.env.SECRETS_CONTEXT || "{}";
const allSecrets: Record<string, string> = JSON.parse(SECRETS_CONTEXT);
Object.keys(allSecrets).forEach((key) => {
process.env[key] = allSecrets[key];
});

export const run = async () => {
if (!token) throw new Error("GitHub token not found");
Expand Down

0 comments on commit d1ac90c

Please sign in to comment.