diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8a5a533 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# https://git-scm.com/docs/gitattributes + +# Ensure consistent EOL(LF) for all files that Git considers text files. +* text=auto eol=lf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0ab954..f0aec60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,11 @@ on: jobs: build_and_lint: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v4 @@ -19,9 +23,18 @@ jobs: - run: npm ci - run: npm run build + - run: npm run lint:commit -- --to "${{ github.sha }}" + if: ${{ runner.os == 'Linux' }} + - run: npm run lint:typescript + if: ${{ runner.os == 'Linux' }} + - run: npm run lint:eslint + if: ${{ runner.os == 'Linux' }} + - run: npm run lint:prettier + if: ${{ runner.os == 'Linux' }} + - run: npm run test - run: npm run start diff --git a/package-lock.json b/package-lock.json index 4bff27f..8e92610 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,11 +16,13 @@ "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", "@octokit/rest": "21.0.2", + "@types/adm-zip": "0.5.7", "@types/node": "22.6.1", "@types/proxy-from-env": "1.0.4", "@typescript-eslint/eslint-plugin": "8.7.0", "@typescript-eslint/parser": "8.7.0", "@vercel/ncc": "0.38.2", + "adm-zip": "0.5.16", "eslint": "8.57.1", "prettier": "3.3.3", "proxy": "2.2.0", @@ -1504,6 +1506,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@types/adm-zip": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.5.7.tgz", + "integrity": "sha512-DNEs/QvmyRLurdQPChqq0Md4zGvPwHerAJYWk9l2jCbD1VPpnzRJorOdiq4zsw09NFbYnhfsoEhWtxIzXpn2yw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/conventional-commits-parser": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@types/conventional-commits-parser/-/conventional-commits-parser-5.0.0.tgz", @@ -1771,6 +1783,16 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/adm-zip": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0" + } + }, "node_modules/agent-base": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", diff --git a/package.json b/package.json index dddd464..03616b1 100644 --- a/package.json +++ b/package.json @@ -37,18 +37,20 @@ "prepublishOnly": "npm run build", "build": "rimraf dist && ncc build src/index.ts --minify", "test": "node --import=tsx --test \"src/**/*.spec.ts\"", - "start": "./dist/index.js", + "start": "node ./dist/index.js", "release": "semantic-release" }, "devDependencies": { "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", "@octokit/rest": "21.0.2", + "@types/adm-zip": "0.5.7", "@types/node": "22.6.1", "@types/proxy-from-env": "1.0.4", "@typescript-eslint/eslint-plugin": "8.7.0", "@typescript-eslint/parser": "8.7.0", "@vercel/ncc": "0.38.2", + "adm-zip": "0.5.16", "eslint": "8.57.1", "prettier": "3.3.3", "proxy": "2.2.0", diff --git a/src/release.ts b/src/release.ts index 7cdb91c..7dd7d65 100644 --- a/src/release.ts +++ b/src/release.ts @@ -7,6 +7,7 @@ import { fetch, ProxyAgent } from "undici" import type { RequestInit } from "undici" import { extract } from "tar" import tmp from "tmp-promise" +import admzip from "adm-zip" import { COMBINED_PATH, NAME } from "./constants" const octokit = new Octokit({ request: { fetch: proxiedFetch } }) @@ -15,7 +16,10 @@ export async function findRelease(version: string) { const release = await getRelease(version) const releasePrefix = getAssetPrefix() const matchedAsset = release.data.assets.find(({ name }) => { - return name.startsWith(releasePrefix) && name.endsWith(".tar.gz") + return ( + name.startsWith(releasePrefix) && + (name.endsWith(".tar.gz") || name.endsWith(".zip")) + ) }) if (!matchedAsset) { throw new Error(`The binary '${releasePrefix}*' not found`) @@ -27,7 +31,14 @@ export async function downloadBinary(url: string) { const response = await proxiedFetch(url) const tmpfile = await tmp.file() await writeFile(tmpfile.path, Buffer.from(await response.arrayBuffer())) - await extract({ file: tmpfile.path, cwd: COMBINED_PATH, strict: true }) + + if (url.endsWith(".zip")) { + const zip = new admzip(tmpfile.path) + zip.extractAllTo(COMBINED_PATH, true) + } else { + await extract({ file: tmpfile.path, cwd: COMBINED_PATH, strict: true }) + } + await tmpfile.cleanup() }