Skip to content

Commit

Permalink
Extract steps to pkl module
Browse files Browse the repository at this point in the history
  • Loading branch information
StefMa authored Aug 26, 2024
1 parent 53c8236 commit 597812c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 61 deletions.
18 changes: 2 additions & 16 deletions .github/workflows/check-dist.pkl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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
Expand Down Expand Up @@ -29,22 +30,7 @@ jobs {
name = "Check Dist"
`runs-on` = "ubuntu-latest"
steps {
new {
name = "Checkout"
uses = "actions/checkout@v4"
}
new {
name = "Setup Node.js"
uses = "actions/setup-node@v4"
with {
["node-version-file"] = ".nvmrc"
["cache"] = "npm"
}
}
new {
name = "Install Dependencies"
run = "npm ci"
}
...Steps.checkoutAndSetupNode(null)
new {
name = "Build dist/ Directory"
run = "npm run bundle"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
Expand Down
25 changes: 4 additions & 21 deletions .github/workflows/ci.pkl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl"
import "modules/Steps.pkl"

name = "Continuous Integration"

Expand All @@ -20,22 +21,7 @@ jobs {
name = "TypeScript Tests"
`runs-on` = "ubuntu-latest"
steps {
new {
name = "Checkout"
uses = "actions/checkout@v4"
}
new {
name = "Setup Node.js"
uses = "actions/setup-node@v4"
with {
["node-version-file"] = ".nvmrc"
["cache"] = "npm"
}
}
new {
name = "Install Dependencies"
run = "npm ci"
}
...Steps.checkoutAndSetupNode(null)
new {
name = "Check Format"
run = "npm run format:check"
Expand Down Expand Up @@ -63,15 +49,12 @@ jobs {
}
`runs-on` = "${{ matrix.os }}"
steps {
new {
name = "Checkout"
uses = "actions/checkout@v4"
}
Steps.checkout(null)
new {
name = "Test Local Action"
uses = "./"
with {
["pkl-version"] = "0.26.0"
["pkl-version"] = "0.26.3"
}
}
new {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
Expand Down Expand Up @@ -44,6 +44,6 @@ jobs:
- name: Test Local Action
uses: ./
with:
pkl-version: 0.26.0
pkl-version: 0.26.3
- name: Confirm download
run: pkl --version
21 changes: 4 additions & 17 deletions .github/workflows/linter.pkl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl"
import "modules/Steps.pkl"

name = "Lint Codebase"

Expand All @@ -22,25 +23,11 @@ jobs {
name = "Lint Codebase"
`runs-on` = "ubuntu-latest"
steps {
new {
name = "Checkout"
uses = "actions/checkout@v4"
with {
...Steps.checkoutAndSetupNode(
new Mapping<String, String|Number|Boolean> {
["fetch-depth"] = 0
}
}
new {
name = "Setup Node.js"
uses = "actions/setup-node@v4"
with {
["node-version-file"] = ".nvmrc"
["cache"] = "npm"
}
}
new {
name = "Install Dependencies"
run = "npm ci"
}
)
new {
name = "Lint Codebase"
uses = "super-linter/super-linter/slim@v6"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
Expand Down
27 changes: 24 additions & 3 deletions .github/workflows/modules/Steps.pkl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/[email protected]#/GitHubAction.pkl"

function checkout(): GitHubAction.Step = new {
name = "checkout"
function checkout(customWith: Mapping<String, String|Number|Boolean>?): GitHubAction.Step = new {
name = "Checkout"
uses = "actions/checkout@v4"
with = customWith
}

function installPkl(): GitHubAction.Step = new {
Expand All @@ -13,7 +14,27 @@ function installPkl(): GitHubAction.Step = new {
}
}

function installNode(): GitHubAction.Step = new {
name = "Install node"
uses = "actions/setup-node@v4"
with {
["node-version-file"] = ".nvmrc"
["cache"] = "npm"
}
}

function installNodeDeps(): GitHubAction.Step = new {
name = "Install Dependencies"
run = "npm ci"
}

function checkoutAndInstallPkl(): Listing<GitHubAction.Step> = new {
checkout()
checkout(null)
installPkl()
}

function checkoutAndSetupNode(customCheckoutWith: Mapping<String, String|Number|Boolean>?): Listing<GitHubAction.Step> = new {
checkout(customCheckoutWith)
installNode()
installNodeDeps()
}

0 comments on commit 597812c

Please sign in to comment.