Skip to content

Commit

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

* Add pre-commit git hook

* Fix setup-node actions

* Fix lint

* Add check-action

* Extract steps to pkl module

* Use pkl properties over functions

* Rename generated yml files

* Fix check-dist diff

* Remove GitHub Actions from dependabot

* Move pkl workflows to pkl-workflows dir

* Inline checkoutAndInstallPkl in action

* Remove bash script and inlineas npm script

* Fix missing quotes

* Update check-actions workflow

* Remove old ci job

* Fix gen:action script

* Fix ci again

* Fix trigger for check actions
  • Loading branch information
StefMa authored Oct 10, 2024
1 parent 060d65f commit 52a5818
Show file tree
Hide file tree
Showing 15 changed files with 438 additions and 200 deletions.
10 changes: 0 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
actions-minor:
update-types:
- minor
- patch

- package-ecosystem: npm
directory: /
schedule:
Expand Down
File renamed without changes.
42 changes: 42 additions & 0 deletions .github/pkl-workflows/check-actions.pkl
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"
}
}
}
}
68 changes: 68 additions & 0 deletions .github/pkl-workflows/check-dist.pkl
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"
}
}
}
}
}
80 changes: 80 additions & 0 deletions .github/pkl-workflows/ci.pkl
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 }}"
"""
}
}
}
}
48 changes: 48 additions & 0 deletions .github/pkl-workflows/linter.pkl
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"
}
}
}
}
}
26 changes: 26 additions & 0 deletions .github/pkl-workflows/modules/Steps.pkl
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
}
33 changes: 33 additions & 0 deletions .github/workflows/check-actions.generated.yml
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:/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
45 changes: 45 additions & 0 deletions .github/workflows/check-dist.generated.yml
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:/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
Loading

0 comments on commit 52a5818

Please sign in to comment.