pkl-swift/.circleci/config.pkl

250 lines
6.4 KiB
Plaintext

// ===----------------------------------------------------------------------===//
// Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ===----------------------------------------------------------------------===//
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.1.1#/PklCI.pkl"
import "pkl:semver"
local swiftTest = new RunStep {
name = "swift test"
command = """
mkdir -p .out/test-results/
swift test -vv --parallel --num-workers 1 --xunit-output .out/test-results/xunit.xml -Xswiftc -warnings-as-errors
"""
}
local class PklDistribution {
/// The version of this distribution
version: String(semver.isValid(this))
/// Normalized version for use in task names
fixed normalizedVersion: String = version.replaceAll(".", "-")
/// The URL to download this distribution
fixed downloadUrl: String = "https://github.com/apple/pkl/releases/download/\(version)/pkl-linux-amd64"
fixed downloadRunStep: RunStep = new {
name = "Downloading pkl-\(version)"
command = """
PKL=$(mktemp /tmp/pkl-\(version)-XXXXXX)
curl -L "\(downloadUrl)" > $PKL
chmod +x $PKL
echo "export PKL_EXEC=$PKL" >> $BASH_ENV
"""
}
}
local pklCurrent: PklDistribution = new {
version = "0.27.2"
}
local pklDistributions: Listing<PklDistribution> = new {
new { version = "0.25.3" }
pklCurrent
}
local testJobs = jobs.keys.filter((it) -> it.startsWith("test"))
main {
jobs {
...testJobs
}
}
prb {
jobs {
...testJobs
}
}
release {
jobs {
...testJobs
new {
["pkl-package"] {
requires {
...testJobs
}
}
}
new {
["pkl-gen-swift-macos"] {
requires {
...testJobs
}
}
}
new {
["pkl-gen-swift-linux-amd64"] {
requires {
...testJobs
}
}
}
new {
["pkl-gen-swift-linux-aarch64"] {
requires {
...testJobs
}
}
}
new {
["do-release"] {
requires {
"pkl-package"
"pkl-gen-swift-macos"
"pkl-gen-swift-linux-amd64"
"pkl-gen-swift-linux-aarch64"
}
context {
"pkl-github-release"
}
}
}
}
}
triggerDocsBuild = "release"
triggerPackageDocsBuild = "release"
jobs {
for (distribution in pklDistributions) {
["test-pkl-\(distribution.normalizedVersion)"] {
docker {
new {
image = "swift:5.9-rhel-ubi9"
}
}
resource_class = "xlarge"
steps {
"checkout"
distribution.downloadRunStep
swiftTest
new RunStep { command = "make test-snippets" }
new RunStep { command = "make test-pkl" }
new RunStep { command = "make generate-fixtures" }
new StoreTestResults {
path = ".out/test-results/"
}
}
}
}
["pkl-gen-swift-macos"] {
macos {
xcode = "15.2.0"
}
resource_class = "macos.m1.large.gen1"
steps {
"checkout"
new RunStep {
name = "Build pkl-gen-swift"
command = """
make pkl-gen-swift-release
mkdir -p out/pkl-gen-swift/
cp $(make pkl-gen-swift-release-output) out/pkl-gen-swift/pkl-gen-swift-macos.bin
"""
}
new PersistToWorkspaceStep { paths { "out/" }; root = "." }
}
}
for (arch in List("aarch64", "amd64")) {
["pkl-gen-swift-linux-\(arch)"] {
docker {
new {
image = "swift:5.9-rhel-ubi9"
}
}
resource_class = if (arch == "amd64") "xlarge" else "arm.xlarge"
steps {
"checkout"
new RunStep {
name = "Build pkl-gen-swift"
command = """
make pkl-gen-swift-release
mkdir -p out/pkl-gen-swift/
cp $(make pkl-gen-swift-release-output) out/pkl-gen-swift/pkl-gen-swift-linux-\(arch).bin
"""
}
new PersistToWorkspaceStep { paths { "out/" }; root = "." }
}
}
}
["pkl-package"] {
docker {
new { image = "cimg/base:current" }
}
steps {
"checkout"
pklCurrent.downloadRunStep
new RunStep {
// TODO remove skip-publish-check after initial release
command = #"$PKL_EXEC project package --skip-publish-check --output-path out/pkl-package/ codegen/src/"#
}
new PersistToWorkspaceStep {
paths {
"out/"
}
root = "."
}
}
}
["do-release"] {
docker {
new { image = "maniator/gh:v2.40.1" }
}
steps {
"checkout"
new AttachWorkspaceStep { at = "." }
new RunStep {
name = "Do release"
// language=bash
command = #"""
EXPECTED_VERSION=$(cat VERSION.txt)
if [ "${EXPECTED_VERSION}" != "${CIRCLE_TAG}" ]; then
echo "Mismatching versions!"
echo "VERSION.txt has ${EXPECTED_VERSION}"
echo "Git tag is ${CIRCLE_TAG}"
echo "Update VERSION.txt to match the tag, and re-tag."
exit 1
fi
echo "Creating release for Pkl package"
gh release create "pkl.swift@${CIRCLE_TAG}" \
--title "pkl.swift@${CIRCLE_TAG}" \
--target "${CIRCLE_SHA1}" \
--notes "This holds the release assets for the pkl.swift Pkl package." \
--repo "${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" \
out/pkl-package/*
echo "Creating release for Swift library"
gh release create "${CIRCLE_TAG}" \
--title "${CIRCLE_TAG}" \
--target "${CIRCLE_SHA1}" \
--verify-tag \
--notes "Release notes: https://pkl-lang.org/swift/current/CHANGELOG.html#release-${CIRCLE_TAG}" \
--repo "${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" \
out/pkl-gen-swift/*
"""#
}
}
}
}