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

allow use exact commit hash (#13) #14

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 38 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,50 @@ async function downloadZig (version) {
win32: 'zip'
}[os.platform()]

const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
if (version.includes('+')) {
// use exact commit hash
const addrhost = {
linux: 'linux-x86_64',
darwin: 'macos-x86_64',
win32: 'windows-x86_64'
}[os.platform()]
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
const variantName = `zig-${addrhost}-${version}`

const downloadPath = await cache.downloadTool(downloadUrl)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')

const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)

return cachePath
} else {
const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })

const availableVersions = Object.keys(index)
const useVersion = semver.valid(version)
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
: null
const availableVersions = Object.keys(index)
const useVersion = semver.valid(version)
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
: null

const meta = index[useVersion || version]
if (!meta || !meta[host]) {
throw new Error(`Could not find version ${version} for platform ${host}`)
}
const meta = index[useVersion || version]
if (!meta || !meta[host]) {
throw new Error(`Could not find version ${version} for platform ${host}`)
}

const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')

const downloadPath = await cache.downloadTool(meta[host].tarball)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')
const downloadPath = await cache.downloadTool(meta[host].tarball)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')

const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)

return cachePath
return cachePath
}
}

async function main () {
Expand Down
55 changes: 38 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,50 @@ async function downloadZig (version) {
win32: 'zip'
}[os.platform()]

const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
if (version.includes('+')) {
// use exact commit hash
const addrhost = {
linux: 'linux-x86_64',
darwin: 'macos-x86_64',
win32: 'windows-x86_64'
}[os.platform()]
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
const variantName = `zig-${addrhost}-${version}`

const availableVersions = Object.keys(index)
const useVersion = semver.valid(version)
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
: null
const downloadPath = await cache.downloadTool(downloadUrl)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')

const meta = index[useVersion || version]
if (!meta || !meta[host]) {
throw new Error(`Could not find version ${version} for platform ${host}`)
}
const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)

return cachePath
} else {
const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })

const availableVersions = Object.keys(index)
const useVersion = semver.valid(version)
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
: null

const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
const meta = index[useVersion || version]
if (!meta || !meta[host]) {
throw new Error(`Could not find version ${version} for platform ${host}`)
}

const downloadPath = await cache.downloadTool(meta[host].tarball)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')

const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
const downloadPath = await cache.downloadTool(meta[host].tarball)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')

return cachePath
const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)

return cachePath
}
}

async function main () {
Expand Down