From b8fb79d765747c98d60f21efbe582c07cf10dff3 Mon Sep 17 00:00:00 2001 From: Mark Phelps <209477+markphelps@users.noreply.github.com> Date: Fri, 22 Dec 2023 20:14:20 -0500 Subject: [PATCH] chore: setup build/push workflow for node --- build/main.go | 28 ++++++++++++++++++++++++++-- flipt-client-node/package.json | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/build/main.go b/build/main.go index 28d5742b..511c9c49 100644 --- a/build/main.go +++ b/build/main.go @@ -120,7 +120,19 @@ func goBuild(ctx context.Context, client *dagger.Client, hostDirectory *dagger.D } func nodeBuild(ctx context.Context, client *dagger.Client, hostDirectory *dagger.Directory) error { - _, err := client.Container().From("node:21.2-bookworm"). + if os.Getenv("NPM_API_KEY") == "" { + return fmt.Errorf("NPM_API_KEY is not set") + } + + npmAPIKeySecret := client.SetSecret("npm-api-key", os.Getenv("NPM_API_KEY")) + + npmHost := os.Getenv("NPM_HOST") + if npmHost == "" { + // TODO: relax this when we push to npmjs.com + return fmt.Errorf("NPM_HOST is not set") + } + + container := client.Container().From("node:21.2-bookworm"). WithDirectory("/app", hostDirectory.Directory("flipt-client-node"), dagger.ContainerWithDirectoryOpts{ Exclude: []string{"./node_modules/"}, }). @@ -128,7 +140,19 @@ func nodeBuild(ctx context.Context, client *dagger.Client, hostDirectory *dagger WithWorkdir("/app"). WithExec([]string{"npm", "install"}). WithExec([]string{"npm", "run", "build"}). - WithExec([]string{"npm", "pack"}). + WithExec([]string{"npm", "pack"}) + + var err error + + if !push { + _, err = container.Sync(ctx) + return err + } + + _, err = container.WithSecretVariable("NPM_TOKEN", npmAPIKeySecret). + WithExec([]string{"npm", "config", "set", "@flipt-io:registry", fmt.Sprintf("http://%s", npmHost)}). + WithExec([]string{"npm", "config", "set", "--", fmt.Sprintf("//%s:_authToken", npmHost), "${NPM_TOKEN}"}). + WithExec([]string{"npm", "publish"}). Sync(ctx) return err diff --git a/flipt-client-node/package.json b/flipt-client-node/package.json index a23a231f..1c773305 100644 --- a/flipt-client-node/package.json +++ b/flipt-client-node/package.json @@ -1,5 +1,5 @@ { - "name": "flipt-client", + "name": "@flipt-io/flipt-client", "version": "0.0.1", "description": "Flipt Node Client for client-side evaluation", "main": "dist/index.js",