Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

Commit

Permalink
Generate and publish Node.js API too
Browse files Browse the repository at this point in the history
By request in pulumi/pulumi-docker#132. The more folks we can get using
this, the more likely we are to get this upstreamed.
  • Loading branch information
benesch committed Jan 3, 2022
1 parent 398b877 commit b5480cf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 20 additions & 3 deletions cmd/pulumi-sdkgen-docker-buildkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -156,20 +158,35 @@ 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)
}
if err := os.WriteFile(path, contents, 0644); err != nil {
return fmt.Errorf("writing file: %v", err)
}
}

return nil
}

0 comments on commit b5480cf

Please sign in to comment.