diff --git a/.github/matchers/actionlint.json b/.github/matchers/actionlint.json new file mode 100644 index 0000000..4613e16 --- /dev/null +++ b/.github/matchers/actionlint.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "actionlint", + "pattern": [ + { + "regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$", + "file": 1, + "line": 2, + "column": 3, + "message": 4, + "code": 5 + } + ] + } + ] +} diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..ce2adaf --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,46 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "baseBranches": ["main"], + "timezone": "Europe/Lisbon", + "schedule": ["before 9pm on sunday"], + "extends": [":dependencyDashboard", ":disableRateLimiting", ":semanticCommits"], + "rangeStrategy": "pin", + "enabledManagers": ["github-actions", "regex", "npm"], + "commitMessageAction": "", + "commitMessageTopic": "{{depName}}", + "commitMessageExtra": "{{#if isPinDigest}}{{{newDigestShort}}}{{else}}{{#if isMajor}}{{prettyNewMajor}}{{else}}{{#if isSingleVersion}}{{prettyNewVersion}}{{else}}{{#if newValue}}{{{newValue}}}{{else}}{{{newDigestShort}}}{{/if}}{{/if}}{{/if}}{{/if}}", + "packageRules": [ + { + "matchManagers": ["github-actions"], + "commitMessageTopic": "{{depName}}" + }, + { + "matchPackagePatterns": ["actionlint"], + "commitMessageTopic": "actionlint" + }, + { + "matchPackagePatterns": ["typos"], + "commitMessageTopic": "typos" + }, + { + "matchPackagePatterns": ["bun"], + "rangeStrategy": "in-range-only" + } + ], + "regexManagers": [ + { + "fileMatch": ["^\\.github/workflows/[^/]+\\.yml$"], + "matchStrings": [ + "version: \"(?.*?)\"\\s+run: curl -Ls( -o \\w+)? \"https://github.com/(?.*?)/releases/download.*", + "https://github\\.com/(?.*?)/archive/refs/tags/v(?.*?)\\.tar\\.gz" + ], + "datasourceTemplate": "github-releases", + "extractVersionTemplate": "^v(?.*)$" + } + ], + "rebaseWhen": "never", + "labels": ["type: dependencies"], + "prBodyTemplate": "{{{header}}}{{{table}}}{{{notes}}}{{{changelogs}}}{{{controls}}}{{{footer}}}", + "prHeader": "", + "prFooter": "" +} diff --git a/.github/workflows/test-bun.yml b/.github/workflows/test-bun.yml new file mode 100644 index 0000000..cc8046a --- /dev/null +++ b/.github/workflows/test-bun.yml @@ -0,0 +1,18 @@ +name: Bun +on: + pull_request: + paths: + - "**/*.ts" + +jobs: + bun-test: + name: Test + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + - run: bun install + + - name: Run tests + run: bun test diff --git a/.github/workflows/validate-actions.yml b/.github/workflows/validate-actions.yml new file mode 100644 index 0000000..6bba13f --- /dev/null +++ b/.github/workflows/validate-actions.yml @@ -0,0 +1,22 @@ +name: Github Actions +on: + pull_request: + paths: + - ".github/workflows/*.yml" + +jobs: + actionlint: + name: Validate + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - name: Install Actionlint + env: + version: "1.7.1" + run: curl -Ls "https://github.com/rhysd/actionlint/releases/download/v${{ env.version }}/actionlint_${{ env.version }}_linux_amd64.tar.gz" | sudo tar -x -z -C /usr/local/bin actionlint + + - name: Run Actionlint + run: | + echo "::add-matcher::.github/matchers/actionlint.json" + actionlint -color diff --git a/.github/workflows/validate-biome.yml b/.github/workflows/validate-biome.yml new file mode 100644 index 0000000..79855b1 --- /dev/null +++ b/.github/workflows/validate-biome.yml @@ -0,0 +1,20 @@ +name: Biome +on: + pull_request: + paths: + - "**/*.ts" + - "**/*.json" + +jobs: + biome: + name: Lint and format + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: biomejs/setup-biome@v2 + + - name: Run Biome + run: biome ci diff --git a/.github/workflows/validate-convco.yml b/.github/workflows/validate-convco.yml index c6ecfd6..8ee7366 100644 --- a/.github/workflows/validate-convco.yml +++ b/.github/workflows/validate-convco.yml @@ -1,4 +1,4 @@ -name: "Conventional Commits" +name: Conventional Commits on: pull_request: types: diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml new file mode 100644 index 0000000..2eead2c --- /dev/null +++ b/.github/workflows/validate-renovate.yml @@ -0,0 +1,19 @@ +name: Renovate +on: + pull_request: + paths: + - ".github/workflows/validate-renovate.yml" + - ".github/renovate.json" + +jobs: + validate-renovate-config: + name: Validate config + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + - run: bun install -g renovate + + - name: Validate config + run: renovate-config-validator .github/renovate.json diff --git a/.github/workflows/validate-typos.yml b/.github/workflows/validate-typos.yml new file mode 100644 index 0000000..60b8231 --- /dev/null +++ b/.github/workflows/validate-typos.yml @@ -0,0 +1,15 @@ +name: Typos +on: + pull_request: + paths: + - "**/*.md" + +jobs: + typos: + name: Check for language typos + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + # No major tag unfortunately + # https://github.com/crate-ci/typos/issues/857 + - uses: crate-ci/typos@v1.23.2 diff --git a/.lefthook.toml b/.lefthook.toml index 2aadadf..bb0a1a4 100644 --- a/.lefthook.toml +++ b/.lefthook.toml @@ -14,3 +14,7 @@ run = "bun test" [pre-commit.commands.typos] glob = "*.{md,mdoc,mdx}" run = "typos {staged_files}" + +[pre-commit.commands.actionlint] +glob = ".github/workflows/*.yml" +run = "actionlint {staged_files}" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1246505..7709984 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,11 +39,11 @@ are more sensitive, emailed to . To install Topsort.js as a contributor, you need to have Bun installed on your machine. Follow the instructions on the [Bun website](https://bun.sh/) to install it. -You will also need [typos][https://github.com/crate-ci/typos] for validating documentation. Install it through your package manager (on MacOS: `brew install typos-cli`) +You will also need [typos](https://github.com/crate-ci/typos) for validating documentation and [actionlint](https://github.com/rhysd/actionlint) for validating actions. Install it through your package manager of choice (on MacOS: `brew install typos-cli actionlint`). Clone the repository and install the dependencies: -```sh +```bash git clone git@github.com:Topsort/topsort.js.git cd topsort.js bun install @@ -54,6 +54,7 @@ bun install In order to run a local application and test it against the local Topsort.js you need to do the following (after having the SDK all set up on local machine): On Topsort.js: + ```bash bun run build bun link @@ -62,11 +63,14 @@ bun link This will register a local `topsort.js` to be used on the secondary project. On the secondary project, if using bun, run: + ```bash bun link topsort.js ``` + Or add it in dependencies in the package.json file: -```sh + +```bash "topsort.js": "link:topsort.js" ``` @@ -74,7 +78,7 @@ Or add it in dependencies in the package.json file: To build the SDK, run the following command: -```sh +```bash bun run build ``` @@ -86,19 +90,21 @@ This command cleans the `dist` directory and compiles the Typescript files into To run the unit tests, use the following command: -```sh +```bash bun run test ``` ## Code Standards We follow the coding standards set by Biome. Ensure your code follows these guidelines before submitting a pull request. You can run the formatter with the following command: -```sh + +```bash bun run format ``` To automatically fix issues: -```sh + +```bash bun run format:fix ``` @@ -116,10 +122,8 @@ We do conventional commits, so it will fail on checker with capital case after c ## Configuration The SDK uses following configuration files: - -`tsconfig.json`: TypeScript configuration. - -`tsup.config.ts`: Configuration for the TSUP bundler. +- `tsconfig.json`: TypeScript configuration. +- `tsup.config.ts`: Configuration for the TSUP bundler. ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details. diff --git a/biome.json b/biome.json index 83b42d5..0509181 100644 --- a/biome.json +++ b/biome.json @@ -12,12 +12,18 @@ } }, "formatter": { + "enabled": true, "formatWithErrors": true, "indentStyle": "space", - "enabled": true, "lineWidth": 100 }, "linter": { "enabled": true + }, + "vcs": { + "enabled": true, + "clientKind": "git", + "defaultBranch": "main", + "useIgnoreFile": true } } diff --git a/test/validate-config.test.ts b/test/validate-config.test.ts index b3b32f7..7267ebc 100644 --- a/test/validate-config.test.ts +++ b/test/validate-config.test.ts @@ -1,8 +1,7 @@ - import { describe, expect, it } from "bun:test"; +import AppError from "../src/lib/app-error"; import { validateConfig } from "../src/lib/validate-config"; import type { Config } from "../src/types/shared"; -import AppError from "../src/lib/app-error"; describe("validateConfig", () => { it("should throw an error if apiKey is missing", () => {