diff --git a/.github/workflows/debtlint.yml b/.github/workflows/debtlint.yml new file mode 100644 index 0000000..9aadf9a --- /dev/null +++ b/.github/workflows/debtlint.yml @@ -0,0 +1,17 @@ +name: Check duplication + +on: + pull_request: + branches: [ "main" ] + +jobs: + debtlint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Run debtlint + uses: ./action + with: + files: "src" \ No newline at end of file diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 60577bf..24e35f7 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -2,7 +2,7 @@ name: Quality on: pull_request: - branches: [ "main" ] + branches: [ "test" ] jobs: check_quality: diff --git a/Cargo.lock b/Cargo.lock index c0e2156..37893b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,9 +54,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.6.1" +version = "4.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" +checksum = "0fb99565819980999fb7b4a1796046a5c949e6d4ff132cf5fadf5a641e20d776" dependencies = [ "clap_builder", "clap_derive", @@ -64,9 +64,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.6.0" +version = "4.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +checksum = "f09628afdcc538b57f3c6341e9c8e9970f18e4a481690a64974d7023bd33548b" dependencies = [ "anstream", "anstyle", @@ -76,14 +76,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.6.1" +version = "4.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" +checksum = "32f2392eae7f16557a3d727ef3a12e57b2b2ca6f98566a5f4fb41ffe305df077" dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.119", ] [[package]] @@ -127,9 +127,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "memchr" -version = "2.8.2" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "once_cell_polyfill" @@ -139,27 +139,27 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "proc-macro2" -version = "1.0.106" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.45" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" dependencies = [ "proc-macro2", ] [[package]] name = "serde" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" dependencies = [ "serde_core", "serde_derive", @@ -167,29 +167,29 @@ dependencies = [ [[package]] name = "serde_core" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.2", ] [[package]] name = "serde_json" -version = "1.0.150" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" dependencies = [ "itoa", "memchr", @@ -206,9 +206,20 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.117" +version = "2.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a207d6d6a2b7fc470b80443726053f18a2481b7e1eee970597051596567987a3" dependencies = [ "proc-macro2", "quote", @@ -244,6 +255,6 @@ dependencies = [ [[package]] name = "zmij" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/action/.gitignore b/action/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/action/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/action/README.md b/action/README.md new file mode 100644 index 0000000..750219d --- /dev/null +++ b/action/README.md @@ -0,0 +1,10 @@ +# Debtlint action + +This action download and run the [debtlint tools](https://github.com/PoCInnovation/Debtlint). + + +## Inputs + +**Required** + +## Outputs \ No newline at end of file diff --git a/action/action.yml b/action/action.yml new file mode 100644 index 0000000..db6b0d5 --- /dev/null +++ b/action/action.yml @@ -0,0 +1,30 @@ +name: debtlint +description: Identifies repeated or near-duplicate code segments across a codebase. +author: poc-innovation +branding: + icon: "check-circle" + color: "green" + +inputs: + files: + required: false + +runs: + using: composite + steps: + + - name: Install debtlint + shell: sh + run: cargo install debtlint + + - name: Install dependencies + shell: sh + run: npm install + working-directory: ./action + + + - name: Run debtlint + shell: sh + env: + GITHUB_TOKEN: ${{ github.token }} + run: node ${{ github.action_path }}/index.js \ No newline at end of file diff --git a/action/index.js b/action/index.js new file mode 100644 index 0000000..ebb2c48 --- /dev/null +++ b/action/index.js @@ -0,0 +1 @@ +import './src/debtlint.js'; \ No newline at end of file diff --git a/action/package-lock.json b/action/package-lock.json new file mode 100644 index 0000000..add6874 --- /dev/null +++ b/action/package-lock.json @@ -0,0 +1,324 @@ +{ + "name": "action", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "action", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@actions/core": "^3.0.1", + "@actions/github": "^9.1.1", + "@octokit/action": "^8.0.4", + "zod": "^4.4.3" + }, + "devDependencies": { + "@types/node": "^26.1.1" + } + }, + "node_modules/@actions/core": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.1.tgz", + "integrity": "sha512-a6d/Nwahm9fliVGRhdhofo40HjHQasUPusmc7vBfyky+7Z+P2A1J68zyFVaNcEclc/Se+eO595oAr5nwEIoIUA==", + "license": "MIT", + "dependencies": { + "@actions/exec": "^3.0.0", + "@actions/http-client": "^4.0.0" + } + }, + "node_modules/@actions/exec": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz", + "integrity": "sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==", + "license": "MIT", + "dependencies": { + "@actions/io": "^3.0.2" + } + }, + "node_modules/@actions/github": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-9.1.1.tgz", + "integrity": "sha512-tL5JbYOBZHc0ngEnCsaDcryUizIUIlQyIMwy1Wkx93H5HzbBJ7TbiPx2PnFjBwZW0Vh05JmfFZhecE6gglYegA==", + "license": "MIT", + "dependencies": { + "@actions/http-client": "^3.0.2", + "@octokit/core": "^7.0.6", + "@octokit/plugin-paginate-rest": "^14.0.0", + "@octokit/plugin-rest-endpoint-methods": "^17.0.0", + "@octokit/request": "^10.0.7", + "@octokit/request-error": "^7.1.0", + "undici": "^6.23.0" + } + }, + "node_modules/@actions/github/node_modules/@actions/http-client": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.2.tgz", + "integrity": "sha512-JP38FYYpyqvUsz+Igqlc/JG6YO9PaKuvqjM3iGvaLqFnJ7TFmcLyy2IDrY0bI0qCQug8E9K+elv5ZNfw62ZJzA==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^6.23.0" + } + }, + "node_modules/@actions/http-client": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.1.tgz", + "integrity": "sha512-+Nvd1ImaOZBSoPbsUtEhv+1z99H12xzncCkz0a3RuehINE81FZSe2QTj3uvAPTcJX/SCzUQHQ0D1GrPMbrPitg==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^6.23.0" + } + }, + "node_modules/@actions/io": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz", + "integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==", + "license": "MIT" + }, + "node_modules/@octokit/action": { + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/@octokit/action/-/action-8.0.4.tgz", + "integrity": "sha512-1qFYTCrShafc5fQaEbLNUo4xIi/nf98R8iAcJ0ITTCfoRnei9g5Ss9kGkN2tOA7gBlI4HB08Seub4navWXSSbg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-action": "^6.0.2", + "@octokit/core": "^7.0.6", + "@octokit/plugin-paginate-rest": "^14.0.0", + "@octokit/plugin-rest-endpoint-methods": "^17.0.0", + "@octokit/types": "^16.0.0", + "undici": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/action/node_modules/undici": { + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.28.0.tgz", + "integrity": "sha512-cRZYrTDwWznlnRiPjggAGxZXanty6M8RV1ff8Wm4LWXBp7/IG8v5DnOm74DtUBp9OONpK75YlPnIjQqX0dBDtA==", + "license": "MIT", + "engines": { + "node": ">=20.18.1" + } + }, + "node_modules/@octokit/auth-action": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-6.0.2.tgz", + "integrity": "sha512-gEBsz0QioHOMoEU7u2VMr2FfOvfJCrGc42K9rliS7LnlZJLcEMFccIiCiPpPNH+yXs7YYNKQ7lOX67ZTWn6Ysg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-token": "^6.0.0", + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/auth-token": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-6.0.0.tgz", + "integrity": "sha512-P4YJBPdPSpWTQ1NU4XYdvHvXJJDxM6YwpS0FZHRgP7YFkdVxsWcpWGy/NVqlAA7PcPCnMacXlRm1y2PFZRWL/w==", + "license": "MIT", + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/core": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-7.0.6.tgz", + "integrity": "sha512-DhGl4xMVFGVIyMwswXeyzdL4uXD5OGILGX5N8Y+f6W7LhC1Ze2poSNrkF/fedpVDHEEZ+PHFW0vL14I+mm8K3Q==", + "license": "MIT", + "dependencies": { + "@octokit/auth-token": "^6.0.0", + "@octokit/graphql": "^9.0.3", + "@octokit/request": "^10.0.6", + "@octokit/request-error": "^7.0.2", + "@octokit/types": "^16.0.0", + "before-after-hook": "^4.0.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/endpoint": { + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-11.0.3.tgz", + "integrity": "sha512-FWFlNxghg4HrXkD3ifYbS/IdL/mDHjh9QcsNyhQjN8dplUoZbejsdpmuqdA76nxj2xoWPs7p8uX2SNr9rYu0Ag==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/graphql": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-9.0.3.tgz", + "integrity": "sha512-grAEuupr/C1rALFnXTv6ZQhFuL1D8G5y8CN04RgrO4FIPMrtm+mcZzFG7dcBm+nq+1ppNixu+Jd78aeJOYxlGA==", + "license": "MIT", + "dependencies": { + "@octokit/request": "^10.0.6", + "@octokit/types": "^16.0.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "27.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-27.0.0.tgz", + "integrity": "sha512-whrdktVs1h6gtR+09+QsNk2+FO+49j6ga1c55YZudfEG+oKJVvJLQi3zkOm5JjiUXAagWK2tI2kTGKJ2Ys7MGA==", + "license": "MIT" + }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-14.0.0.tgz", + "integrity": "sha512-fNVRE7ufJiAA3XUrha2omTA39M6IXIc6GIZLvlbsm8QOQCYvpq/LkMNGyFlB1d8hTDzsAXa3OKtybdMAYsV/fw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-17.0.0.tgz", + "integrity": "sha512-B5yCyIlOJFPqUUeiD0cnBJwWJO8lkJs5d8+ze9QDP6SvfiXSz1BF+91+0MeI1d2yxgOhU/O+CvtiZ9jSkHhFAw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/request": { + "version": "10.0.11", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-10.0.11.tgz", + "integrity": "sha512-+s7HUxjfFqOMS9VlIwDffq0MikjSAK0gSpG73W+meAvVAvX4MBrHYTK5Bj3Uot55qFT4gzUtfzE4mGWY4Br8/Q==", + "license": "MIT", + "dependencies": { + "@octokit/endpoint": "^11.0.3", + "@octokit/request-error": "^7.0.2", + "@octokit/types": "^16.0.0", + "content-type": "^2.0.0", + "json-with-bigint": "^3.5.3", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/request-error": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-7.1.0.tgz", + "integrity": "sha512-KMQIfq5sOPpkQYajXHwnhjCC0slzCNScLHs9JafXc4RAJI+9f+jNDlBNaIMTvazOPLgb4BnlhGJOTbnN0wIjPw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/types": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-16.0.0.tgz", + "integrity": "sha512-sKq+9r1Mm4efXW1FCk7hFSeJo4QKreL/tTbR0rz/qx/r1Oa2VV83LTA/H/MuCOX7uCIJmQVRKBcbmWoySjAnSg==", + "license": "MIT", + "dependencies": { + "@octokit/openapi-types": "^27.0.0" + } + }, + "node_modules/@types/node": { + "version": "26.1.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.1.1.tgz", + "integrity": "sha512-nxAkRSVkN1Y0JC1W8ky/fTfkGsMmcrRsbx+3XoZE+rMOX71kLYTV7fLXpqud1GpbpP5TuffXFqfX7fH2GgZREw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~8.3.0" + } + }, + "node_modules/before-after-hook": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz", + "integrity": "sha512-q6tR3RPqIB1pMiTRMFcZwuG5T8vwp+vUvEG0vuI6B+Rikh5BfPp2fQ82c925FOs+b0lcFQ8CFrL+KbilfZFhOQ==", + "license": "Apache-2.0" + }, + "node_modules/content-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz", + "integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/json-with-bigint": { + "version": "3.5.10", + "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.5.10.tgz", + "integrity": "sha512-Vcx+JVNEBts/xfcoCS69sKrOhOk/3TVlvlT+XzUOefVKnnrbYSCKpDCm10pohsJFtsJVYnwa/cXRZ4eElzaM6w==", + "license": "MIT" + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "license": "MIT", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/undici": { + "version": "6.27.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", + "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, + "node_modules/undici-types": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz", + "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/universal-user-agent": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.3.tgz", + "integrity": "sha512-TmnEAEAsBJVZM/AADELsK76llnwcf9vMKuPz8JflO1frO8Lchitr0fNaN9d+Ap0BjKtqWqd/J17qeDnXh8CL2A==", + "license": "ISC" + }, + "node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + } + } +} diff --git a/action/package.json b/action/package.json new file mode 100644 index 0000000..2c5876d --- /dev/null +++ b/action/package.json @@ -0,0 +1,22 @@ +{ + "name": "action", + "version": "1.0.0", + "description": "This action download and run the [debtlint tools](https://github.com/PoCInnovation/Debtlint).", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "module", + "dependencies": { + "@actions/core": "^3.0.1", + "@actions/github": "^9.1.1", + "@octokit/action": "^8.0.4", + "zod": "^4.4.3" + }, + "devDependencies": { + "@types/node": "^26.1.1" + } +} diff --git a/action/src/debtlint.js b/action/src/debtlint.js new file mode 100644 index 0000000..95b0888 --- /dev/null +++ b/action/src/debtlint.js @@ -0,0 +1,60 @@ +import * as core from '@actions/core'; +import * as github from '@actions/github'; +import { Octokit } from '@octokit/action'; +import { spawn } from 'child_process'; + +import { diagnosticSchema } from './schemas.js'; + +const octokit = new Octokit(); + +/** + * Execute a command in a child process te + * @param {string} cmd + * @param {string[]} args + * @returns {Promise} + */ +const execCommand = (cmd, args = []) => { + return new Promise((resolve, reject) => { + const process = spawn(cmd, args); + let output = "" + let errorOutput = "" + + process.stdout.on('data', (data) => { + output += data.toString(); + }); + + process.stderr.on('data', (data) => { + errorOutput += data.toString(); + }); + + process.on('close', (code) => { + if (code !== 0) { + return reject(new Error(`Process exited with code ${code}: ${errorOutput}`)); + } + resolve(output); + }); + + process.on('error', reject); + }); +}; + +const rawOutput = await execCommand('cargo', ['run', 'main.rs']); +const diagnostic = diagnosticSchema.parse(JSON.parse(rawOutput)); + +const range = diagnostic.ranges[0]; + +await octokit.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', { + owner: github.context.repo.owner, + repo: github.context.repo.repo, + pull_number: github.context.payload.pull_request.number, + body: diagnostic.code_description, + commit_id: github.context.payload.pull_request.head.sha, + path: diagnostic.source, + start_line: range.start.line, + start_side: 'RIGHT', + line: range.end.line, + side: 'RIGHT', + headers: { + 'X-GitHub-Api-Version': '2026-03-10', + }, +}); \ No newline at end of file diff --git a/action/src/schemas.js b/action/src/schemas.js new file mode 100644 index 0000000..af12006 --- /dev/null +++ b/action/src/schemas.js @@ -0,0 +1,19 @@ +import { z } from "zod"; + +const positionSchema = z.object({ + line: z.number().min(0), + character: z.number().min(0), +}); + +const rangeSchema = z.object({ + start: positionSchema, + end: positionSchema, +}); + +export const diagnosticSchema = z.object({ + source: z.string(), + severity: z.string(), + code: z.number().min(0) , + ranges: z.array(rangeSchema), + codeDescription: z.string().optional(), +}) diff --git a/src/debug_run.rs b/src/debug_run.rs index 945b69a..777ba71 100644 --- a/src/debug_run.rs +++ b/src/debug_run.rs @@ -1,9 +1,21 @@ use debtlint::in_out::{read_corpus, save_vocabulary, write_encoded_sequence_json}; use debtlint::pipeline::{BpeConfig, run_bpe}; use debtlint::tokenizer::{BASE_VOCAB_SIZE, SourceFile, decode_sequence}; +use debtlint::linter::{get_duplicated}; use crate::cli::Args; +use serde_json; + +pub fn run_linter() -> std::io::Result<()> { + let diagnostic = get_duplicated(); + match serde_json::to_string(&diagnostic) { + Ok(data) => { println!("{}", data); Ok(()) }, + Err(err) => { println!("Error: {}", err); Err(std::io::Error::new(std::io::ErrorKind::Other, err)) } + } +} + +#[allow(dead_code)] pub fn run(args: &Args) -> std::io::Result<()> { let content = read_corpus(&args.file)?; let files = vec![SourceFile { @@ -30,6 +42,7 @@ pub fn run(args: &Args) -> std::io::Result<()> { Ok(()) } +#[allow(dead_code)] fn print_stats(result: &debtlint::tokenizer::BpeTrainingResult, content: &str, args: &Args) { let initial_tokens = result.initial_token_count; let encoded_tokens = result.encoded_token_count(); @@ -59,6 +72,7 @@ fn print_stats(result: &debtlint::tokenizer::BpeTrainingResult, content: &str, a ); } +#[allow(dead_code)] fn verify_decode_roundtrip( args: &Args, files: &[SourceFile], diff --git a/src/lib.rs b/src/lib.rs index 7d0b318..584e63b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod in_out; pub mod pipeline; pub mod tokenizer; +pub mod linter; \ No newline at end of file diff --git a/src/linter/diagnostic.rs b/src/linter/diagnostic.rs new file mode 100644 index 0000000..2edee5e --- /dev/null +++ b/src/linter/diagnostic.rs @@ -0,0 +1,24 @@ +use serde::Serialize; + + + +#[derive(Serialize, Debug)] +pub struct Position { + pub line: u32, + pub character: u32 +} + +#[derive(Serialize, Debug)] +pub struct Range { + pub start: Position, + pub end: Position +} + +#[derive(Serialize, Debug)] +pub struct Diagnostic { + pub source: String, + pub severity: String, + pub code: u16, + pub ranges: Vec, + pub code_description: String +} \ No newline at end of file diff --git a/src/linter/linter.rs b/src/linter/linter.rs new file mode 100644 index 0000000..677a1aa --- /dev/null +++ b/src/linter/linter.rs @@ -0,0 +1,14 @@ +use super::diagnostic::{Diagnostic, Range, Position}; + +pub fn get_duplicated() -> Diagnostic { + Diagnostic { + source: String::from("src/main.rs"), + severity: String::from("low"), + code: 1, + ranges: vec![Range { + start: Position { line: 8, character: 8 }, + end: Position { line: 8, character: 12 }, + }], + code_description: String::from("No typing"), + } +} \ No newline at end of file diff --git a/src/linter/mod.rs b/src/linter/mod.rs new file mode 100644 index 0000000..68415a0 --- /dev/null +++ b/src/linter/mod.rs @@ -0,0 +1,5 @@ +mod diagnostic; +mod linter; + +pub use diagnostic::{Diagnostic}; +pub use linter::get_duplicated; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index da9c918..590ac46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,25 +1,15 @@ mod cli; mod config; mod ingestion; +mod debug_run; use clap::Parser; use cli::Args; -use config::get_config; -use debtlint::pipeline::{BpeConfig, run_bpe}; -use ingestion::ingest_codebase; -fn main() -> std::io::Result<()> { - let args = Args::parse(); - let cfg = get_config(); - let files = ingest_codebase(cfg); - - let _result = run_bpe( - &files, - BpeConfig { - vocab_size: args.vocab_size, - min_frequency: args.min_frequency, - }, - args.load_vocab.as_deref(), - )?; - Ok(()) +fn main() { + let _ = Args::parse(); + if let Err(err) = debug_run::run_linter() { + eprintln!("{err}"); + std::process::exit(1); + } } diff --git a/src/pipeline.rs b/src/pipeline.rs index c3fd0d1..6187b5b 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -1,5 +1,6 @@ use crate::in_out::load_vocabulary; use crate::tokenizer::{BpeTrainingResult, SourceFile, encode_corpus, train_corpus}; + use std::path::Path; pub struct BpeConfig {