Skip to content

Commit

Permalink
Use upstream pkl-gha for GitHub Action Workflows (#3677)
Browse files Browse the repository at this point in the history
* Use upstream for pkl workflows

Signed-off-by: StefMa <[email protected]>

* Remove custom pkl project

Signed-off-by: StefMa <[email protected]>

* Translate pkl actions

---------

Signed-off-by: StefMa <[email protected]>
  • Loading branch information
StefMa authored Dec 30, 2024
1 parent e24061b commit b8820ce
Show file tree
Hide file tree
Showing 25 changed files with 399 additions and 1,108 deletions.
4 changes: 1 addition & 3 deletions .github/build-workflows.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Get-ChildItem -Path './pkl-workflows' -Filter *.pkl -File -Name | ForEach-Object {
&pkl eval ./pkl-workflows/$_ -o "./workflows/$($_.Replace('pkl', 'yml'))"
}
pkl eval pkl-workflows/*.pkl -o workflows/%{moduleName}.yml
690 changes: 0 additions & 690 deletions .github/pkl-workflows/GithubAction/GithubAction.pkl

This file was deleted.

8 changes: 0 additions & 8 deletions .github/pkl-workflows/GithubAction/PklProject

This file was deleted.

4 changes: 0 additions & 4 deletions .github/pkl-workflows/GithubAction/PklProject.deps.json

This file was deleted.

5 changes: 0 additions & 5 deletions .github/pkl-workflows/PklProject

This file was deleted.

10 changes: 0 additions & 10 deletions .github/pkl-workflows/PklProject.deps.json

This file was deleted.

4 changes: 2 additions & 2 deletions .github/pkl-workflows/Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Preprocessing the GA workflows

We're using [pkl](http://github.com/apple/pkl) to generate the github actions workflows.
We're using [pkl](http://github.com/apple/pkl) to generate the GitHub actions workflows.

## Prerequisites

Expand All @@ -18,5 +18,5 @@ Run `pwsh .github/build-workflows.ps1` or the following bash script if you don't

```bash
cd $SolutionDir/.github/pkl-workflows
for file in *.pkl ; do pkl eval $file -o ../workflows/$(echo $file | sed s/pkl/yml/) ; done
pkl eval *.pkl -o ../workflows/%{moduleName}.yml
```
6 changes: 3 additions & 3 deletions .github/pkl-workflows/codeql.pkl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module codeql

amends "GithubAction/GithubAction.pkl"
amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl"

import "helpers/Common.pkl"
import "helpers/Steps.pkl"
Expand Down Expand Up @@ -34,9 +34,9 @@ concurrency {
`cancel-in-progress` = true
}
jobs {
["analyze-csharp"] = new Job {
["analyze-csharp"] {
name = "Analyze C#"
`runs-on` = new WindowsLatest{}
`runs-on` = new WindowsLatest {}
permissions {
actions = "read"
contents = "read"
Expand Down
12 changes: 7 additions & 5 deletions .github/pkl-workflows/helpers/BaaS.pkl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module baas

import "../GithubAction/GithubAction.pkl" as gha
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" as gha
import "Common.pkl"
import "Steps.pkl"

function deploy(differentiators: Listing<Common.SyncDifferentiator>): gha.MatrixJob = new {
function deploy(differentiators: Listing<Common.SyncDifferentiator>): gha.Job = new {
name = "Deploy BaaS"
`runs-on` = new gha.UbuntuLatest{}
`runs-on` = new gha.UbuntuLatest {}
strategy {
matrix {
["differentiator"] = differentiators
}
`fail-fast` = false
}
`if` = Common.ifNotCanceledCondition
steps {
Expand All @@ -26,13 +27,14 @@ function deployStep(differentiator: Common.SyncDifferentiator?, shouldDeploy: Bo
`working-directory` = "Tools/DeployApps"
}) else List()

function cleanup(differentiators: Listing<Common.SyncDifferentiator>): gha.MatrixJob = new {
function cleanup(differentiators: Listing<Common.SyncDifferentiator>): gha.Job = new {
name = "Cleanup BaaS"
`runs-on` = new gha.UbuntuLatest{}
`runs-on` = new gha.UbuntuLatest {}
strategy {
matrix {
["differentiator"] = differentiators
}
`fail-fast` = false
}
`if` = Common.ifNotCanceledCondition
steps {
Expand Down
16 changes: 8 additions & 8 deletions .github/pkl-workflows/helpers/Common.pkl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module common

import "../GithubAction/GithubAction.pkl" as gha
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" as gha
import "BaaS.pkl"
import "Lint.pkl"
import "Package.pkl"
Expand All @@ -24,9 +24,9 @@ local const job_Wrappers: String = "build-wrappers"

const mainBranch: String = "main"

typealias NetFramework = "net6.0" | "net8.0" | String(startsWith("${{ matrix")) | String(startsWith("net8"))
typealias NetRuntime = "win-x64" | "linux-x64" | "osx-x64" | "osx-arm64" | String(startsWith("${{ matrix"))
typealias SyncDifferentiator = "ios-maui" | "android-maui" | "tvos" | "macos-maui" | "code-coverage" | "uwp" | "net-framework" | String(startsWith("${{ matrix"))
typealias NetFramework = "net6.0"|"net8.0"|String(startsWith("${{ matrix"))|String(startsWith("net8"))
typealias NetRuntime = "win-x64"|"linux-x64"|"osx-x64"|"osx-arm64"|String(startsWith("${{ matrix"))
typealias SyncDifferentiator = "ios-maui"|"android-maui"|"tvos"|"macos-maui"|"code-coverage"|"uwp"|"net-framework"|String(startsWith("${{ matrix"))

const wrapperBinaryNames: List<String> =
List("macos", "catalyst")
Expand All @@ -36,7 +36,7 @@ const wrapperBinaryNames: List<String> =
+ uwpArchs.map((arch) -> "windows-uwp-\(arch)")
+ applePlatformTargets((platform, target) -> "\(platform)-\(target)")

const defaultEnv: Mapping<String, String | Boolean> = new {
const defaultEnv: Mapping<String, String|Boolean|Number> = new {
["REALM_DISABLE_ANALYTICS"] = true
["DOTNET_NOLOGO"] = true
}
Expand All @@ -50,13 +50,13 @@ const packages: List<String> = nugetPackages + List("Realm.UnityUtils", "Realm.U

const testTimeout: Int = 60

const function defaultBuildJobs(baasDifferentiators: Listing<SyncDifferentiator>, netCoreVersions: Listing<NetFramework>): Mapping<String, gha.JobBase> = new {
[job_Wrappers] = new gha.ReusableWorkflowJob {
const function defaultBuildJobs(baasDifferentiators: Listing<SyncDifferentiator>, netCoreVersions: Listing<NetFramework>): Mapping<String, gha.Job> = new {
[job_Wrappers] = new gha.ReusableJob {
uses = "./.github/workflows/wrappers.yml"
name = "Wrappers"
}
[job_Baas] = BaaS.deploy(baasDifferentiators)
[job_Packages] = (Package.nuget("contains(github.head_ref, 'release')")){
[job_Packages] = (Package.nuget("contains(github.head_ref, 'release')")) {
needs {
job_Wrappers
}
Expand Down
8 changes: 4 additions & 4 deletions .github/pkl-workflows/helpers/Lint.pkl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module lint

import "../GithubAction/GithubAction.pkl" as gha
import "Steps.pkl"
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" as gha
import "Common.pkl"
import "Steps.pkl"

const actionVerifyTODO = "nirinchev/verify-todo@ffa352ac028b4cdc8bc626471d33aa341b3ab7c9"

function lint(): gha.Job = new {
name = "Verify TODOs"
`runs-on` = new gha.UbuntuLatest{}
`runs-on` = new gha.UbuntuLatest {}
steps {
Steps.checkoutWithoutMatchers(false)
new gha.Step {
Expand All @@ -24,7 +24,7 @@ function lint(): gha.Job = new {
}

function verifyNamespaces(): gha.Job = new {
`runs-on` = new gha.UbuntuLatest{}
`runs-on` = new gha.UbuntuLatest {}
name = "Verify Namespaces"
needs {
Common.job_Packages
Expand Down
10 changes: 5 additions & 5 deletions .github/pkl-workflows/helpers/Package.pkl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module package

import "../GithubAction/GithubAction.pkl" as gha
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" as gha
import "Actions.pkl"
import "Common.pkl"
import "Steps.pkl"
import "Actions.pkl"

const unityPkgName = "io.realm.unity-${{ needs.\(Common.job_Packages).outputs.\(Steps.getVersionOutput) }}.tgz"

Expand All @@ -14,7 +14,7 @@ local const buildSuffixOutput = "build_suffix"

function nuget(shouldBuildDocsCondition: String): gha.Job = new {
name = "Package NuGet"
`runs-on` = new gha.WindowsLatest{}
`runs-on` = new gha.WindowsLatest {}
`if` = Common.ifNotCanceledCondition
outputs {
[Steps.getVersionOutput] = Steps.getVersionExpresssion
Expand All @@ -37,15 +37,15 @@ function nuget(shouldBuildDocsCondition: String): gha.Job = new {
Steps.readVersionFromPackage()
for (pkgName in Common.packages) {
let (finalPkgName = "\(pkgName).\(Steps.getVersionExpresssion)")
Steps.uploadArtifacts(finalPkgName, "Realm/packages/\(finalPkgName).*nupkg")
Steps.uploadArtifacts(finalPkgName, "Realm/packages/\(finalPkgName).*nupkg")
}
Steps.uploadArtifacts("ExtractedChangelog", "Realm/Realm/ExtractedChangelog.md")
...buildDocs(shouldBuildDocsCondition)
}
}
function unity(): gha.Job = new {
name = "Package Unity"
`runs-on` = new gha.WindowsLatest{}
`runs-on` = new gha.WindowsLatest {}
`timeout-minutes` = 30
`if` = Common.ifNotCanceledCondition
needs {
Expand Down
28 changes: 14 additions & 14 deletions .github/pkl-workflows/helpers/Steps.pkl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import "../GithubAction/GithubAction.pkl" as gha
import "Common.pkl"
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" as gha
import "Actions.pkl"
import "Common.pkl"

const getVersionStepName = "get-version"
const getVersionOutput = "package_version"

const getVersionExpresssion = "${{ steps.\(getVersionStepName).outputs.\(getVersionOutput) }}"

const function checkout(submodules: (Boolean | "recursive")): Listing<gha.Step> = new {
const function checkout(submodules: (Boolean|"recursive")): Listing<gha.Step> = new {
checkoutWithoutMatchers(submodules)
registerProblemMatchers()
}

const function checkoutWithoutMatchers(submodules: (Boolean | "recursive")): gha.Step = new {
const function checkoutWithoutMatchers(submodules: (Boolean|"recursive")): gha.Step = new {
name = "Checkout Code"
uses = Actions.checkout
with {
Expand Down Expand Up @@ -136,7 +136,7 @@ const function setupAndroid(): Listing<gha.Step> = new {
}
}

const function configureAWSCredentials(accessKey: String, secretKey: String, region: "us-east-1" | "us-west-2" | "us-east-2"): gha.Step = new {
const function configureAWSCredentials(accessKey: String, secretKey: String, region: "us-east-1"|"us-west-2"|"us-east-2"): gha.Step = new {
name = "Configure AWS Credentials"
uses = Actions.awsConfigureCredentials
with {
Expand All @@ -157,7 +157,7 @@ const function readVersionFromPackage(): gha.Step = new {
shell = "bash"
}

const function uploadToNPM(tag: "latest" | "alpha"): Listing<gha.Step> = new {
const function uploadToNPM(tag: "latest"|"alpha"): Listing<gha.Step> = new {
local packageName = "io.realm.unity-\(getVersionExpresssion).tgz"

new {
Expand Down Expand Up @@ -186,18 +186,18 @@ const function uploadPackagesToSleet(versionExpression: String, expectShortPath:
configureAWSCredentials("NUGET_S3_ACCESS_KEY", "NUGET_S3_SECRET_KEY", "us-east-1")
for (package in Common.nugetPackages) {
let (packageWithVersion = "\(package).\(versionExpression)")
let (packagePath = "\(if (expectShortPath) "" else "\(packageWithVersion)/")\(packageWithVersion).nupkg")
new {
name = "NuGet Publish \(packageWithVersion)"
run = "sleet push ${{ github.workspace }}/Realm/packages/\(packagePath) --config ${{ github.workspace }}/.github/sleet.json --source NugetSource"
}
let (packagePath = "\(if (expectShortPath) "" else "\(packageWithVersion)/")\(packageWithVersion).nupkg")
new {
name = "NuGet Publish \(packageWithVersion)"
run = "sleet push ${{ github.workspace }}/Realm/packages/\(packagePath) --config ${{ github.workspace }}/.github/sleet.json --source NugetSource"
}
}
}

class MSBuildConfig {
projects: Listing<String>
target: String?
properties: Mapping<String, String> = new{}
properties: Mapping<String, String> = new {}
standaloneExe: Boolean = false

function getTargetForInvocation(): String = if (target != null) " -t:\(target)" else ""
Expand Down Expand Up @@ -280,9 +280,9 @@ const function cleanupWorkspace(): gha.Step = new {
class SimulatorConfig {
appPath: String
bundleId: String
iphoneToSimulate: "Apple-TV-1080p" | "iPhone-8" | "iPhone-15"
iphoneToSimulate: "Apple-TV-1080p"|"iPhone-8"|"iPhone-15"
arguments: String
os: "tvOS" | "iOS"
os: "tvOS"|"iOS"
}

class DeviceFarmConfig {
Expand Down
Loading

0 comments on commit b8820ce

Please sign in to comment.