diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 742ec57..96e100e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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: diff --git a/.github/workflows/Check-Version.ps1 b/.github/pkl-workflows/Check-Version.ps1 similarity index 100% rename from .github/workflows/Check-Version.ps1 rename to .github/pkl-workflows/Check-Version.ps1 diff --git a/.github/pkl-workflows/check-actions.pkl b/.github/pkl-workflows/check-actions.pkl new file mode 100644 index 0000000..543f38b --- /dev/null +++ b/.github/pkl-workflows/check-actions.pkl @@ -0,0 +1,42 @@ +amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.3#/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" + } + } + } +} \ No newline at end of file diff --git a/.github/pkl-workflows/check-dist.pkl b/.github/pkl-workflows/check-dist.pkl new file mode 100644 index 0000000..f9394f9 --- /dev/null +++ b/.github/pkl-workflows/check-dist.pkl @@ -0,0 +1,68 @@ +amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.3#/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" + } + } + } + } +} \ No newline at end of file diff --git a/.github/pkl-workflows/ci.pkl b/.github/pkl-workflows/ci.pkl new file mode 100644 index 0000000..d365cc9 --- /dev/null +++ b/.github/pkl-workflows/ci.pkl @@ -0,0 +1,80 @@ +amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.3#/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 }}" + """ + } + } + } +} diff --git a/.github/pkl-workflows/linter.pkl b/.github/pkl-workflows/linter.pkl new file mode 100644 index 0000000..39fd0ff --- /dev/null +++ b/.github/pkl-workflows/linter.pkl @@ -0,0 +1,48 @@ +amends "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.3#/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" + } + } + } + } +} \ No newline at end of file diff --git a/.github/pkl-workflows/modules/Steps.pkl b/.github/pkl-workflows/modules/Steps.pkl new file mode 100644 index 0000000..65c6087 --- /dev/null +++ b/.github/pkl-workflows/modules/Steps.pkl @@ -0,0 +1,26 @@ +import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.3#/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 = new { + checkout + installNode + installNodeDeps +} \ No newline at end of file diff --git a/.github/workflows/check-actions.generated.yml b/.github/workflows/check-actions.generated.yml new file mode 100644 index 0000000..0b2fecf --- /dev/null +++ b/.github/workflows/check-actions.generated.yml @@ -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 diff --git a/.github/workflows/check-dist.generated.yml b/.github/workflows/check-dist.generated.yml new file mode 100644 index 0000000..7dec5cb --- /dev/null +++ b/.github/workflows/check-dist.generated.yml @@ -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 diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml deleted file mode 100644 index 1383744..0000000 --- a/.github/workflows/check-dist.yml +++ /dev/null @@ -1,66 +0,0 @@ -# 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: - branches: - - main - push: - branches: - - main - -permissions: - contents: read - -jobs: - check-dist: - name: Check dist/ - runs-on: ubuntu-latest - - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v4 - - - name: Setup Node.js - id: setup-node - uses: actions/setup-node@v4 - with: - node-version-file: .nvmrc - cache: npm - - - name: Install Dependencies - id: install - run: npm ci - - - name: Build dist/ Directory - id: build - run: npm run bundle - - # This will fail the workflow if the PR wasn't created by Dependabot. - - 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 - - # If `dist/` was different than expected, and this was not a Dependabot - # PR, upload the expected version as a workflow artifact. - - if: ${{ failure() && steps.diff.outcome == 'failure' }} - name: Upload Artifact - id: upload - uses: actions/upload-artifact@v4 - with: - name: dist - path: dist/ diff --git a/.github/workflows/ci.generated.yml b/.github/workflows/ci.generated.yml new file mode 100644 index 0000000..34a9aa7 --- /dev/null +++ b/.github/workflows/ci.generated.yml @@ -0,0 +1,55 @@ +# Do not modify! +# This file was generated from a template using https://github.com/StefMa/pkl-gha + +name: Continuous Integration +'on': + pull_request: {} + push: + branches: + - main +env: + CHECK_VERSION: 0.26.0 +permissions: + contents: read +jobs: + test-typescript: + name: TypeScript Tests + 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: Check Format + run: npm run format:check + - name: Lint + run: npm run lint + - name: Test + run: npm run ci-test + test-action: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-13 + - macos-14 + - windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test Local Action + uses: ./ + with: + pkl-version: ${{ env.CHECK_VERSION }} + - name: Confirm download (unix) + if: matrix.os != 'windows-latest' + run: pkl --version | grep "Pkl ${{ env.CHECK_VERSION }}" + - name: Confirm download (windows) + if: matrix.os == 'windows-latest' + run: .github/pkl-workflows/Check-Version.ps1 "Pkl ${{ env.CHECK_VERSION }}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 19250e8..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Continuous Integration - -on: - pull_request: - branches: - - main - push: - branches: - - main - -permissions: - contents: read - -env: - CHECK_VERSION: 0.26.0 - -jobs: - test-typescript: - name: TypeScript Tests - runs-on: ubuntu-latest - - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v4 - - - name: Setup Node.js - id: setup-node - uses: actions/setup-node@v4 - with: - node-version-file: .nvmrc - cache: npm - - - name: Install Dependencies - id: npm-ci - run: npm ci - - - name: Check Format - id: npm-format-check - run: npm run format:check - - - name: Lint - id: npm-lint - run: npm run lint - - - name: Test - id: npm-ci-test - run: npm run ci-test - - test-action: - strategy: - matrix: - # Right now macos-13 is amd64 while macos-14 is aarch64 (M1) - os: [ubuntu-latest, macos-13, macos-14, windows-latest] - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v4 - - - name: Test Local Action - id: test-action - uses: ./ - with: - pkl-version: ${{ env.CHECK_VERSION }} - - - name: Confirm download (unix) - run: pkl --version | grep "Pkl ${{ env.CHECK_VERSION }}" - if: matrix.os != 'windows-latest' - - - name: Confirm download (windows) - run: .github/workflows/Check-Version.ps1 "Pkl ${{ env.CHECK_VERSION }}" - if: matrix.os == 'windows-latest' diff --git a/.github/workflows/linter.generated.yml b/.github/workflows/linter.generated.yml new file mode 100644 index 0000000..b66fac5 --- /dev/null +++ b/.github/workflows/linter.generated.yml @@ -0,0 +1,39 @@ +# Do not modify! +# This file was generated from a template using https://github.com/StefMa/pkl-gha + +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: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install node + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: npm + - name: Install Dependencies + run: npm ci + - name: Lint Codebase + 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' + uses: super-linter/super-linter/slim@v6 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml deleted file mode 100644 index 8628e3c..0000000 --- a/.github/workflows/linter.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Lint Codebase - -on: - pull_request: - branches: - - main - push: - branches: - - main - -permissions: - contents: read - packages: read - statuses: write - -jobs: - lint: - name: Lint Codebase - runs-on: ubuntu-latest - - steps: - - name: Checkout - id: checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Node.js - id: setup-node - uses: actions/setup-node@v4 - with: - node-version-file: .nvmrc - cache: npm - - - name: Install Dependencies - id: install - run: npm ci - - - name: Lint Codebase - id: super-linter - uses: super-linter/super-linter/slim@v7 - 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 diff --git a/package.json b/package.json index 498e7e7..3479585 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,9 @@ "coverage": "make-coverage-badge --output-path ./badges/coverage.svg", "format:write": "prettier --write **/*.ts", "format:check": "prettier --check **/*.ts", + "gen:actions": "pkl eval .github/pkl-workflows/*.pkl -o \".github/workflows/%{moduleName}.generated.yml\"", "lint": "npx eslint . -c ./.github/linters/.eslintrc.yml", - "package": "ncc build src/index.ts --license licenses.txt", + "package": "ncc build src/index.ts --license licenses.txt && npm run gen:actions", "package:watch": "npm run package -- --watch", "test": "jest", "all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package"