From b5480cf2eea7ae1e7d5abbbe83469c9b371ce81e Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Sun, 2 Jan 2022 22:35:21 -0500 Subject: [PATCH] Generate and publish Node.js API too By request in pulumi/pulumi-docker#132. The more folks we can get using this, the more likely we are to get this upstreamed. --- .github/workflows/release.yml | 9 ++++++++- Makefile | 6 +++++- cmd/pulumi-sdkgen-docker-buildkit/main.go | 23 ++++++++++++++++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 15ab1ac..8684535 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,14 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - run: make python-sdk + - run: make sdk + - uses: actions/setup-node@v2 + with: + node-version: 16.x + registry-url: https://registry.npmjs.org + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: python setup.py build sdist working-directory: sdk/python - uses: pypa/gh-action-pypi-publish@master diff --git a/Makefile b/Makefile index 5dad95c..99a3d8a 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,17 @@ VERSION ?= $(patsubst v%,%,$(shell git describe)) bin/pulumi-sdkgen-docker-buildkit: cmd/pulumi-sdkgen-docker-buildkit/*.go go build -o bin/pulumi-sdkgen-docker-buildkit ./cmd/pulumi-sdkgen-docker-buildkit -python-sdk: bin/pulumi-sdkgen-docker-buildkit +sdk: bin/pulumi-sdkgen-docker-buildkit rm -rf sdk bin/pulumi-sdkgen-docker-buildkit $(VERSION) cp README.md sdk/python/ + cp README.md sdk/nodejs/ cd sdk/python/ && \ sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" -e "s/\$${PLUGIN_VERSION}/$(VERSION)/g" setup.py && \ rm setup.py.bak + cd sdk/nodejs/ && \ + sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" package.json && \ + rm package.json.bak .PHONY: install install: diff --git a/cmd/pulumi-sdkgen-docker-buildkit/main.go b/cmd/pulumi-sdkgen-docker-buildkit/main.go index 63bb718..78507ee 100644 --- a/cmd/pulumi-sdkgen-docker-buildkit/main.go +++ b/cmd/pulumi-sdkgen-docker-buildkit/main.go @@ -24,6 +24,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil" "github.com/pkg/errors" + jsgen "github.com/pulumi/pulumi/pkg/v3/codegen/nodejs" pygen "github.com/pulumi/pulumi/pkg/v3/codegen/python" "github.com/pulumi/pulumi/pkg/v3/codegen/schema" ) @@ -147,6 +148,7 @@ func run(version string) error { }, Language: map[string]json.RawMessage{ "python": json.RawMessage("{}"), + "nodejs": json.RawMessage(`{"packageName": "@materializeinc/pulumi-docker-buildkit"}`), }, } ppkg, err := schema.ImportSpec(spec, nil) @@ -156,13 +158,29 @@ func run(version string) error { toolDescription := "the Pulumi SDK Generator" extraFiles := map[string][]byte{} - files, err := pygen.GeneratePackage(toolDescription, ppkg, extraFiles) + + pyFiles, err := pygen.GeneratePackage(toolDescription, ppkg, extraFiles) if err != nil { return fmt.Errorf("generating python package: %v", err) } + if err := writeFiles(filepath.Join("sdk", "python"), pyFiles); err != nil { + return err + } + jsFiles, err := jsgen.GeneratePackage(toolDescription, ppkg, extraFiles) + if err != nil { + return fmt.Errorf("generating python package: %v", err) + } + if err := writeFiles(filepath.Join("sdk", "nodejs"), jsFiles); err != nil { + return err + } + + return nil +} + +func writeFiles(base string, files map[string][]byte) error { for path, contents := range files { - path = filepath.Join("sdk", "python", path) + path = filepath.Join(base, path) if err := tools.EnsureFileDir(path); err != nil { return fmt.Errorf("creating directory: %v", err) } @@ -170,6 +188,5 @@ func run(version string) error { return fmt.Errorf("writing file: %v", err) } } - return nil }