generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pkl-gha
for GitHub Action Workflows
#47
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4a99cca
Add pkl GitHub Action Workflows
StefMa 084df68
Add pre-commit git hook
StefMa 4bd66da
Fix setup-node actions
StefMa aeababd
Fix lint
StefMa 53c8236
Add check-action
StefMa 54eb10e
Extract steps to pkl module
StefMa e3b40c3
Use pkl properties over functions
StefMa 95abf43
Rename generated yml files
StefMa cec2d47
Fix check-dist diff
StefMa 7e13d7b
Remove GitHub Actions from dependabot
StefMa ca54c01
Move pkl workflows to pkl-workflows dir
StefMa 26f6b76
Inline checkoutAndInstallPkl in action
StefMa ed98e00
Remove bash script and inlineas npm script
StefMa d222aad
Merge remote-tracking branch 'origin/main' into pkl-gha
StefMa 7aca398
Fix missing quotes
StefMa 7ee2169
Update check-actions workflow
StefMa 71ae10b
Remove old ci job
StefMa b45986c
Fix gen:action script
StefMa 75aba06
Fix ci again
StefMa 3fc3203
Fix trigger for check actions
StefMa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
File renamed without changes.
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 "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" | ||
import "modules/Steps.pkl" | ||
|
||
name = "Check Pkl Actions Converted" | ||
|
||
on { | ||
pull_request {} | ||
push { | ||
branches { | ||
"main" | ||
} | ||
} | ||
} | ||
|
||
permissions { | ||
contents = "read" | ||
} | ||
|
||
jobs { | ||
["check-actions"] { | ||
name = "Check Actions converted" | ||
`runs-on` = "ubuntu-latest" | ||
steps { | ||
...Steps.checkoutAndSetupNode | ||
new { | ||
name = "Install pkl" | ||
uses = "pkl-community/setup-pkl@v0" | ||
with { | ||
["pkl-version"] = "0.26.3" | ||
} | ||
} | ||
new { | ||
name = "Convert pkl actions to yaml" | ||
run = "npm run gen:actions" | ||
} | ||
new { | ||
name = "Verify if pkl actions are converted" | ||
run = "git diff --exit-code" | ||
} | ||
} | ||
} | ||
} |
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,68 @@ | ||
amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" | ||
import "modules/Steps.pkl" | ||
|
||
// In TypeScript actions, `dist/` is a special directory. When you reference | ||
// an action with the `uses:` property, `dist/index.js` is the code that will be | ||
// run. For this project, the `dist/index.js` file is transpiled from other | ||
// source files. This workflow ensures the `dist/` directory contains the | ||
// expected transpiled code. | ||
// | ||
// If this workflow is run from a feature branch, it will act as an additional CI | ||
// check and fail if the checked-in `dist/` directory does not match what is | ||
// expected from the build. | ||
name = "Check Transpiled JavaScript" | ||
|
||
on { | ||
pull_request {} | ||
push { | ||
branches { | ||
"main" | ||
} | ||
} | ||
} | ||
|
||
permissions { | ||
contents = "read" | ||
} | ||
|
||
jobs { | ||
["check-dist"] { | ||
name = "Check Dist" | ||
`runs-on` = "ubuntu-latest" | ||
steps { | ||
...Steps.checkoutAndSetupNode | ||
new { | ||
name = "Install pkl" | ||
uses = "pkl-community/setup-pkl@v0" | ||
with { | ||
["pkl-version"] = "0.26.3" | ||
} | ||
} | ||
new { | ||
name = "Build dist/ Directory" | ||
run = "npm run bundle" | ||
} | ||
// This will fail the workflow if the PR wasn't created by Dependabot. | ||
new { | ||
name = "Compare Directories" | ||
id = "diff" | ||
run = """ | ||
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then | ||
echo "Detected uncommitted changes after build. See status below:" | ||
git diff --ignore-space-at-eol --text dist/ | ||
exit 1 | ||
fi | ||
""" | ||
} | ||
new { | ||
name = "Upload Artifact" | ||
`if` = "${{ failure() && steps.diff.outcome == 'failure' }}" | ||
uses = "actions/upload-artifact@v4" | ||
with { | ||
["name"] = "dist" | ||
["path"] = "dist" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,80 @@ | ||
amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" | ||
import "modules/Steps.pkl" | ||
|
||
name = "Continuous Integration" | ||
|
||
env { | ||
["CHECK_VERSION"] = "0.26.0" | ||
} | ||
|
||
on { | ||
pull_request {} | ||
push { | ||
branches { | ||
"main" | ||
} | ||
} | ||
} | ||
|
||
permissions { | ||
contents = "read" | ||
} | ||
|
||
jobs { | ||
["test-typescript"] { | ||
name = "TypeScript Tests" | ||
`runs-on` = "ubuntu-latest" | ||
steps { | ||
...Steps.checkoutAndSetupNode | ||
new { | ||
name = "Check Format" | ||
run = "npm run format:check" | ||
} | ||
new { | ||
name = "Lint" | ||
run = "npm run lint" | ||
} | ||
new { | ||
name = "Test" | ||
run = "npm run ci-test" | ||
} | ||
} | ||
} | ||
["test-action"] { | ||
strategy { | ||
matrix { | ||
["os"] = new { | ||
"ubuntu-latest" | ||
"macos-13" // macos-13 is amd64 | ||
"macos-14" // macos-14 is aarch64 (M1) | ||
"windows-latest" | ||
} | ||
} | ||
} | ||
`runs-on` = "${{ matrix.os }}" | ||
steps { | ||
Steps.checkout | ||
new { | ||
name = "Test Local Action" | ||
uses = "./" | ||
with { | ||
["pkl-version"] = "${{ env.CHECK_VERSION }}" | ||
} | ||
} | ||
new { | ||
name = "Confirm download (unix)" | ||
`if` = "matrix.os != 'windows-latest'" | ||
run = """ | ||
pkl --version | grep "Pkl ${{ env.CHECK_VERSION }}" | ||
""" | ||
} | ||
new { | ||
name = "Confirm download (windows)" | ||
`if` = "matrix.os == 'windows-latest'" | ||
run = """ | ||
.github/pkl-workflows/Check-Version.ps1 "Pkl ${{ env.CHECK_VERSION }}" | ||
""" | ||
} | ||
} | ||
} | ||
} |
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,48 @@ | ||
amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" | ||
import "modules/Steps.pkl" | ||
|
||
name = "Lint Codebase" | ||
|
||
on { | ||
pull_request {} | ||
push { | ||
branches { | ||
"main" | ||
} | ||
} | ||
} | ||
|
||
permissions { | ||
contents = "read" | ||
packages = "read" | ||
statuses = "write" | ||
} | ||
|
||
jobs { | ||
["test-typescript"] { | ||
name = "Lint Codebase" | ||
`runs-on` = "ubuntu-latest" | ||
steps { | ||
(Steps.checkout) { | ||
with { | ||
["fetch-depth"] = 0 | ||
} | ||
} | ||
Steps.installNode | ||
Steps.installNodeDeps | ||
new { | ||
name = "Lint Codebase" | ||
uses = "super-linter/super-linter/slim@v6" | ||
env { | ||
["DEFAULT_BRANCH"] = "main" | ||
["FILTER_REGEX_EXCLUDE"] = "dist/**/*" | ||
["GITHUB_TOKEN"] = "${{ secrets.GITHUB_TOKEN }}" | ||
["VALIDATE_ALL_CODEBASE"] = "true" | ||
["VALIDATE_JAVASCRIPT_STANDARD"] = "false" | ||
["VALIDATE_JSCPD"] = "false" | ||
["VALIDATE_TYPESCRIPT_STANDARD"] = "false" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,26 @@ | ||
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl" | ||
|
||
checkout: GitHubAction.Step = new { | ||
name = "Checkout" | ||
uses = "actions/checkout@v4" | ||
} | ||
|
||
installNode: GitHubAction.Step = new { | ||
name = "Install node" | ||
uses = "actions/setup-node@v4" | ||
with { | ||
["node-version-file"] = ".nvmrc" | ||
["cache"] = "npm" | ||
} | ||
} | ||
|
||
installNodeDeps: GitHubAction.Step = new { | ||
name = "Install Dependencies" | ||
run = "npm ci" | ||
} | ||
|
||
checkoutAndSetupNode: Listing<GitHubAction.Step> = new { | ||
checkout | ||
installNode | ||
installNodeDeps | ||
} |
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,33 @@ | ||
# Do not modify! | ||
# This file was generated from a template using https://github.com/StefMa/pkl-gha | ||
|
||
name: Check Pkl Actions Converted | ||
'on': | ||
pull_request: {} | ||
push: | ||
branches: | ||
- main | ||
permissions: | ||
contents: read | ||
jobs: | ||
check-actions: | ||
name: Check Actions converted | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Install node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .nvmrc | ||
cache: npm | ||
- name: Install Dependencies | ||
run: npm ci | ||
- name: Install pkl | ||
uses: pkl-community/setup-pkl@v0 | ||
with: | ||
pkl-version: 0.26.3 | ||
- name: Convert pkl actions to yaml | ||
run: npm run gen:actions | ||
- name: Verify if pkl actions are converted | ||
run: git diff --exit-code |
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,45 @@ | ||
# Do not modify! | ||
# This file was generated from a template using https://github.com/StefMa/pkl-gha | ||
|
||
name: Check Transpiled JavaScript | ||
'on': | ||
pull_request: {} | ||
push: | ||
branches: | ||
- main | ||
permissions: | ||
contents: read | ||
jobs: | ||
check-dist: | ||
name: Check Dist | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Install node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: .nvmrc | ||
cache: npm | ||
- name: Install Dependencies | ||
run: npm ci | ||
- name: Install pkl | ||
uses: pkl-community/setup-pkl@v0 | ||
with: | ||
pkl-version: 0.26.3 | ||
- name: Build dist/ Directory | ||
run: npm run bundle | ||
- name: Compare Directories | ||
id: diff | ||
run: |- | ||
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then | ||
echo "Detected uncommitted changes after build. See status below:" | ||
git diff --ignore-space-at-eol --text dist/ | ||
exit 1 | ||
fi | ||
- name: Upload Artifact | ||
if: ${{ failure() && steps.diff.outcome == 'failure' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this has been typed correctly in your base module, you shouldn't need
= new {}
to create a new list, the override syntax["os"] { ... }
should work. The only reason to do that typically with a Listing would be if there are default values in the parent object and you want to "start fresh" with a new Listing. Let me go check the typing in your parent module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at https://github.com/StefMa/pkl-gha/blob/main/GitHubAction.pkl#L592, I think there's extra complexity because
matrix
is typed asListing<String|*Dynamic>
. Can it really be a Dynamic object?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be Dynamic.
See https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-a-multi-dimension-matrix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha - to me that looks more like it could be
Mapping<String, String>
- remember thatDynamic
can contain properties, entries, AND elements, eg:Note that this is actually not representable in JSON or YAML at all (below is from the REPL):
But that's an aside, not important to this PR. Just info for you and your library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint!
Do you now how I could model this better/differently? 🤔