-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d266b8b
Showing
7 changed files
with
445 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
module com.github.GitHubAction | ||
|
||
// JSON Schema defination: | ||
// https://json.schemastore.org/github-workflow.json | ||
|
||
// Definitions | ||
|
||
// Trigger | ||
abstract class Trigger { | ||
hidden name: String | ||
} | ||
|
||
class Push extends Trigger { | ||
branches: Listing<String>? | ||
`branches-ignore`: Listing<String>? | ||
tags: Listing<String>? | ||
`tags-ignore`: Listing<String>? | ||
paths: Listing<String>? | ||
`paths-ignore`: Listing<String>? | ||
} | ||
|
||
class WorkflowDispatch extends Trigger { | ||
inputs: Mapping<String, Input>? | ||
} | ||
class Input { | ||
description: String | ||
deprecatedMessage: String? | ||
required: Boolean? | ||
default: String? | ||
type: InputType? | ||
options: Listing<String>? | ||
} | ||
typealias InputType = "boolean"|"string"|"choice"|"environment"|"number" | ||
|
||
class PullRequest extends Trigger { | ||
types: Listing<PullRequestTypes> | ||
} | ||
typealias PullRequestTypes = | ||
"assigned" | ||
|"unassigned" | ||
|"review_requested" | ||
|"review_request_removed" | ||
|"labeled" | ||
|"unlabeled" | ||
|"opened" | ||
|"edited" | ||
|"closed" | ||
|"reopened" | ||
|"synchronize" | ||
|"ready_for_review" | ||
|"locked" | ||
|"unlocked" | ||
|"ready_for_review" | ||
|"converted_to_draft" | ||
|"demilestoned" | ||
|"milestoned" | ||
|"review_requested" | ||
|"review_request_removed" | ||
|"auto_merge_enabled" | ||
|"auto_merge_disabled" | ||
|
||
// On | ||
class On { | ||
push: Push? | ||
workflow_dispatch: WorkflowDispatch? | ||
pull_request: PullRequest? | ||
} | ||
|
||
// Environment Variables | ||
typealias EnvironmentVariables = Mapping<String, String> | ||
|
||
// Permissions | ||
class Permissions { | ||
actions: Permission? | ||
checks: Permission? | ||
contents: Permission? | ||
deployments: Permission? | ||
`id-token`: Permission? | ||
issues: Permission? | ||
discussions: Permission? | ||
packages: Permission? | ||
pages: Permission? | ||
`pull-requests`: Permission? | ||
`repository-projects`: Permission? | ||
`security-events`: Permission? | ||
statuses: Permission? | ||
} | ||
typealias Permission = "read"|"write"|"none" | ||
|
||
// Concurrency | ||
class Concurrency { | ||
group: String | ||
`cancel-in-progress`: Boolean | ||
} | ||
|
||
// Jobs | ||
class Job { | ||
`runs-on`: Machine|String | ||
`if`: String? | ||
steps: Listing<Step> | ||
env: EnvironmentVariables? | ||
concurrency: Concurrency? | ||
} | ||
|
||
// Machines, part of Jobs | ||
abstract class Machine { | ||
name: String | ||
} | ||
class UbuntuLatest extends Machine { | ||
name = "ubuntu-latest" | ||
} | ||
class MacOsLatest extends Machine { | ||
name = "macos-latest" | ||
} | ||
class WindowsLatest extends Machine { | ||
name = "windows-latest" | ||
} | ||
|
||
// Steps, part of Jobs | ||
open class Step { | ||
name: String? | ||
id: String? | ||
`if`: String? | ||
env: EnvironmentVariables? | ||
`working-directory`: String? | ||
} | ||
|
||
class RunStep extends Step { | ||
run: String | ||
} | ||
|
||
class UsesStep extends Step { | ||
uses: String | ||
with: Mapping<String, String>? | ||
} | ||
|
||
// Templating | ||
|
||
name: String | ||
|
||
on: On | ||
|
||
env: EnvironmentVariables? | ||
|
||
concurrency: Concurrency? | ||
|
||
permissions: (Permissions|"read-all"|"write-all")? | ||
|
||
jobs: Mapping<String, Job> | ||
|
||
// Output | ||
output { | ||
renderer = new YamlRenderer { | ||
converters { | ||
["runs-on"] = (runsOn: String|Machine) -> if (runsOn is Machine) runsOn.name else runsOn | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
amends "pkl:Project" | ||
|
||
package { | ||
name = "com.github.action" | ||
baseUri = "package://github.com/stefma/pkl-gha" | ||
version = "0.0.1" | ||
packageZipUrl = "https://github.com/stefma/pkl-gha/releases/download/\(name)@\(version)/\(name)@\(version).zip" | ||
sourceCode = "https://github.com/stefma/pkl-gha" | ||
// apiTests = import*("tests/**.pkl").keys.toListing() // Doesn't work | ||
exclude { | ||
"examples/**" | ||
"tests/**" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"resolvedDependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
amends "../GitHubAction.pkl" | ||
|
||
name = "PrintHelloWorld" | ||
|
||
// Fake: not implemented yet in generic GitHubAction module... | ||
local class LabelTrigger extends Trigger { | ||
name = "label" | ||
types = new Listing<String> { | ||
"created" | ||
} | ||
} | ||
|
||
on { | ||
push { | ||
`tags-ignore` { | ||
"v*" | ||
} | ||
branches { | ||
"master" | ||
"develop" | ||
} | ||
} | ||
pull_request { | ||
types { | ||
"opened" | ||
"edited" | ||
"reopened" | ||
"synchronize" | ||
"review_requested" | ||
} | ||
} | ||
workflow_dispatch { | ||
inputs { | ||
["name"] = new { | ||
description = "Name of the person to greet" | ||
required = true | ||
default = "Mona the Octocat" | ||
} | ||
} | ||
} | ||
} | ||
|
||
permissions = new Permissions { | ||
actions = "read" | ||
contents = "read" | ||
issues = "write" | ||
`pull-requests` = "write" | ||
} | ||
|
||
env { | ||
["PR_NUMBER"] = "${{github.event.number}}" | ||
} | ||
|
||
concurrency { | ||
group = "example-group" | ||
`cancel-in-progress` = true | ||
} | ||
|
||
jobs { | ||
["hello_dependabot"] = new { | ||
`runs-on` = new MacOsLatest {} | ||
`if` = "${{ github.actor == 'dependabot[bot]' }}" | ||
steps { | ||
new UsesStep { | ||
name = "Checkout" | ||
uses = "actions/checkout@v4" | ||
with = new { | ||
["ref"] = "develop" | ||
["token"] = "${{ secrets.GITHUB_TOKEN }}" | ||
} | ||
} | ||
new RunStep { | ||
name = "Hello World" | ||
`working-directory` = "src/" | ||
run = "echo Dependabot!" | ||
} | ||
} | ||
} | ||
["print"] = new { | ||
`runs-on` = new UbuntuLatest{} | ||
steps { | ||
new RunStep { | ||
name = "Hello World" | ||
run = "echo Hello World" | ||
} | ||
new RunStep { | ||
name = "date" | ||
run = "date" | ||
} | ||
new UsesStep { | ||
name = "Checkout" | ||
uses = "actions/checkout@v4" | ||
with = new { | ||
["ref"] = "develop" | ||
} | ||
} | ||
new UsesStep { | ||
name = "Slack" | ||
id = "Slack" | ||
`if` = "${{ failure() }}" | ||
uses = "slackapi/[email protected]" | ||
with = new { | ||
["payload"] = """ | ||
{ | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": ":alert: Develop is broken!" | ||
} | ||
} | ||
] | ||
} | ||
""" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
amends "../GitHubAction.pkl" | ||
|
||
name = "Update Wiki Readme" | ||
|
||
on { | ||
push { | ||
paths { | ||
"wiki/**" | ||
"!wiki/README.md" | ||
} | ||
} | ||
} | ||
|
||
jobs { | ||
["update-wiki-readme"] { | ||
`runs-on` = new UbuntuLatest{} | ||
steps { | ||
new UsesStep { | ||
uses = "actions/checkout@v4" | ||
} | ||
new UsesStep { | ||
uses = "actions/setup-go@v5" | ||
with { | ||
["go-version"] = "1.17.7" | ||
} | ||
} | ||
new RunStep { | ||
run = "go run wiki/generateWikiToc.go" | ||
} | ||
new RunStep { | ||
name = "Commit changes" | ||
run = """ | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "StefMa" | ||
git add wiki/README.md || echo "No changes to commit" | ||
git commit -m 'Re-build TOC in README.md' || echo "No changes to commit" | ||
git push origin || echo "No changes to commit" | ||
""" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module com.github.GitHubAction.tests | ||
|
||
amends "pkl:test" | ||
|
||
examples { | ||
["basic.pkl"] { | ||
import("../examples/TestWorkflow.pkl").output.text | ||
} | ||
["updateWikiReadme.pkl"] { | ||
import("../examples/UpdateWikiReadme.pkl").output.text | ||
} | ||
} |
Oops, something went wrong.