Skip to content

Commit

Permalink
Merge pull request #12 from Avarei/pkl-pipeline
Browse files Browse the repository at this point in the history
Pkl pipeline
  • Loading branch information
Avarei authored Jul 1, 2024
2 parents 815b402 + d8272ca commit f52b0f2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 73 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pkl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Pkl"
on:
push:
tags:
- 'crossplane.contrib*.*.*'

jobs:
pkl:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- 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: Get Tag Name
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Package and Create GitHub Release
id: create_package
run: make pkl-release TAG=$TAG_NAME TARGET=${{ github.sha }}
95 changes: 28 additions & 67 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,77 +1,38 @@
REPO := github.com/crossplane-contrib/function-pkl
CONTAINER_IMAGE := ghcr.io/crossplane-contrib/function-pkl
TAG := v0.0.1

# Branch used for Pkl Package Releases
BRANCH := $(shell git branch --show-current)

PKL_BASE_URI := package://pkg.pkl-lang.org

PKL_CORE_NAME := crossplane
PKL_CORE_VERSION := 1.0.0
PKL_CORE_REF := ${PKL_CORE_NAME}@${PKL_CORE_VERSION}
PKL_CORE_URI := ${PKL_BASE_URI}/${REPO}/${PKL_CORE_REF}

PKL_EXAMPLE_NAME := crossplane-example
PKL_EXAMPLE_VERSION := 1.0.0
PKL_EXAMPLE_REF := ${PKL_EXAMPLE_NAME}@${PKL_EXAMPLE_VERSION}
PKL_EXAMPLE_URI := ${PKL_BASE_URI}/${REPO}/${PKL_CORE_REF}

SED_MAC = sed -i '' -E "s|($(PKL_BASE_URI)/${REPO}/$(PACKAGE_NAME)@)([0-9]+\.[0-9]+\.[0-9]+)|\1$(PACKAGE_VERSION)|g"
SED_LINUX = sed -i -E "s|($(PKL_BASE_URI)/${REPO}/$(PACKAGE_NAME)@)([0-9]+\.[0-9]+\.[0-9]+)|\1$(PACKAGE_VERSION)|g"
SED_TARGETS := example/ README.md pkl/${PKL_CORE_NAME}/PklProject pkl/${PKL_EXAMPLE_NAME}/PklProject

.PHONY: build-core-package
build-core-package: PACKAGE_NAME := $(PKL_CORE_NAME)
build-core-package: PACKAGE_VERSION := $(PKL_CORE_VERSION)
build-core-package:
pkl project resolve ./pkl/${PACKAGE_NAME}/
ifeq ($(shell uname), Darwin)
find $(SED_TARGETS) -type f -exec $(SED_MAC) {} +
else
find $(SED_TARGETS) -type f -exec $(SED_LINUX) {} +
endif


.PHONY: release-pkl-crossplane
release-pkl-crossplane:
pkl project resolve ./pkl/${PKL_CORE_NAME}/ && \
RELEASE_FILES=$$(pkl project package ./pkl/${PKL_CORE_NAME}/) && \
gh release create ${PKL_CORE_REF} \
-t ${PKL_CORE_REF} \
-n "" \
--target ${BRANCH} \
--prerelease \
$$RELEASE_FILES

.PHONY: build-example-package
build-example-package: PACKAGE_NAME := $(PKL_EXAMPLE_NAME)
build-example-package: PACKAGE_VERSION := $(PKL_EXAMPLE_VERSION)
build-example-package:
pkl project resolve ./pkl/${PACKAGE_NAME}/
ifeq ($(shell uname), Darwin)
find $(SED_TARGETS) -type f -exec $(SED_MAC) {} +
else
find $(SED_TARGETS) -type f -exec $(SED_LINUX) {} +
endif

.PHONY: build-pkl-crossplane-example
release-pkl-crossplane-example:
pkl project resolve ./pkl/${PKL_EXAMPLE_NAME}/ && \
RELEASE_FILES=$$(pkl project package ./pkl/${PKL_EXAMPLE_NAME}/) && \
gh release create ${PKL_EXAMPLE_REF} \
-t ${PKL_EXAMPLE_REF} \
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)

.PHONY: pkl-resolve
pkl-resolve:
pkl project resolve ./pkl/*/

.PHONY: check-tag
check-tag:
@[ "${TAG}" ] || (echo "TAG is not specified" && exit 1)

.PHONY: pkl-release
pkl-release: check-tag pkl-resolve
$(eval RELEASE_FILES := $(shell pkl project package ./pkl/*/ | grep ${TAG}))
@if [ -z "$(RELEASE_FILES)" ]; then \
echo "No release files found for tag ${TAG}."; \
exit 1; \
fi

gh release create ${TAG} \
-t ${TAG} \
-n "" \
--target ${BRANCH} \
--target ${TARGET} \
--prerelease \
$$RELEASE_FILES
--draft \
$(RELEASE_FILES)

.PHONY: build-image
build-image:
docker build --build-arg PKL_CORE_PACKAGE=${PKL_CORE_URI} -t runtime .
docker build --build-arg -t runtime .
crossplane xpkg build -f package --embed-runtime-image=runtime -o .out/function-pkl.xpkg


.PHONY: push-image
push-image:
crossplane xpkg push -f .out/function-pkl.xpkg ${CONTAINER_IMAGE}:${TAG}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,26 @@ $ 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 project resolve ./pkl/*/

# Package the Pkl Project
$ pkl project package
$ pkl project package ./pkl/*/

# Debugging this function
# While a Debugging session is running run on the same host:
$ crossplane beta render xr.yaml composition.yaml functions.yaml --verbose
```

### Creating a new Release
#### Composition Function
Run the [CI action](https://github.com/crossplane-contrib/function-pkl/actions/workflows/ci.yml) and provide a Package version.
#### Pkl Packages
Update `PklProject.package.version` of the relevant Package in ./pkl/

Create a Tag in the style of <PklProject.package.name>@<PklProject.package.version> e.g. `git tag [email protected]`

Push it `git push --tags`

### Pkl Function Flow
This Chart illustrates how what happens, when Crossplane Triggers this Composition Function.

Expand Down
1 change: 0 additions & 1 deletion example/inline/composition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ spec:
}
meta = if (request.meta != null) new ResponseMeta {
tag = request.meta.tag
ttl = 60.s
} else null
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 @@ -50,9 +50,9 @@
"sha256": "75c6d66d94c335417a3c502e107aaeadf7a60b4e1d34b2c979afe11193205a1a"
}
},
"package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crospslane.contrib.xrd@1": {
"package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane.contrib.xrd@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crospslane[email protected]",
"uri": "projectpackage://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane[email protected]",
"path": "../crossplane.contrib.xrd"
},
"package://pkg.pkl-lang.org/pkl-pantry/org.openapis.v3@2": {
Expand Down
2 changes: 1 addition & 1 deletion pkl/crossplane.contrib.xrd/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ amends "pkl:Project"
local repo = "github.com/crossplane-contrib/function-pkl"

package {
name = "crospslane.contrib.xrd"
name = "crossplane.contrib.xrd"
authors {
"Tim Geimer <[email protected]>"
}
Expand Down

0 comments on commit f52b0f2

Please sign in to comment.