diff --git a/Makefile b/Makefile index 62158ff..1748dfa 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,26 @@ -VERSION:=0.18.0 +LIBRARY_VERSION:=0.0.1 +PROVIDER_VERSION:=0.18.0 JSONNET_BIN:=jrsonnet grafanaplane: grafanaplane/raw.libsonnet grafanaplane/compositions.libsonnet grafanaplane/raw.libsonnet: generator/main.libsonnet generator/namespaced.libsonnet generator/crds.yaml generator/vendor - $(JSONNET_BIN) -S -J generator/vendor generator/main.libsonnet | jsonnetfmt - > grafanaplane/raw.libsonnet + $(JSONNET_BIN) -S -J generator/vendor -A 'version=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)' generator/main.libsonnet | jsonnetfmt - > grafanaplane/raw.libsonnet grafanaplane/compositions.libsonnet: generator/compositions.libsonnet generator/namespaced.libsonnet generator/crds.yaml generator/vendor $(JSONNET_BIN) -J generator/vendor generator/compositions.libsonnet | jsonnetfmt - > grafanaplane/compositions.libsonnet generator/crds.yaml: cd generator && \ - curl -sLO https://github.com/grafana/crossplane-provider-grafana/releases/download/v${VERSION}/crds.yaml + curl -sLO https://github.com/grafana/crossplane-provider-grafana/releases/download/v$(PROVIDER_VERSION)/crds.yaml docs: grafanaplane @rm -rf docs/ @$(JSONNET_BIN) \ - -J grafanaplane/vendor \ + -J generator/vendor \ -S -c -m docs \ -e '(import "github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet").render(import "grafanaplane/main.libsonnet")' + +.PHONY: tag +tag: + git tag $(LIBRARY_VERSION)-$(PROVIDER_VERSION) diff --git a/docs/README.md b/docs/README.md index 91ebadc..977a11d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,7 +24,7 @@ The library in `main.libsonnet` can be used to build objects for these XRDs. ## Install ``` -jb install github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane@main +jb install github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane@0.0.1-0.18.0 ``` ## Usage diff --git a/generator/.env b/generator/.env new file mode 100644 index 0000000..3f5f29b --- /dev/null +++ b/generator/.env @@ -0,0 +1,2 @@ +export JSONNET_BIN=jrsonnet +export NVIM_JSONNET_USE_TANKA=false diff --git a/generator/main.libsonnet b/generator/main.libsonnet index 64ab6de..e17059e 100644 --- a/generator/main.libsonnet +++ b/generator/main.libsonnet @@ -51,17 +51,62 @@ local mergeDocstring(group, version, name, obj, help='') = obj, ]); -std.foldl( - function(acc, def) - local render = crdsonnet.xrd.render(def.definition, 'grafana.crossplane.io', processor); +local packageDocString(version='main') = + a.object.new([ + a.field.new( + a.string.new('#'), + a.literal.new( + std.manifestJsonEx( + d.package.new( + 'grafanaplane', + 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane', + ||| + Jsonnet library providing a namespaced set of compositions/XRDs for the Grafana Crossplane provider. The compositions, XRDs and the library for creating the XRD objects is generated. + + The compositions/XRDs can be imported like this: + + ```jsonnet + local compositions = import "github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/compositions.libsonnet" + + [ + # Each composition has a `definition` and `composition` key + compositions.oss.v1alpha1.folder.composition, + compositions.oss.v1alpha1.folder.definition, + + # When using Tanka, then providing the higher level objects is also possible + compositions.cloud.v1alpha1.stack, # a composition/XRD pair + compositions.oss, # whole group of composition/XRD pairs + ] + ``` + + The library in `main.libsonnet` can be used to build objects for these XRDs. + + |||, + 'main.libsonnet', + version + ) + , ' ', '' + ), + ), + ), + ]); + +local ast = + std.foldl( + function(acc, def) + local render = crdsonnet.xrd.render(def.definition, 'grafana.crossplane.io', processor); + + local group = helpers.getGroupKey(def.definition.spec.group, 'grafana.crossplane.io'); + local version = 'v1alpha1'; + local kind = helpers.camelCaseKind(crdsonnet.xrd.getKind(def.definition)); + + local renderWithDocs = mergeDocstring(group, version, kind, render); - local group = helpers.getGroupKey(def.definition.spec.group, 'grafana.crossplane.io'); - local version = 'v1alpha1'; - local kind = helpers.camelCaseKind(crdsonnet.xrd.getKind(def.definition)); + autils.deepMergeObjects([acc, renderWithDocs]), + definitions, + a.object.withMembers([]), + ); - local renderWithDocs = mergeDocstring(group, version, kind, render); +function(version='main') + autils.deepMergeObjects([ast, packageDocString(version)]).toString() - autils.deepMergeObjects([acc, renderWithDocs]), - definitions, - a.object.withMembers([]), -).toString() diff --git a/grafanaplane/jsonnetfile.json b/grafanaplane/jsonnetfile.json deleted file mode 100644 index a8232b3..0000000 --- a/grafanaplane/jsonnetfile.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": 1, - "dependencies": [ - { - "source": { - "git": { - "remote": "https://github.com/jsonnet-libs/docsonnet.git", - "subdir": "doc-util" - } - }, - "version": "master" - } - ], - "legacyImports": true -} diff --git a/grafanaplane/main.libsonnet b/grafanaplane/main.libsonnet index 2d0c130..13c2c10 100644 --- a/grafanaplane/main.libsonnet +++ b/grafanaplane/main.libsonnet @@ -1,33 +1 @@ -local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; - -(import './raw.libsonnet') -+ { - '#': d.package.new( - 'grafanaplane', - 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane', - ||| - Jsonnet library providing a namespaced set of compositions/XRDs for the Grafana Crossplane provider. The compositions, XRDs and the library for creating the XRD objects is generated. - - The compositions/XRDs can be imported like this: - - ```jsonnet - local compositions = import "github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/compositions.libsonnet" - - [ - # Each composition has a `definition` and `composition` key - compositions.oss.v1alpha1.folder.composition, - compositions.oss.v1alpha1.folder.definition, - - # When using Tanka, then providing the higher level objects is also possible - compositions.cloud.v1alpha1.stack, # a composition/XRD pair - compositions.oss, # whole group of composition/XRD pairs - ] - ``` - - The library in `main.libsonnet` can be used to build objects for these XRDs. - - |||, - 'main.libsonnet', - 'main' - ), -} +import './raw.libsonnet' diff --git a/grafanaplane/raw.libsonnet b/grafanaplane/raw.libsonnet index 43df197..5ab3d7a 100644 --- a/grafanaplane/raw.libsonnet +++ b/grafanaplane/raw.libsonnet @@ -78042,4 +78042,5 @@ }, }, }, + '#': { filename: 'main.libsonnet', help: 'Jsonnet library providing a namespaced set of compositions/XRDs for the Grafana Crossplane provider. The compositions, XRDs and the library for creating the XRD objects is generated.\n\nThe compositions/XRDs can be imported like this:\n\n```jsonnet\nlocal compositions = import "github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/compositions.libsonnet"\n\n[\n # Each composition has a `definition` and `composition` key\n compositions.oss.v1alpha1.folder.composition,\n compositions.oss.v1alpha1.folder.definition,\n\n # When using Tanka, then providing the higher level objects is also possible\n compositions.cloud.v1alpha1.stack, # a composition/XRD pair\n compositions.oss, # whole group of composition/XRD pairs\n]\n```\n\nThe library in `main.libsonnet` can be used to build objects for these XRDs.\n\n\n## Install\n\n```\njb install github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane@0.0.1-0.18.0\n```\n\n## Usage\n\n```jsonnet\nlocal grafanaplane = import "github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet"\n```\n', 'import': 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane/main.libsonnet', installTemplate: '\n## Install\n\n```\njb install %(url)s@%(version)s\n```\n', name: 'grafanaplane', url: 'github.com/Duologic/grafana-crossplane-libsonnet/grafanaplane', usageTemplate: '\n## Usage\n\n```jsonnet\nlocal %(name)s = import "%(import)s"\n```\n', version: '0.0.1-0.18.0' }, }