Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for .zip files in binary download #417

Merged
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } })
Expand All @@ -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`)
Expand All @@ -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()
}

Expand Down
Loading