Compare commits
No commits in common. "d78f7abf57e77a749d297b45d845a0d086f51ddb" and "7e1b9284f3b8edf30a1e5fdcc2a99898e7c724c4" have entirely different histories.
d78f7abf57
...
7e1b9284f3
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
|
@ -17,23 +17,11 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-12, macos-latest, windows-latest]
|
||||
zig-version: [0.11.0, 0.12.0]
|
||||
test-variant: [modern]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
zig-version: [0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.11.0]
|
||||
include:
|
||||
- { os: ubuntu-latest, zig-version: 0.5.0, test-variant: legacy }
|
||||
- { os: ubuntu-latest, zig-version: 0.7.0, test-variant: legacy }
|
||||
- { os: ubuntu-latest, zig-version: 0.8.0, test-variant: legacy }
|
||||
- { os: ubuntu-latest, zig-version: 0.9.0, test-variant: legacy }
|
||||
- { os: ubuntu-latest, zig-version: 0.10.0, test-variant: legacy }
|
||||
- { os: macos-12, zig-version: 0.7.0, test-variant: legacy }
|
||||
- { os: macos-12, zig-version: 0.8.0, test-variant: legacy }
|
||||
- { os: macos-12, zig-version: 0.9.0, test-variant: legacy }
|
||||
- { os: macos-12, zig-version: 0.10.0, test-variant: legacy }
|
||||
- { os: windows-latest, zig-version: 0.7.0, test-variant: legacy }
|
||||
- { os: windows-latest, zig-version: 0.8.0, test-variant: legacy }
|
||||
- { os: windows-latest, zig-version: 0.9.0, test-variant: legacy }
|
||||
- { os: windows-latest, zig-version: 0.10.0, test-variant: legacy }
|
||||
- os: ubuntu-latest
|
||||
zig-version: 0.5.0
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
|
@ -43,10 +31,10 @@ jobs:
|
|||
with:
|
||||
version: ${{matrix.zig-version}}
|
||||
- name: Run tests (zig up to v0.10.x)
|
||||
if: ${{ matrix.test-variant == 'legacy' }}
|
||||
if: ${{ !startsWith(matrix.zig-version, '0.11.') }}
|
||||
run: zig build test
|
||||
working-directory: test/v0.10
|
||||
- name: Run tests (zig v0.11.x)
|
||||
if: ${{ matrix.test-variant == 'modern' }}
|
||||
if: ${{ startsWith(matrix.zig-version, '0.11.') }}
|
||||
run: zig build test
|
||||
working-directory: test/v0.11
|
||||
|
|
4914
dist/index.js
vendored
4914
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
60
flake.lock
60
flake.lock
|
@ -1,60 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1714245158,
|
||||
"narHash": "sha256-9P2M0+tf1TE7Z5PwDVwhheuD2mFf6/phPr0Jvl7cxcc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2b1f64b358f2cab62617f26b3870fd0ee375d848",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
19
index.js
19
index.js
|
@ -14,17 +14,12 @@ const {
|
|||
|
||||
const TOOL_NAME = 'zig'
|
||||
|
||||
async function downloadZig (arch, platform, version, useCache = true) {
|
||||
async function downloadZig (platform, version, useCache = true) {
|
||||
const ext = extForPlatform(platform)
|
||||
|
||||
const {
|
||||
downloadUrl,
|
||||
fileWithoutFileType,
|
||||
variantName,
|
||||
version: useVersion
|
||||
} = version.includes('+')
|
||||
? resolveCommit(arch, platform, version)
|
||||
: await resolveVersion(arch, platform, version)
|
||||
const { downloadUrl, variantName, version: useVersion } = version.includes('+')
|
||||
? resolveCommit(platform, version)
|
||||
: await resolveVersion(platform, version)
|
||||
|
||||
const cachedPath = toolCache.find(TOOL_NAME, useVersion)
|
||||
if (cachedPath) {
|
||||
|
@ -34,7 +29,7 @@ async function downloadZig (arch, platform, version, useCache = true) {
|
|||
|
||||
const cacheKey = `${TOOL_NAME}-${variantName}`
|
||||
if (useCache) {
|
||||
const restorePath = path.join(process.env.RUNNER_TOOL_CACHE, TOOL_NAME, useVersion, arch)
|
||||
const restorePath = path.join(process.env.RUNNER_TOOL_CACHE, TOOL_NAME, useVersion, os.arch())
|
||||
actions.info(`attempting restore of ${cacheKey} to ${restorePath}`)
|
||||
const restoredKey = await cache.restoreCache([restorePath], cacheKey)
|
||||
if (restoredKey) {
|
||||
|
@ -49,7 +44,7 @@ async function downloadZig (arch, platform, version, useCache = true) {
|
|||
? await toolCache.extractZip(downloadPath)
|
||||
: await toolCache.extractTar(downloadPath, undefined, 'x')
|
||||
|
||||
const binPath = path.join(zigPath, fileWithoutFileType)
|
||||
const binPath = path.join(zigPath, variantName)
|
||||
const cachePath = await toolCache.cacheDir(binPath, TOOL_NAME, useVersion)
|
||||
|
||||
if (useCache) {
|
||||
|
@ -72,7 +67,7 @@ async function main () {
|
|||
return
|
||||
}
|
||||
|
||||
const zigPath = await downloadZig(os.arch(), os.platform(), version, useCache === 'true')
|
||||
const zigPath = await downloadZig(os.platform(), version, useCache === 'true')
|
||||
|
||||
// Add the `zig` binary to the $PATH
|
||||
actions.addPath(zigPath)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"simple-get": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.20.0",
|
||||
"esbuild": "^0.19.0",
|
||||
"standard": "^17.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/goto-bus-stop/setup-zig",
|
||||
|
|
63
test.js
63
test.js
|
@ -5,72 +5,29 @@ const {
|
|||
} = require('./versions')
|
||||
|
||||
async function test () {
|
||||
assert.deepEqual(resolveCommit('x64', 'linux', '0.6.0+4b48fccad'), {
|
||||
assert.deepEqual(resolveCommit('linux', '0.6.0+4b48fccad'), {
|
||||
downloadUrl: 'https://ziglang.org/builds/zig-linux-x86_64-0.6.0+4b48fccad.tar.xz',
|
||||
fileWithoutFileType: 'zig-linux-x86_64-0.6.0+4b48fccad',
|
||||
variantName: 'zig-linux-x86_64-0.6.0',
|
||||
version: '0.6.0'
|
||||
variantName: 'zig-linux-x86_64-0.6.0+4b48fccad',
|
||||
version: '0.6.0+4b48fccad'
|
||||
})
|
||||
assert.deepEqual(resolveCommit('x64', 'win32', '0.6.0+4b48fccad'), {
|
||||
assert.deepEqual(resolveCommit('win32', '0.6.0+4b48fccad'), {
|
||||
downloadUrl: 'https://ziglang.org/builds/zig-windows-x86_64-0.6.0+4b48fccad.zip',
|
||||
fileWithoutFileType: 'zig-windows-x86_64-0.6.0+4b48fccad',
|
||||
variantName: 'zig-windows-x86_64-0.6.0',
|
||||
version: '0.6.0'
|
||||
})
|
||||
assert.deepEqual(resolveCommit('x64', 'win32', '0.12.0-dev.1092+68ed78775'), {
|
||||
downloadUrl: 'https://ziglang.org/builds/zig-windows-x86_64-0.12.0-dev.1092+68ed78775.zip',
|
||||
fileWithoutFileType: 'zig-windows-x86_64-0.12.0-dev.1092+68ed78775',
|
||||
variantName: 'zig-windows-x86_64-0.12.0-dev.1092',
|
||||
version: '0.12.0-dev.1092'
|
||||
})
|
||||
assert.deepEqual(resolveCommit('x64', 'darwin', '0.12.0-dev.1150+3c22cecee'), {
|
||||
downloadUrl: 'https://ziglang.org/builds/zig-macos-x86_64-0.12.0-dev.1150+3c22cecee.tar.xz',
|
||||
fileWithoutFileType: 'zig-macos-x86_64-0.12.0-dev.1150+3c22cecee',
|
||||
variantName: 'zig-macos-x86_64-0.12.0-dev.1150',
|
||||
version: '0.12.0-dev.1150'
|
||||
variantName: 'zig-windows-x86_64-0.6.0+4b48fccad',
|
||||
version: '0.6.0+4b48fccad'
|
||||
})
|
||||
|
||||
assert.deepEqual(await resolveVersion('x64', 'linux', '0.7.0'), {
|
||||
assert.deepEqual(await resolveVersion('linux', '0.7.0'), {
|
||||
downloadUrl: 'https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz',
|
||||
variantName: 'zig-linux-x86_64-0.7.0',
|
||||
version: '0.7.0'
|
||||
})
|
||||
assert.deepEqual(await resolveVersion('x64', 'win32', '0.4.0'), {
|
||||
assert.deepEqual(await resolveVersion('win32', '0.4.0'), {
|
||||
downloadUrl: 'https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip',
|
||||
variantName: 'zig-windows-x86_64-0.4.0',
|
||||
version: '0.4.0'
|
||||
})
|
||||
assert.deepEqual(await resolveVersion('arm64', 'darwin', '0.11.0'), {
|
||||
downloadUrl: 'https://ziglang.org/download/0.11.0/zig-macos-aarch64-0.11.0.tar.xz',
|
||||
variantName: 'zig-macos-aarch64-0.11.0',
|
||||
version: '0.11.0'
|
||||
})
|
||||
assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.1.0-mach'), {
|
||||
downloadUrl: 'https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.2063+804cee3b9.tar.xz',
|
||||
variantName: 'zig-macos-aarch64-0.12.0-dev.2063',
|
||||
version: '2024.1.0-mach'
|
||||
})
|
||||
assert.deepEqual(await resolveVersion('x64', 'linux', '2024.3.0-mach'), {
|
||||
downloadUrl: 'https://pkg.machengine.org/zig/zig-linux-x86_64-0.12.0-dev.3180+83e578a18.tar.xz',
|
||||
variantName: 'zig-linux-x86_64-0.12.0-dev.3180',
|
||||
version: '2024.3.0-mach'
|
||||
})
|
||||
assert.deepEqual(await resolveVersion('x64', 'win32', '2024.1.0-mach'), {
|
||||
downloadUrl: 'https://pkg.machengine.org/zig/zig-windows-x86_64-0.12.0-dev.2063+804cee3b9.zip',
|
||||
variantName: 'zig-windows-x86_64-0.12.0-dev.2063',
|
||||
version: '2024.1.0-mach'
|
||||
})
|
||||
assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.3.0-mach'), {
|
||||
downloadUrl: 'https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.3180+83e578a18.tar.xz',
|
||||
variantName: 'zig-macos-aarch64-0.12.0-dev.3180',
|
||||
version: '2024.3.0-mach'
|
||||
})
|
||||
await assert.doesNotReject(resolveVersion('x64', 'linux', 'mach-latest'))
|
||||
await assert.doesNotReject(resolveVersion('x64', 'win32', 'mach-latest'))
|
||||
await assert.doesNotReject(resolveVersion('arm64', 'darwin', 'mach-latest'))
|
||||
await assert.doesNotReject(resolveVersion('x64', 'linux', 'master'))
|
||||
await assert.doesNotReject(resolveVersion('x64', 'win32', 'master'))
|
||||
await assert.doesNotReject(resolveVersion('arm64', 'darwin', 'master'))
|
||||
await assert.doesNotReject(resolveVersion('linux', 'master'))
|
||||
await assert.doesNotReject(resolveVersion('win32', 'master'))
|
||||
}
|
||||
|
||||
test().catch((error) => {
|
||||
|
|
91
versions.js
91
versions.js
|
@ -10,44 +10,18 @@ function extForPlatform (platform) {
|
|||
}[platform]
|
||||
}
|
||||
|
||||
/**
|
||||
* resolveCommit resolves a specific commit, so is only used
|
||||
* in cases where the zig version is specified through the use of a plus
|
||||
* sign. It does not require any fetch from an external resource as the
|
||||
* data (downloadUrl, etc) can be resolved directly
|
||||
*/
|
||||
function resolveCommit (arch, platform, version) {
|
||||
function resolveCommit (platform, version) {
|
||||
const ext = extForPlatform(platform)
|
||||
const resolvedOs = {
|
||||
linux: 'linux',
|
||||
darwin: 'macos',
|
||||
win32: 'windows'
|
||||
const addrhost = {
|
||||
linux: 'linux-x86_64',
|
||||
darwin: 'macos-x86_64',
|
||||
win32: 'windows-x86_64'
|
||||
}[platform]
|
||||
|
||||
const resolvedArch = {
|
||||
arm: 'armv7a',
|
||||
arm64: 'aarch64',
|
||||
ppc64: 'powerpc64',
|
||||
riscv64: 'riscv64',
|
||||
x64: 'x86_64'
|
||||
}[arch]
|
||||
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
|
||||
const variantName = `zig-${addrhost}-${version}`
|
||||
|
||||
const downloadUrl = `https://ziglang.org/builds/zig-${resolvedOs}-${resolvedArch}-${version}.${ext}`
|
||||
// This function is only called if the version includes a '+' sign, so mach versions
|
||||
// will not come through here
|
||||
//
|
||||
// Mach builds come from pkg.machengine.org
|
||||
// const machDownloadUrl = `https://pkg.machengine.org/zig/zig-${resolvedOs}-${resolvedArch}-${version}.${ext}`
|
||||
const versionWithoutBuildHash = semver.clean(version)
|
||||
const fileWithoutFileType = `zig-${resolvedOs}-${resolvedArch}-${version}`
|
||||
const variantName = `zig-${resolvedOs}-${resolvedArch}-${versionWithoutBuildHash}`
|
||||
|
||||
return {
|
||||
downloadUrl,
|
||||
fileWithoutFileType,
|
||||
variantName,
|
||||
version: versionWithoutBuildHash
|
||||
}
|
||||
return { downloadUrl, variantName, version }
|
||||
}
|
||||
|
||||
function getJSON (opts) {
|
||||
|
@ -62,57 +36,28 @@ function getJSON (opts) {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* resolveVersion resolves a generic commit, so is only used
|
||||
* in cases where the zig version is specified through WITHOUT the use of a plus
|
||||
* sign. It needs to fetch data from the index files provided by zig (or mach)
|
||||
* to determine the appropriate downloadUrl, etc.
|
||||
*
|
||||
* @returns {string} download URL for the version
|
||||
* @returns {string} variant name for the version - should be used as cache key
|
||||
* @returns {string} version name - use for display only
|
||||
*/
|
||||
async function resolveVersion (arch, platform, version) {
|
||||
async function resolveVersion (platform, version) {
|
||||
const ext = extForPlatform(platform)
|
||||
const resolvedOs = {
|
||||
linux: 'linux',
|
||||
darwin: 'macos',
|
||||
win32: 'windows'
|
||||
}[platform]
|
||||
const host = {
|
||||
linux: 'x86_64-linux',
|
||||
darwin: 'x86_64-macos',
|
||||
win32: 'x86_64-windows'
|
||||
}[platform] || platform
|
||||
|
||||
const resolvedArch = {
|
||||
arm: 'armv7a',
|
||||
arm64: 'aarch64',
|
||||
ppc64: 'powerpc64',
|
||||
riscv64: 'riscv64',
|
||||
x64: 'x86_64'
|
||||
}[arch]
|
||||
const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
|
||||
|
||||
const host = `${resolvedArch}-${resolvedOs}`
|
||||
|
||||
// const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
|
||||
const machIndex = await getJSON({ url: 'https://machengine.org/zig/index.json' })
|
||||
|
||||
const availableVersions = Object.keys(machIndex)
|
||||
const availableVersions = Object.keys(index)
|
||||
const useVersion = semver.valid(version)
|
||||
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
|
||||
: null
|
||||
|
||||
// The mach index is advertised as a strict superset of the ziglang index,
|
||||
// but we will fall back to the the ziglang index just in case
|
||||
const meta = machIndex[useVersion || version] ||
|
||||
(await getJSON({ url: 'https://ziglang.org/download/index.json' }))[useVersion || version]
|
||||
|
||||
const meta = index[useVersion || version]
|
||||
if (!meta || !meta[host]) {
|
||||
throw new Error(`Could not find version ${useVersion || version} for platform ${host}`)
|
||||
}
|
||||
|
||||
const downloadUrl = meta[host].tarball
|
||||
// If this is mach, we could end up with '+sha...' at the end of this, as
|
||||
// a version of '2024.1.0-mach' will resolve to a specific dev version
|
||||
// So, while the function is not called with "+...", we still have to deal with
|
||||
// it. This is important as it is used as the cache key
|
||||
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '').replace(/\+\S*$/, '')
|
||||
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
|
||||
|
||||
return { downloadUrl, variantName, version: useVersion || version }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user