Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move generated files to seperate directory #19

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions .env

This file was deleted.

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Bugs or feature requests can go into [GitHub Issues](https://github.com/grafana/

`generator/` is where the code generator lives.

`packages/` and `docs/` are completely generated, do not edit these, changes will be overwritten by the generation process.
`grafanaplane/` is the actual library.

`grafanaplane/` except for `grafanaplane/main.libsonnet` and `grafanaplane/example.jsonnet` are generated as well.
`grafanaplane/zz/`, `packages/` and `docs/` are completely generated, do not edit these, changes will be overwritten by the generation process.
25 changes: 9 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
LIBRARY_VERSION:=0.2.0
LIBRARY_VERSION:=0.3.0
PROVIDER_VERSION:=0.22.0
JSONNET_BIN:=jrsonnet
CROSSPLANE?=crossplane
REGISTRY?=ghcr.io
SHELL:=/bin/bash

VENDOR_DEPTHS:=$(shell find generator/vendor -type f)
GENERATOR_DEPTHS:=$(shell find generator -type f)

.PHONY: build
build: grafanaplane/raw.libsonnet grafanaplane/configurations.libsonnet packages
build: grafanaplane/zz packages docs

.PHONY: push
push: push_packages

grafanaplane: grafanaplane/raw.libsonnet grafanaplane/configurations.libsonnet
grafanaplane: grafanaplane/zz

generator/crds.yaml:
cd generator && \
curl -sLO https://github.com/grafana/crossplane-provider-grafana/releases/download/v$(PROVIDER_VERSION)/crds.yaml

grafanaplane/raw.libsonnet: generator/main.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS)
rm -rf grafanaplane/raw && \
grafanaplane/zz: $(GENERATOR_DEPTHS)
rm -rf grafanaplane/zz && \
FILES=$$($(JSONNET_BIN) \
-S -c -m grafanaplane \
-J generator/vendor \
-A 'version=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)' \
generator/main.libsonnet) && \
xargs -n1 jsonnetfmt -i <<< "$${FILES}"

grafanaplane/configurations.libsonnet: generator/configurations.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS)
$(JSONNET_BIN) \
-J generator/vendor \
-A 'configurationVersion=$(LIBRARY_VERSION)-$(PROVIDER_VERSION)' \
generator/configurations.libsonnet | \
jsonnetfmt - > grafanaplane/configurations.libsonnet

packages: generator/packages.libsonnet generator/namespaced.libsonnet generator/crds.yaml $(VENDOR_DEPTHS)
packages: $(GENERATOR_DEPTHS)
rm -rf packages && \
$(JSONNET_BIN) -S -m packages -c -J generator/vendor generator/packages.libsonnet

Expand All @@ -46,8 +39,8 @@ push_packages: packages $(packages)
$(foreach pkg,$(packages),$(CROSSPLANE) xpkg push -f output/$(patsubst packages/%,%,$(pkg)).xpkg $(REGISTRY)/grafana/crossplane/$(patsubst packages/%,%,$(pkg)):$(LIBRARY_VERSION)-$(PROVIDER_VERSION);)

docs: $(shell find grafanaplane/ -type f)
@rm -rf docs/
@$(JSONNET_BIN) \
rm -rf docs/
$(JSONNET_BIN) \
-J generator/vendor \
-S -c -m docs \
-e '(import "github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet").render(import "grafanaplane/main.libsonnet")'
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ This repository provides a set of Crossplane Configurations packages and and acc

The Configuration packages provide a set of (namespaced) composition/XRD pairs that map directly to their non-namespaced Managed resources equivalents.

The library consists of two parts, the manually written functions to get started quicly and the full library in `raw/`. They can be used in combination with each other.
The library consists of two parts, the manually written functions to get started quicly and the full library in `zz/`. They can be used in combination with each other.

Most of this library is generated: the Compositions/XRDs packages, Configurations and the library in `raw/`.
Most of this library is generated: the Compositions/XRDs packages, Configurations and the library in `zz/`.

## Install

```
jb install github.com/grafana/grafana-crossplane-libsonnet/grafanaplane@0.2.0-0.22.0
jb install github.com/grafana/grafana-crossplane-libsonnet/grafanaplane@0.3.0-0.22.0
```

## Usage
Expand Down
8 changes: 4 additions & 4 deletions generator/main.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';
local processor = crdsonnet.processor.new('ast');

