Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions GitHubAction.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,19 @@ permissions: (*Permissions|"read-all"|"write-all")?
jobs: Jobs

// Output
local jsonRenderer = new JsonRenderer {}
local baseHeaderComment = "# Do not modify!\n# This file was generated from a template using https://github.com/StefMa/pkl-gha"
headerComment: String? = null
local finalHeaderComment: String = if (headerComment != null) "\(headerComment)\n\n" + baseHeaderComment else baseHeaderComment
output {
text = "# Do not modify!\n# This file was generated from a template using https://github.com/StefMa/pkl-gha\n\n\(super.text)"
text = "\(finalHeaderComment)\n\n\(super.text)"
renderer = new YamlRenderer {
converters {
["runs-on"] = (runsOn: String|Machine|Listing<String|Machine>) ->
if (runsOn is Listing<String|Machine>) convertMachinesToString(runsOn) else convertMachineToString(runsOn)
["schedule"] = (schedule: Schedule?) -> schedule.ifNonNull((_) ->
schedule.cron.toList().map((cr) -> Map("cron", new RenderDirective { text = " " + jsonRenderer.renderValue(cr) }))
schedule.cron.toList().map((cr) -> Map("cron", new RenderDirective { text = " " + new JsonRenderer {}.renderValue(cr) }))
)
["headerComment"] = (headerComment: String?) -> null
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions examples/HeaderComment.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
amends "../GitHubAction.pkl"

headerComment = """
# SPDX-FileCopyrightText: Copyright line here
#
# SPDX-License-Identifier: License here
"""

name = "Custom header comment"

on {
push {
branches {
"main"
}
}
}

jobs {
["headerComment"] {
`runs-on` = "ubuntu-latest"
steps {
new {
uses = "actions/checkout@v4"
}
new {
run = "echo Hello World"
}
}
}
}
3 changes: 3 additions & 0 deletions tests/GitHubAction.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ examples {
["reusableWorkflow"] {
import("../examples/ReusableWorkflow.pkl").output.text
}
["headerComment"] {
import("../examples/HeaderComment.pkl").output.text
}
}

facts {
Expand Down
23 changes: 23 additions & 0 deletions tests/GitHubAction.pkl-expected.pcf
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,27 @@ examples {

"""
}
["headerComment"] {
"""
# SPDX-FileCopyrightText: Copyright line here
#
# SPDX-License-Identifier: License here

# Do not modify!
# This file was generated from a template using https://github.com/StefMa/pkl-gha

name: Custom header comment
'on':
push:
branches:
- main
jobs:
headerComment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo Hello World

"""
}
}