Skip to content

Commit

Permalink
Merge pull request #17 from Avarei/better-pipeline
Browse files Browse the repository at this point in the history
version of pkl packages is now inferred from env variables
  • Loading branch information
Avarei authored Jul 3, 2024
2 parents 23f5405 + f894833 commit e477f50
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pkl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
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
Expand Down
39 changes: 32 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
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/*/

.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 ./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; \
Expand All @@ -24,8 +51,6 @@ pkl-release: check-tag pkl-resolve
-t ${TAG} \
-n "" \
--target ${TARGET} \
--prerelease \
--draft \
$(RELEASE_FILES)

.PHONY: build-image
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
$ git push --tags
$ make pkl-release [email protected]

# Debugging this function
# While a Debugging session is running run on the same host:
Expand Down
13 changes: 8 additions & 5 deletions pkl/crossplane.contrib.example/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
}
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/).
Expand All @@ -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/[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions pkl/crossplane.contrib.example/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions pkl/crossplane.contrib.xrd/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"
}
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)"
Expand All @@ -43,5 +44,5 @@ dependencies {
["syntax"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" }
["openapiv3"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" }

["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" }
}
4 changes: 2 additions & 2 deletions pkl/crossplane.contrib.xrd/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 8 additions & 5 deletions pkl/crossplane.contrib/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@
/// 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 <[email protected]>"
}
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/).
"""
}
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"
}
}
4 changes: 2 additions & 2 deletions pkl/crossplane.contrib/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down

0 comments on commit e477f50

Please sign in to comment.