local definitions = import './namespaced.libsonnet';
local configurations = import './configurations.libsonnet';

local globalDefinitions =
std.filter(
Expand Down Expand Up @@ -133,13 +134,12 @@ local splitIntoFiles(objast, sub='', depth=1, maxDepth=5) =
);

function(version='main')
local files = splitIntoFiles(ast);
local files = splitIntoFiles(ast, 'zz');
{
[file.key]: file.value.toString()
for file in std.objectKeysValues(files)
if file.key != 'main.libsonnet'
}
+ {
'raw.libsonnet': (files['main.libsonnet']).toString(),
'version.libsonnet': std.manifestJson(version),
'zz/configurations.libsonnet': std.manifestJson(configurations(version)),
'zz/version.libsonnet': std.manifestJson(version),
}
1 change: 0 additions & 1 deletion generator/namespaced.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local crds =
// XRD metadata.name consists of `plural+group`, for some resources this became longer than 63 characters, which resulted in this error:
// 'cannot establish control of object: Composition.apiextensions.crossplane.io "stackserviceaccounttoken-namespaced" is invalid: metadata.labels: Invalid value:"xstackserviceaccounttokens.cloud.grafana.crossplane.io.namespaced": must be no more than 63 characters'
local renameGroup(obj) =
assert std.trace(std.manifestJson(obj.definition.metadata), true);
local name = std.strReplace(obj.definition.metadata.name, 'crossplane.io', 'net');
assert std.length(name) <= 63 : 'CompositeResourceDefinition names must be no more than 63 characters';
obj + {
Expand Down
10 changes: 5 additions & 5 deletions grafanaplane/main.libsonnet
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';
local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';

local configurations = import './configurations.libsonnet';
local raw = import './raw.libsonnet';
local configurations = import './zz/configurations.libsonnet';
local raw = import './zz/main.libsonnet';

{
local root = self,
Expand All @@ -16,12 +16,12 @@ local raw = import './raw.libsonnet';

The Configuration packages provide a set of (namespaced) composition/XRD pairs that map directly to their non-namespaced Managed resources equivalents.

The library consists of two parts, the manually written functions to get started quicly and the full library in `raw/`. They can be used in combination with each other.
The library consists of two parts, the manually written functions to get started quicly and the full library in `zz/`. They can be used in combination with each other.

Most of this library is generated: the Compositions/XRDs packages, Configurations and the library in `raw/`.
Most of this library is generated: the Compositions/XRDs packages, Configurations and the library in `zz/`.
|||,
'main.libsonnet',
import 'version.libsonnet',
import 'zz/version.libsonnet',
)
+ d.package.withUsageTemplate(
@"local %(name)s = import '%(import)s';"
Expand Down
1 change: 0 additions & 1 deletion grafanaplane/version.libsonnet

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name: 'grafana-namespaced-alerting',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-alerting:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-alerting:0.3.0-0.22.0',
},
},
cloud: {
Expand All @@ -22,7 +22,7 @@
name: 'grafana-namespaced-cloud',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-cloud:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-cloud:0.3.0-0.22.0',
},
},
enterprise: {
Expand All @@ -35,7 +35,7 @@
name: 'grafana-namespaced-enterprise',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-enterprise:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-enterprise:0.3.0-0.22.0',
},
},
ml: {
Expand All @@ -48,7 +48,7 @@
name: 'grafana-namespaced-ml',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-ml:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-ml:0.3.0-0.22.0',
},
},
oncall: {
Expand All @@ -61,7 +61,7 @@
name: 'grafana-namespaced-oncall',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-oncall:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-oncall:0.3.0-0.22.0',
},
},
oss: {
Expand All @@ -74,7 +74,7 @@
name: 'grafana-namespaced-oss',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-oss:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-oss:0.3.0-0.22.0',
},
},
slo: {
Expand All @@ -87,7 +87,7 @@
name: 'grafana-namespaced-slo',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-slo:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-slo:0.3.0-0.22.0',
},
},
sm: {
Expand All @@ -100,7 +100,7 @@
name: 'grafana-namespaced-sm',
},
spec: {
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-sm:0.2.0-0.22.0',
package: 'ghcr.io/grafana/crossplane/grafana-namespaced-sm:0.3.0-0.22.0',
},
},
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading