Skip to content

Commit

Permalink
Move schema to root (#1157)
Browse files Browse the repository at this point in the history
Registry only searches for the schema at the root or in the go provider path.

- Set schema outDir to the root directory but pass in /awsx for when reading the package spec etc while building the schema.
- Fix ioutil warnings.
- Fix paths where we read the schema in the makefile.
- Fix path when generating provider types.
  • Loading branch information
danielrbradley committed Nov 20, 2023
1 parent 5d5870e commit 6f8e292
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ JAVA_GEN_VERSION := v0.9.7

AWSX_SRC := $(wildcard awsx/*.*) $(wildcard awsx/*/*.ts)
AWSX_CLASSIC_SRC:= $(wildcard awsx-classic/*.*) $(wildcard awsx-classic/*/*.ts)
CODEGEN_SRC := $(wildcard schemagen/go.*) $(wildcard schemagen/pkg/*/*) $(wildcard schemagen/pkg/cmd/${CODEGEN}/*.go)
CODEGEN_SRC := $(shell find schemagen -type f)

WORKING_DIR := $(shell pwd)

Expand All @@ -35,7 +35,7 @@ bin/${CODEGEN}: ${CODEGEN_SRC}
cd schemagen && go build -o $(WORKING_DIR)/bin/${CODEGEN} $(WORKING_DIR)/schemagen/cmd/$(CODEGEN)

.make/schema: bin/${CODEGEN}
cd schemagen/cmd/$(CODEGEN) && go run . schema $(WORKING_DIR)/$(PACK)
bin/${CODEGEN} schema $(WORKING_DIR)
@touch $@

.make/awsx_node_modules: awsx/package.json awsx/yarn.lock
Expand All @@ -49,7 +49,7 @@ bin/${CODEGEN}: ${CODEGEN_SRC}
.make/awsx_bin: .make/awsx_node_modules .make/gen_types ${AWSX_SRC}
@cd awsx && \
yarn tsc && \
cp package.json schema.json ./bin/ && \
cp package.json ../schema.json ./bin/ && \
sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" ./bin/package.json
@touch $@

Expand Down Expand Up @@ -86,7 +86,7 @@ dist/${GZIP_PREFIX}-%.tar.gz::
.make/build_nodejs: VERSION := $(shell pulumictl get version --language javascript)
.make/build_nodejs: bin/${CODEGEN} .make/schema ${AWSX_CLASSIC_SRC}
rm -rf sdk/nodejs
bin/${CODEGEN} nodejs sdk/nodejs awsx/schema.json $(VERSION)
bin/${CODEGEN} nodejs sdk/nodejs schema.json $(VERSION)
cd sdk/nodejs && \
yarn install --no-progress && \
yarn run tsc --version && \
Expand All @@ -98,7 +98,7 @@ dist/${GZIP_PREFIX}-%.tar.gz::
.make/build_java: VERSION := $(shell pulumictl get version --language javascript)
.make/build_java: bin/pulumi-java-gen .make/schema ${AWSX_CLASSIC_SRC}
rm -rf sdk/java
$(WORKING_DIR)/bin/$(JAVA_GEN) generate --schema awsx/schema.json --out sdk/java --build gradle-nexus
$(WORKING_DIR)/bin/$(JAVA_GEN) generate --schema schema.json --out sdk/java --build gradle-nexus
cd sdk/java && \
gradle --console=plain build
@touch $@
Expand All @@ -109,7 +109,7 @@ bin/pulumi-java-gen::
.make/build_python: PYPI_VERSION := $(shell pulumictl get version --language python)
.make/build_python: bin/${CODEGEN} .make/schema README.md
rm -rf sdk/python
bin/${CODEGEN} python sdk/python awsx/schema.json $(VERSION)
bin/${CODEGEN} python sdk/python schema.json $(VERSION)
cd sdk/python/ && \
cp ../../README.md . && \
python3 setup.py clean --all 2>/dev/null && \
Expand All @@ -123,7 +123,7 @@ bin/pulumi-java-gen::
.make/build_go: AWS_VERSION := $(shell node -e 'console.log(require("./awsx/package.json").dependencies["@pulumi/aws"])')
.make/build_go: bin/${CODEGEN} .make/schema
rm -rf sdk/go
bin/${CODEGEN} go sdk/go awsx/schema.json $(VERSION)
bin/${CODEGEN} go sdk/go schema.json $(VERSION)
cd sdk && \
go get github.com/pulumi/pulumi-aws/sdk/v6@v$(AWS_VERSION) && \
go mod tidy && \
Expand All @@ -133,7 +133,7 @@ bin/pulumi-java-gen::
.make/build_dotnet: DOTNET_VERSION := $(shell pulumictl get version --language dotnet)
.make/build_dotnet: bin/${CODEGEN} .make/schema
rm -rf sdk/dotnet
bin/${CODEGEN} dotnet sdk/dotnet awsx/schema.json $(VERSION)
bin/${CODEGEN} dotnet sdk/dotnet schema.json $(VERSION)
cd sdk/dotnet/ && \
echo "${DOTNET_VERSION}" >version.txt && \
dotnet build /p:Version=${DOTNET_VERSION}
Expand Down
2 changes: 1 addition & 1 deletion awsx/scripts/generate-provider-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,6 @@ export function generateProviderTypes(args: { schema: string; out: string }) {
}

generateProviderTypes({
schema: "schema.json",
schema: "../schema.json",
out: "schema-types.ts",
});
File renamed without changes.
21 changes: 10 additions & 11 deletions schemagen/cmd/pulumi-gen-awsx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -56,7 +55,7 @@ func main() {
os.Exit(1)
}

language, outdir := Language(args[0]), args[1]
language, outDir := Language(args[0]), args[1]

var schemaFile string
var version string
Expand All @@ -70,24 +69,24 @@ func main() {

switch language {
case DotNet:
genDotNet(readSchema(schemaFile, version), outdir)
genDotNet(readSchema(schemaFile, version), outDir)
case Go:
genGo(readSchema(schemaFile, version), outdir)
genGo(readSchema(schemaFile, version), outDir)
case Python:
genPython(readSchema(schemaFile, version), outdir)
genPython(readSchema(schemaFile, version), outDir)
case Nodejs:
genNodejs(readSchema(schemaFile, version), outdir)
genNodejs(readSchema(schemaFile, version), outDir)
case Schema:
pkgSpec := gen.GenerateSchema(outdir)
mustWritePulumiSchema(pkgSpec, outdir)
pkgSpec := gen.GenerateSchema(filepath.Join(outDir, "awsx"))
mustWritePulumiSchema(pkgSpec, outDir)
default:
panic(fmt.Sprintf("Unrecognized language %q", language))
}
}

func readSchema(schemaPath string, version string) *schema.Package {
// Read in, decode, and import the schema.
schemaBytes, err := ioutil.ReadFile(schemaPath)
schemaBytes, err := os.ReadFile(schemaPath)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -147,7 +146,7 @@ func genNodejs(pkg *schema.Package, outdir string) {
return nil
}
}
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down Expand Up @@ -177,7 +176,7 @@ func mustWriteFile(rootDir, filename string, contents []byte) {
if err := os.MkdirAll(filepath.Dir(outPath), 0755); err != nil {
panic(err)
}
err := ioutil.WriteFile(outPath, contents, 0600)
err := os.WriteFile(outPath, contents, 0600)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 6f8e292

Please sign in to comment.