Compare commits

..

13 Commits

Author SHA1 Message Date
d78f7abf57
mach engine support 2024-04-28 21:00:34 -07:00
Renée Kooi
d637512b0b Merge branch 'default' into fix-caching 2024-04-26 10:11:14 +02:00
Renée
2a9625d550
Update CI version matrix (#77)
* ci: tweak versions matrix

* tweak ifs

* ci: different way to use legacy versions

* clearer test variant name

* fixup! clearer test variant name

* syntax?
2024-04-26 10:05:48 +02:00
Renée Kooi
c921de45d4 Update tests for version resolution 2024-04-26 09:51:59 +02:00
Renée Kooi
e3b63a8160 Run standard --fix 2024-04-26 09:42:30 +02:00
goto-bus-stop
8554b2f249 Rebuild (automated) 2024-04-26 07:39:51 +00:00
David
ef1fbe2694
Better handle architecture, fixes macOS silicon support (#68) 2024-04-26 09:39:29 +02:00
Renée Kooi
ddee30a84b Merge branch 'default' into fix-caching 2024-04-26 09:37:40 +02:00
goto-bus-stop
4f12c907f3 Rebuild (automated) 2024-01-29 09:56:20 +00:00
dependabot[bot]
c13dfb00a4
Bump esbuild from 0.19.12 to 0.20.0 (#71)
Bumps [esbuild](https://github.com/evanw/esbuild) from 0.19.12 to 0.20.0.
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG.md)
- [Commits](https://github.com/evanw/esbuild/compare/v0.19.12...v0.20.0)

---
updated-dependencies:
- dependency-name: esbuild
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-29 10:55:58 +01:00
Mark Delk
11ef85623b fix 🐛 when extracting 2023-11-26 00:51:32 -06:00
Mark Delk
8269bac1f7 add another spec, rm unused var 2023-11-26 00:29:13 -06:00
Mark Delk
9f5e80ae9e fix caching by ignoring semver build metadata 2023-11-23 22:00:45 -06:00
7 changed files with 3130 additions and 2341 deletions

View File

@ -17,11 +17,23 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
zig-version: [0.7.0, 0.8.0, 0.9.0, 0.10.0, 0.11.0]
os: [ubuntu-latest, macos-12, macos-latest, windows-latest]
zig-version: [0.11.0, 0.12.0]
test-variant: [modern]
include:
- os: ubuntu-latest
zig-version: 0.5.0
- { 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 }
runs-on: ${{matrix.os}}
steps:
- name: Checkout sources
@ -31,10 +43,10 @@ jobs:
with:
version: ${{matrix.zig-version}}
- name: Run tests (zig up to v0.10.x)
if: ${{ !startsWith(matrix.zig-version, '0.11.') }}
if: ${{ matrix.test-variant == 'legacy' }}
run: zig build test
working-directory: test/v0.10
- name: Run tests (zig v0.11.x)
if: ${{ startsWith(matrix.zig-version, '0.11.') }}
if: ${{ matrix.test-variant == 'modern' }}
run: zig build test
working-directory: test/v0.11

5016
dist/index.js vendored

File diff suppressed because it is too large Load Diff

60
flake.lock Normal file
View File

@ -0,0 +1,60 @@
{
"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
}

View File

@ -14,12 +14,17 @@ const {
const TOOL_NAME = 'zig'
async function downloadZig (platform, version, useCache = true) {
async function downloadZig (arch, platform, version, useCache = true) {
const ext = extForPlatform(platform)
const { downloadUrl, variantName, version: useVersion } = version.includes('+')
? resolveCommit(platform, version)
: await resolveVersion(platform, version)
const {
downloadUrl,
fileWithoutFileType,
variantName,
version: useVersion
} = version.includes('+')
? resolveCommit(arch, platform, version)
: await resolveVersion(arch, platform, version)
const cachedPath = toolCache.find(TOOL_NAME, useVersion)
if (cachedPath) {
@ -29,7 +34,7 @@ async function downloadZig (platform, version, useCache = true) {
const cacheKey = `${TOOL_NAME}-${variantName}`
if (useCache) {
const restorePath = path.join(process.env.RUNNER_TOOL_CACHE, TOOL_NAME, useVersion, os.arch())
const restorePath = path.join(process.env.RUNNER_TOOL_CACHE, TOOL_NAME, useVersion, arch)
actions.info(`attempting restore of ${cacheKey} to ${restorePath}`)
const restoredKey = await cache.restoreCache([restorePath], cacheKey)
if (restoredKey) {
@ -44,7 +49,7 @@ async function downloadZig (platform, version, useCache = true) {
? await toolCache.extractZip(downloadPath)
: await toolCache.extractTar(downloadPath, undefined, 'x')
const binPath = path.join(zigPath, variantName)
const binPath = path.join(zigPath, fileWithoutFileType)
const cachePath = await toolCache.cacheDir(binPath, TOOL_NAME, useVersion)
if (useCache) {
@ -67,7 +72,7 @@ async function main () {
return
}
const zigPath = await downloadZig(os.platform(), version, useCache === 'true')
const zigPath = await downloadZig(os.arch(), os.platform(), version, useCache === 'true')
// Add the `zig` binary to the $PATH
actions.addPath(zigPath)

View File

@ -14,7 +14,7 @@
"simple-get": "^4.0.0"
},
"devDependencies": {
"esbuild": "^0.19.0",
"esbuild": "^0.20.0",
"standard": "^17.0.0"
},
"homepage": "https://github.com/goto-bus-stop/setup-zig",

63
test.js
View File

@ -5,29 +5,72 @@ const {
} = require('./versions')
async function test () {
assert.deepEqual(resolveCommit('linux', '0.6.0+4b48fccad'), {
assert.deepEqual(resolveCommit('x64', 'linux', '0.6.0+4b48fccad'), {
downloadUrl: 'https://ziglang.org/builds/zig-linux-x86_64-0.6.0+4b48fccad.tar.xz',
variantName: 'zig-linux-x86_64-0.6.0+4b48fccad',
version: '0.6.0+4b48fccad'
fileWithoutFileType: 'zig-linux-x86_64-0.6.0+4b48fccad',
variantName: 'zig-linux-x86_64-0.6.0',
version: '0.6.0'
})
assert.deepEqual(resolveCommit('win32', '0.6.0+4b48fccad'), {
assert.deepEqual(resolveCommit('x64', 'win32', '0.6.0+4b48fccad'), {
downloadUrl: 'https://ziglang.org/builds/zig-windows-x86_64-0.6.0+4b48fccad.zip',
variantName: 'zig-windows-x86_64-0.6.0+4b48fccad',
version: '0.6.0+4b48fccad'
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'
})
assert.deepEqual(await resolveVersion('linux', '0.7.0'), {
assert.deepEqual(await resolveVersion('x64', '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('win32', '0.4.0'), {
assert.deepEqual(await resolveVersion('x64', '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'
})
await assert.doesNotReject(resolveVersion('linux', 'master'))
await assert.doesNotReject(resolveVersion('win32', 'master'))
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'))
}
test().catch((error) => {

View File

@ -10,18 +10,44 @@ function extForPlatform (platform) {
}[platform]
}
function resolveCommit (platform, version) {
/**
* 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) {
const ext = extForPlatform(platform)
const addrhost = {
linux: 'linux-x86_64',
darwin: 'macos-x86_64',
win32: 'windows-x86_64'
const resolvedOs = {
linux: 'linux',
darwin: 'macos',
win32: 'windows'
}[platform]
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
const variantName = `zig-${addrhost}-${version}`
const resolvedArch = {
arm: 'armv7a',
arm64: 'aarch64',
ppc64: 'powerpc64',
riscv64: 'riscv64',
x64: 'x86_64'
}[arch]
return { downloadUrl, variantName, 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
}
}
function getJSON (opts) {
@ -36,28 +62,57 @@ function getJSON (opts) {
})
}
async function resolveVersion (platform, version) {
/**
* 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) {
const ext = extForPlatform(platform)
const host = {
linux: 'x86_64-linux',
darwin: 'x86_64-macos',
win32: 'x86_64-windows'
}[platform] || platform
const resolvedOs = {
linux: 'linux',
darwin: 'macos',
win32: 'windows'
}[platform]
const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
const resolvedArch = {
arm: 'armv7a',
arm64: 'aarch64',
ppc64: 'powerpc64',
riscv64: 'riscv64',
x64: 'x86_64'
}[arch]
const availableVersions = Object.keys(index)
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 useVersion = semver.valid(version)
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
: null
const meta = index[useVersion || version]
// 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]
if (!meta || !meta[host]) {
throw new Error(`Could not find version ${useVersion || version} for platform ${host}`)
}
const downloadUrl = meta[host].tarball
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
// 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*$/, '')
return { downloadUrl, variantName, version: useVersion || version }
}