From ea48fc6a73daffa546d75a4805f1947291ce1940 Mon Sep 17 00:00:00 2001 From: Tim <32556895+Avarei@users.noreply.github.com> Date: Wed, 3 Jul 2024 01:27:03 +0200 Subject: [PATCH 1/6] version of pkl packages is now inferred from env variables make pkl-resolve and make pkl-release now read the latest git tag for each package to determine the version without being stored in the PklProject files update Kubernetes Dependencies Signed-off-by: Tim <32556895+Avarei@users.noreply.github.com> --- Makefile | 26 ++++++++++++++++--- pkl/crossplane.contrib.example/PklProject | 13 ++++++---- .../PklProject.deps.json | 4 +-- pkl/crossplane.contrib.xrd/PklProject | 7 ++--- .../PklProject.deps.json | 4 +-- pkl/crossplane.contrib/PklProject | 13 ++++++---- pkl/crossplane.contrib/PklProject.deps.json | 4 +-- 7 files changed, 48 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 230fb3b..39b95cd 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,38 @@ -REPO =? github.com/crossplane-contrib/function-pkl -CONTAINER_IMAGE =? ghcr.io/crossplane-contrib/function-pkl +REPO ?= github.com/crossplane-contrib/function-pkl +CONTAINER_IMAGE ?= ghcr.io/crossplane-contrib/function-pkl # Target used for Pkl Package Releases TARGET =? $(shell git branch --show-current) +LATEST_CORE := $(shell git tag -l "crossplane.contrib@*.*.*" --sort=-v:refname | head -n 1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') +LATEST_EXAMPLE := $(shell git tag -l "crossplane.contrib.example@*.*.*" --sort=-v:refname | head -n 1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') +LATEST_XRD := $(shell git tag -l "crossplane.contrib.xrd@*.*.*" --sort=-v:refname | head -n 1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') + +# This Resolves the Dependencies and sets the versions of our packages to the Latest ones for the package in Git .PHONY: pkl-resolve pkl-resolve: - pkl project resolve ./pkl/*/ + pkl project resolve \ + -e REPOSITORY="$(REPO)" \ + -e CROSSPLANE_CONTRIB_VERSION="$(LATEST_CORE)" \ + -e CROSSPLANE_CONTRIB_EXAMPLE_VERSION="$(LATEST_EXAMPLE)" \ + -e CROSSPLANE_CONTRIB_XRD_VERSION="$(LATEST_XRD)" \ + ./pkl/*/ +# Ensures the TAG Variable is set. .PHONY: check-tag check-tag: @[ "${TAG}" ] || (echo "TAG is not specified" && exit 1) +# Packages all Projects with the latest tags for each before Pushing the one referenced in TAG .PHONY: pkl-release pkl-release: check-tag pkl-resolve - $(eval RELEASE_FILES := $(shell pkl project package ./pkl/*/ | grep ${TAG})) + $(eval RELEASE_FILES := $(shell \ + pkl project package \ + -e REPOSITORY="$(REPO)" \ + -e CROSSPLANE_CONTRIB_VERSION="$(LATEST_CORE)" \ + -e CROSSPLANE_CONTRIB_EXAMPLE_VERSION="$(LATEST_EXAMPLE)" \ + -e CROSSPLANE_CONTRIB_XRD_VERSION="$(LATEST_XRD)" \ + ./pkl/*/ | grep ${TAG})) @if [ -z "$(RELEASE_FILES)" ]; then \ echo "No release files found for tag ${TAG}."; \ exit 1; \ diff --git a/pkl/crossplane.contrib.example/PklProject b/pkl/crossplane.contrib.example/PklProject index ff5fe3a..8abf0d6 100644 --- a/pkl/crossplane.contrib.example/PklProject +++ b/pkl/crossplane.contrib.example/PklProject @@ -17,15 +17,18 @@ /// Templates for configuring [Kubernetes](https://kubernetes.io). amends "pkl:Project" +local repo = read?("env:REPOSITORY") ?? "github.com/crossplane-contrib/function-pkl" +local packageVersion: String = read?("env:CROSSPLANE_CONTRIB_EXAMPLE_VERSION") ?? "0.0.0" + package { name = "crossplane.contrib.example" authors { "Tim Geimer <32556895+Avarei@users.noreply.github.com>" } - version = "1.0.0" - baseUri = "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/\(name)" - packageZipUrl = "https://github.com/crossplane-contrib/function-pkl/releases/download/\(name)@\(version)/\(name)@\(version).zip" - sourceCode = "https://github.com/crossplane-contrib/function-pkl" + version = packageVersion + baseUri = "package://pkg.pkl-lang.org/\(repo)/\(name)" + packageZipUrl = "https://\(repo)/releases/download/\(name)@\(version)/\(name)@\(version).zip" + sourceCode = "https://\(repo)" license = "Apache-2.0" description = """ Example for using the [Composition Functions](https://docs.crossplane.io/latest/concepts/composition-functions/). @@ -36,7 +39,7 @@ dependencies { ["crossplane.contrib.xrd"] = import("../crossplane.contrib.xrd/PklProject") ["k8s"] { - uri = "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1" + uri = "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.1.0" } ["k8s.contrib.crd"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib.crd@1.0.7" diff --git a/pkl/crossplane.contrib.example/PklProject.deps.json b/pkl/crossplane.contrib.example/PklProject.deps.json index 35ca7cd..84d9b93 100644 --- a/pkl/crossplane.contrib.example/PklProject.deps.json +++ b/pkl/crossplane.contrib.example/PklProject.deps.json @@ -45,9 +45,9 @@ }, "package://pkg.pkl-lang.org/pkl-k8s/k8s@1": { "type": "remote", - "uri": "projectpackage://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1", + "uri": "projectpackage://pkg.pkl-lang.org/pkl-k8s/k8s@1.1.0", "checksums": { - "sha256": "75c6d66d94c335417a3c502e107aaeadf7a60b4e1d34b2c979afe11193205a1a" + "sha256": "9ca6002419e405a19b517d506490b46be9279556b5ef2664be0e836df80535e5" } }, "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane.contrib.xrd@1": { diff --git a/pkl/crossplane.contrib.xrd/PklProject b/pkl/crossplane.contrib.xrd/PklProject index 4b0b1b4..d7db778 100644 --- a/pkl/crossplane.contrib.xrd/PklProject +++ b/pkl/crossplane.contrib.xrd/PklProject @@ -17,14 +17,15 @@ /// Templates for configuring [Kubernetes](https://kubernetes.io). amends "pkl:Project" -local repo = "github.com/crossplane-contrib/function-pkl" +local repo = read?("env:REPOSITORY") ?? "github.com/crossplane-contrib/function-pkl" +local packageVersion: String = read?("env:CROSSPLANE_CONTRIB_XRD_VERSION") ?? "0.0.0" package { name = "crossplane.contrib.xrd" authors { "Tim Geimer <32556895+Avarei@users.noreply.github.com>" } - version = "1.0.0" + version = packageVersion baseUri = "package://pkg.pkl-lang.org/\(repo)/\(name)" packageZipUrl = "https://\(repo)/releases/download/\(name)@\(version)/\(name)@\(version).zip" sourceCode = "https://\(repo)" @@ -43,5 +44,5 @@ dependencies { ["syntax"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.syntax@1.0.2" } ["openapiv3"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/org.openapis.v3@2.1.1" } - ["k8s"] { uri = "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1" } + ["k8s"] { uri = "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.1.0" } } diff --git a/pkl/crossplane.contrib.xrd/PklProject.deps.json b/pkl/crossplane.contrib.xrd/PklProject.deps.json index 83a1670..6119d55 100644 --- a/pkl/crossplane.contrib.xrd/PklProject.deps.json +++ b/pkl/crossplane.contrib.xrd/PklProject.deps.json @@ -38,9 +38,9 @@ }, "package://pkg.pkl-lang.org/pkl-k8s/k8s@1": { "type": "remote", - "uri": "projectpackage://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1", + "uri": "projectpackage://pkg.pkl-lang.org/pkl-k8s/k8s@1.1.0", "checksums": { - "sha256": "75c6d66d94c335417a3c502e107aaeadf7a60b4e1d34b2c979afe11193205a1a" + "sha256": "9ca6002419e405a19b517d506490b46be9279556b5ef2664be0e836df80535e5" } }, "package://pkg.pkl-lang.org/pkl-pantry/org.openapis.v3@2": { diff --git a/pkl/crossplane.contrib/PklProject b/pkl/crossplane.contrib/PklProject index f66a30c..7556d4b 100644 --- a/pkl/crossplane.contrib/PklProject +++ b/pkl/crossplane.contrib/PklProject @@ -17,15 +17,18 @@ /// Templates for configuring [Kubernetes](https://kubernetes.io). amends "pkl:Project" +local repo = read?("env:REPOSITORY") ?? "github.com/crossplane-contrib/function-pkl" +local packageVersion: String = read?("env:CROSSPLANE_CONTRIB_VERSION") ?? "0.0.0" + package { name = "crossplane.contrib" authors { "Tim Geimer <32556895+Avarei@users.noreply.github.com>" } - version = "1.0.0" - baseUri = "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/\(name)" - packageZipUrl = "https://github.com/crossplane-contrib/function-pkl/releases/download/\(name)@\(version)/\(name)@\(version).zip" - sourceCode = "https://github.com/crossplane-contrib/function-pkl" + version = packageVersion + baseUri = "package://pkg.pkl-lang.org/\(repo)/\(name)" + packageZipUrl = "https://\(repo)/releases/download/\(name)@\(version)/\(name)@\(version).zip" + sourceCode = "https://\(repo)" license = "Apache-2.0" description = """ Templates for reading and configuring [Composition Functions](https://docs.crossplane.io/latest/concepts/composition-functions/). @@ -33,6 +36,6 @@ package { } dependencies { ["k8s"] { - uri = "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1" + uri = "package://pkg.pkl-lang.org/pkl-k8s/k8s@1.1.0" } } diff --git a/pkl/crossplane.contrib/PklProject.deps.json b/pkl/crossplane.contrib/PklProject.deps.json index 3ede6e3..9a7a11a 100644 --- a/pkl/crossplane.contrib/PklProject.deps.json +++ b/pkl/crossplane.contrib/PklProject.deps.json @@ -3,9 +3,9 @@ "resolvedDependencies": { "package://pkg.pkl-lang.org/pkl-k8s/k8s@1": { "type": "remote", - "uri": "projectpackage://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.1", + "uri": "projectpackage://pkg.pkl-lang.org/pkl-k8s/k8s@1.1.0", "checksums": { - "sha256": "75c6d66d94c335417a3c502e107aaeadf7a60b4e1d34b2c979afe11193205a1a" + "sha256": "9ca6002419e405a19b517d506490b46be9279556b5ef2664be0e836df80535e5" } } } From c62e4fe529cc2e7810de0f90b5d9c8a00fad9afd Mon Sep 17 00:00:00 2001 From: Tim <32556895+Avarei@users.noreply.github.com> Date: Wed, 3 Jul 2024 01:52:56 +0200 Subject: [PATCH 2/6] add target for pkl-package creation Signed-off-by: Tim <32556895+Avarei@users.noreply.github.com> --- Makefile | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 39b95cd..354eddb 100644 --- a/Makefile +++ b/Makefile @@ -18,21 +18,30 @@ pkl-resolve: -e CROSSPLANE_CONTRIB_XRD_VERSION="$(LATEST_XRD)" \ ./pkl/*/ +.PHONY: pkl-package +pkl-package: pkl-resolve + $(eval PACKAGE_FILES := $(shell \ + pkl project package \ + -e REPOSITORY="$(REPO)" \ + -e CROSSPLANE_CONTRIB_VERSION="$(LATEST_CORE)" \ + -e CROSSPLANE_CONTRIB_EXAMPLE_VERSION="$(LATEST_EXAMPLE)" \ + -e CROSSPLANE_CONTRIB_XRD_VERSION="$(LATEST_XRD)" \ + ./pkl/*/ )) + # Ensures the TAG Variable is set. .PHONY: check-tag check-tag: @[ "${TAG}" ] || (echo "TAG is not specified" && exit 1) +# Initializes Empty Array +RELEASE_FILES := + # Packages all Projects with the latest tags for each before Pushing the one referenced in TAG .PHONY: pkl-release -pkl-release: check-tag pkl-resolve - $(eval RELEASE_FILES := $(shell \ - pkl project package \ - -e REPOSITORY="$(REPO)" \ - -e CROSSPLANE_CONTRIB_VERSION="$(LATEST_CORE)" \ - -e CROSSPLANE_CONTRIB_EXAMPLE_VERSION="$(LATEST_EXAMPLE)" \ - -e CROSSPLANE_CONTRIB_XRD_VERSION="$(LATEST_XRD)" \ - ./pkl/*/ | grep ${TAG})) +pkl-release: check-tag pkl-package + $(foreach file,$(PACKAGE_FILES), \ + $(if $(findstring ${TAG},$(file)), \ + $(eval RELEASE_FILES += $(file)))) @if [ -z "$(RELEASE_FILES)" ]; then \ echo "No release files found for tag ${TAG}."; \ exit 1; \ From a21369f5a6a6ad5c339894182273c897312ac8df Mon Sep 17 00:00:00 2001 From: Tim <32556895+Avarei@users.noreply.github.com> Date: Wed, 3 Jul 2024 01:53:54 +0200 Subject: [PATCH 3/6] update docs for releasing Pkl Packages Signed-off-by: Tim <32556895+Avarei@users.noreply.github.com> --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e129ef7..bb3cef9 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,15 @@ $ crossplane xpkg build -f package --embed-runtime-image=runtime $ crossplane xpkg push -f function-pkl*.xpkg ghcr.io/crossplane-contrib/function-pkl # Resolve Pkl Project Dependencies -$ pkl project resolve ./pkl/*/ +$ make pkl-resolve # Package the Pkl Project -$ pkl project package ./pkl/*/ +$ make pkl-package + +# Release a Pkl Project +$ git tag crossplane.contrib@x.y.z +$ git push --tags +$ make pkl-release TAG=crossplane.contrib@x.y.z # Debugging this function # While a Debugging session is running run on the same host: From 18f4947f781fbc6fa87c4aa5ff0e9d0e00ae047d Mon Sep 17 00:00:00 2001 From: Tim <32556895+Avarei@users.noreply.github.com> Date: Wed, 3 Jul 2024 02:31:24 +0200 Subject: [PATCH 4/6] fetch tags in pipeline Signed-off-by: Tim <32556895+Avarei@users.noreply.github.com> --- .github/workflows/pkl.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pkl.yml b/.github/workflows/pkl.yml index db20711..e170906 100644 --- a/.github/workflows/pkl.yml +++ b/.github/workflows/pkl.yml @@ -10,6 +10,8 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@v4 + with: + fetch-tags: true - name: Setup Pkl uses: pkl-community/setup-pkl@v0 with: From 78df314f499bef94c5db94d62848dec5d4471fd3 Mon Sep 17 00:00:00 2001 From: Tim <32556895+Avarei@users.noreply.github.com> Date: Wed, 3 Jul 2024 02:35:57 +0200 Subject: [PATCH 5/6] fix fetch tags in pipeline Signed-off-by: Tim <32556895+Avarei@users.noreply.github.com> --- .github/workflows/pkl.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pkl.yml b/.github/workflows/pkl.yml index e170906..c226b74 100644 --- a/.github/workflows/pkl.yml +++ b/.github/workflows/pkl.yml @@ -10,14 +10,14 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@v4 - with: - fetch-tags: true - name: Setup Pkl uses: pkl-community/setup-pkl@v0 with: pkl-version: 0.26.1 - name: Login to GH run: echo ${{ github.token }} | gh auth login --with-token + - name: Fetch Tags + run: git fetch --tags - name: Get Tag Name run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - name: Package and Create GitHub Release From f894833fc5df7dd627ce834f817bf12f40c6e211 Mon Sep 17 00:00:00 2001 From: Tim <32556895+Avarei@users.noreply.github.com> Date: Wed, 3 Jul 2024 02:39:39 +0200 Subject: [PATCH 6/6] remove prerelease and draft parameters Signed-off-by: Tim <32556895+Avarei@users.noreply.github.com> --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 354eddb..8ee9f7f 100644 --- a/Makefile +++ b/Makefile @@ -51,8 +51,6 @@ pkl-release: check-tag pkl-package -t ${TAG} \ -n "" \ --target ${TARGET} \ - --prerelease \ - --draft \ $(RELEASE_FILES) .PHONY: build-image