From 4cffd12f3b5edcd67a783a309e3d0c8c0c739d19 Mon Sep 17 00:00:00 2001 From: Daniel Simon Date: Fri, 12 Apr 2024 14:12:59 +0700 Subject: [PATCH] ci: fix "Prepare Environment from Latest Deployment Context" If we're going to call into Node anyway, then there's no need to wrap it in fragile shell. --- .github/workflows/testnet-deployment.yml | 7 ++----- .../utils/deployment-artifacts-to-app-env.ts | 17 +++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/testnet-deployment.yml b/.github/workflows/testnet-deployment.yml index 3350201b..daa78239 100644 --- a/.github/workflows/testnet-deployment.yml +++ b/.github/workflows/testnet-deployment.yml @@ -93,11 +93,8 @@ jobs: run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} - name: Prepare Environment from Latest Deployment Context - run: | - test -f ./deployment-context-latest.json && - cat ./deployment-context-latest.json | - pnpm tsx contracts/utils/deployment-artifacts-to-next-env.ts > ./frontend/.env.local && - cat ./frontend/.env.local + run: pnpm tsx utils/deployment-artifacts-to-next-env.ts ../deployment-context-latest.json ../frontend/.env.local + working-directory: contracts - name: Build Project Artifacts run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} diff --git a/contracts/utils/deployment-artifacts-to-app-env.ts b/contracts/utils/deployment-artifacts-to-app-env.ts index 526f3f0d..ddc1b3dd 100644 --- a/contracts/utils/deployment-artifacts-to-app-env.ts +++ b/contracts/utils/deployment-artifacts-to-app-env.ts @@ -1,12 +1,12 @@ import { z } from "zod"; -import { argv, echo, stdin } from "zx"; +import { argv, echo, fs } from "zx"; const HELP = ` converts the deployment artifacts created by ./deploy into environment variables to be used by the Next.js app located in frontend/. Usage: - ./deployment-artifacts-to-app-env.ts < deployment-latest.json + ./deployment-artifacts-to-app-env.ts Options: --help, -h Show this help message. @@ -33,18 +33,19 @@ type DeploymentContext = z.infer; const NULL_ADDRESS = `0x${"0".repeat(40)}`; export async function main() { - if ("help" in argv || "h" in argv) { + if ("help" in argv || "h" in argv || argv._.length !== 2) { echo`${HELP}`; process.exit(0); } - const deploymentContext = parseDeploymentContext(await stdin()); + const deploymentContext = parseDeploymentContext(await fs.readFile(argv._[0], "utf-8")); - console.log( - objectToEnvironmentVariables( - deploymentContextToAppEnvVariables(deploymentContext), - ), + const outputEnv = objectToEnvironmentVariables( + deploymentContextToAppEnvVariables(deploymentContext) ); + + await fs.writeFile(argv._[1], outputEnv); + console.log(outputEnv); } function objectToEnvironmentVariables(object: Record) {