Skip to content

Commit

Permalink
feat: version the library
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Sep 20, 2024
1 parent a14930c commit 46743f8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 64 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions generator/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export JSONNET_BIN=jrsonnet
export NVIM_JSONNET_USE_TANKA=false
67 changes: 56 additions & 11 deletions generator/main.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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()
15 changes: 0 additions & 15 deletions grafanaplane/jsonnetfile.json

This file was deleted.

34 changes: 1 addition & 33 deletions grafanaplane/main.libsonnet
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions grafanaplane/raw.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
}

0 comments on commit 46743f8

Please sign in to comment.