backport caching to v1 (#54)
* deps: use esbuild * deps: update tool-cache * Fix tool-cache usage (#45) * cache log * log * log * use resolved ver for cache * build * log cache * log * use version as key * deps * loggggggg * method name * improve log * ci: tweak versions * include version for commit deps * trailing * mistake * Use github cache (#53) * Cache the zig compiler locally * logging * npm update * verboser * os.arch * debug * log signal * address https://github.com/actions/toolkit/issues/687 * correct path * add a cache: false option * share size * zigpath * path.join skull * target node12 * changelog: add 1.4.0v1
parent
03aebe4822
commit
3d1ffe6553
|
@ -9,7 +9,7 @@ jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- uses: EndBug/add-and-commit@v4
|
- uses: EndBug/add-and-commit@v4
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -6,7 +6,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm install
|
run: npm install
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
|
@ -17,7 +17,10 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
zig-version: [0.5.0, 0.7.0, master]
|
zig-version: [0.7.0, 0.8.0, 0.9.0, 0.10.0]
|
||||||
|
include:
|
||||||
|
- os: ubuntu-latest
|
||||||
|
zig-version: 0.5.0
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
|
|
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## 1.4.0
|
||||||
|
* The action now caches compilers in your repository's Actions cache by default. This significantly
|
||||||
|
speeds up installs on average. [#53](https://github.com/goto-bus-stop/setup-zig/pull/54)
|
||||||
|
|
||||||
## 1.3.0
|
## 1.3.0
|
||||||
* Support pinning to a specific commit of the zig compiler. ([@codehz](https://github.com/codehz) in [#14](https://github.com/goto-bus-stop/setup-zig/pull/14))
|
* Support pinning to a specific commit of the zig compiler. ([@codehz](https://github.com/codehz) in [#14](https://github.com/goto-bus-stop/setup-zig/pull/14))
|
||||||
```yaml
|
```yaml
|
||||||
|
|
12
README.md
12
README.md
|
@ -53,6 +53,18 @@ If you are running Zig on Windows machines, you need to make sure that your .zig
|
||||||
*.zig text eol=lf
|
*.zig text eol=lf
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This action caches the downloaded compilers in your repository's Actions cache by default,
|
||||||
|
to reduce the load on the Zig Foundation's servers. Cached compilers are only about 60MB
|
||||||
|
each per version/OS/architecture.
|
||||||
|
|
||||||
|
If this is really bad for you for some reason you can disable the caching.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: goto-bus-stop/setup-zig@v1
|
||||||
|
with:
|
||||||
|
cache: false
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[Apache-2.0](LICENSE.md)
|
[Apache-2.0](LICENSE.md)
|
||||||
|
|
|
@ -9,6 +9,10 @@ inputs:
|
||||||
description: 'Version of the zig compiler to use (must be 0.3.0 or up)'
|
description: 'Version of the zig compiler to use (must be 0.3.0 or up)'
|
||||||
required: true
|
required: true
|
||||||
default: '0.5.0'
|
default: '0.5.0'
|
||||||
|
cache:
|
||||||
|
description: 'Cache downloaded compilers for faster action runs. Strongly recommended.'
|
||||||
|
required: false
|
||||||
|
default: 'true'
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|
File diff suppressed because one or more lines are too long
53
index.js
53
index.js
|
@ -1,46 +1,77 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
const actions = require('@actions/core')
|
const actions = require('@actions/core')
|
||||||
const cache = require('@actions/tool-cache')
|
const cache = require('@actions/cache')
|
||||||
|
const toolCache = require('@actions/tool-cache')
|
||||||
const {
|
const {
|
||||||
extForPlatform,
|
extForPlatform,
|
||||||
resolveCommit,
|
resolveCommit,
|
||||||
resolveVersion
|
resolveVersion
|
||||||
} = require('./versions')
|
} = require('./versions')
|
||||||
|
|
||||||
async function downloadZig (platform, version) {
|
const TOOL_NAME = 'zig'
|
||||||
|
|
||||||
|
async function downloadZig (platform, version, useCache = true) {
|
||||||
const ext = extForPlatform(platform)
|
const ext = extForPlatform(platform)
|
||||||
|
|
||||||
const { downloadUrl, variantName } = version.includes('+')
|
const { downloadUrl, variantName, version: useVersion } = version.includes('+')
|
||||||
? resolveCommit(platform, version)
|
? resolveCommit(platform, version)
|
||||||
: await resolveVersion(platform, version)
|
: await resolveVersion(platform, version)
|
||||||
|
|
||||||
const downloadPath = await cache.downloadTool(downloadUrl)
|
const cachedPath = toolCache.find(TOOL_NAME, useVersion)
|
||||||
|
if (cachedPath) {
|
||||||
|
actions.info(`using cached zig install: ${cachedPath}`)
|
||||||
|
return cachedPath
|
||||||
|
}
|
||||||
|
|
||||||
|
const cacheKey = `${TOOL_NAME}-${variantName}`
|
||||||
|
if (useCache) {
|
||||||
|
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) {
|
||||||
|
actions.info(`using cached zig install: ${restorePath}`)
|
||||||
|
return restorePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.info(`no cached version found. downloading zig ${variantName}`)
|
||||||
|
const downloadPath = await toolCache.downloadTool(downloadUrl)
|
||||||
const zigPath = ext === 'zip'
|
const zigPath = ext === 'zip'
|
||||||
? await cache.extractZip(downloadPath)
|
? await toolCache.extractZip(downloadPath)
|
||||||
: await cache.extractTar(downloadPath, undefined, 'x')
|
: await toolCache.extractTar(downloadPath, undefined, 'x')
|
||||||
|
|
||||||
const binPath = path.join(zigPath, variantName)
|
const binPath = path.join(zigPath, variantName)
|
||||||
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
|
const cachePath = await toolCache.cacheDir(binPath, TOOL_NAME, useVersion)
|
||||||
|
|
||||||
|
if (useCache) {
|
||||||
|
actions.info(`adding zig ${useVersion} at ${cachePath} to local cache ${cacheKey}`)
|
||||||
|
await cache.saveCache([cachePath], cacheKey)
|
||||||
|
}
|
||||||
|
|
||||||
return cachePath
|
return cachePath
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main () {
|
async function main () {
|
||||||
const version = actions.getInput('version') || '0.5.0'
|
const version = actions.getInput('version') || '0.5.0'
|
||||||
|
const useCache = actions.getInput('cache') || 'true'
|
||||||
if (semver.valid(version) && semver.lt(version, '0.3.0')) {
|
if (semver.valid(version) && semver.lt(version, '0.3.0')) {
|
||||||
actions.setFailed('This action does not work with Zig 0.1.0 and Zig 0.2.0')
|
actions.setFailed('This action does not work with Zig 0.1.0 and Zig 0.2.0')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (useCache !== 'false' && useCache !== 'true') {
|
||||||
let zigPath = cache.find('zig', version)
|
actions.setFailed('`with.cache` must be "true" or "false"')
|
||||||
if (!zigPath) {
|
return
|
||||||
zigPath = await downloadZig(os.platform(), version)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const zigPath = await downloadZig(os.platform(), version, Boolean(useCache))
|
||||||
|
|
||||||
// Add the `zig` binary to the $PATH
|
// Add the `zig` binary to the $PATH
|
||||||
actions.addPath(zigPath)
|
actions.addPath(zigPath)
|
||||||
|
actions.info(`zig installed at ${zigPath}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
main().catch((err) => {
|
||||||
|
|
|
@ -7,14 +7,15 @@
|
||||||
"url": "https://github.com/goto-bus-stop/setup-zig/issues"
|
"url": "https://github.com/goto-bus-stop/setup-zig/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@actions/cache": "^3.2.1",
|
||||||
"@actions/core": "^1.2.2",
|
"@actions/core": "^1.2.2",
|
||||||
"@actions/tool-cache": "^1.3.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"semver": "^7.1.3",
|
"semver": "^7.1.3",
|
||||||
"simple-get": "^4.0.0"
|
"simple-get": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vercel/ncc": "^0.25.0",
|
"esbuild": "^0.18.8",
|
||||||
"standard": "^16.0.1"
|
"standard": "^17.0.0"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/goto-bus-stop/setup-zig",
|
"homepage": "https://github.com/goto-bus-stop/setup-zig",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -30,7 +31,7 @@
|
||||||
"url": "https://github.com/goto-bus-stop/setup-zig.git"
|
"url": "https://github.com/goto-bus-stop/setup-zig.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "ncc build index.js -o dist",
|
"prepare": "esbuild index.js --outdir=dist --keep-names --bundle --platform=node --target=node12",
|
||||||
"test": "standard && node test"
|
"test": "standard && node test"
|
||||||
},
|
},
|
||||||
"standard": {
|
"standard": {
|
||||||
|
|
12
test.js
12
test.js
|
@ -7,20 +7,24 @@ const {
|
||||||
async function test () {
|
async function test () {
|
||||||
assert.deepEqual(resolveCommit('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',
|
downloadUrl: 'https://ziglang.org/builds/zig-linux-x86_64-0.6.0+4b48fccad.tar.xz',
|
||||||
variantName: 'zig-linux-x86_64-0.6.0+4b48fccad'
|
variantName: 'zig-linux-x86_64-0.6.0+4b48fccad',
|
||||||
|
version: '0.6.0+4b48fccad'
|
||||||
})
|
})
|
||||||
assert.deepEqual(resolveCommit('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',
|
downloadUrl: 'https://ziglang.org/builds/zig-windows-x86_64-0.6.0+4b48fccad.zip',
|
||||||
variantName: 'zig-windows-x86_64-0.6.0+4b48fccad'
|
variantName: 'zig-windows-x86_64-0.6.0+4b48fccad',
|
||||||
|
version: '0.6.0+4b48fccad'
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.deepEqual(await resolveVersion('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',
|
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'
|
variantName: 'zig-linux-x86_64-0.7.0',
|
||||||
|
version: '0.7.0'
|
||||||
})
|
})
|
||||||
assert.deepEqual(await resolveVersion('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',
|
downloadUrl: 'https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip',
|
||||||
variantName: 'zig-windows-x86_64-0.4.0'
|
variantName: 'zig-windows-x86_64-0.4.0',
|
||||||
|
version: '0.4.0'
|
||||||
})
|
})
|
||||||
await assert.doesNotReject(resolveVersion('linux', 'master'))
|
await assert.doesNotReject(resolveVersion('linux', 'master'))
|
||||||
await assert.doesNotReject(resolveVersion('win32', 'master'))
|
await assert.doesNotReject(resolveVersion('win32', 'master'))
|
||||||
|
|
|
@ -21,7 +21,7 @@ function resolveCommit (platform, version) {
|
||||||
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
|
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
|
||||||
const variantName = `zig-${addrhost}-${version}`
|
const variantName = `zig-${addrhost}-${version}`
|
||||||
|
|
||||||
return { downloadUrl, variantName }
|
return { downloadUrl, variantName, version }
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJSON (opts) {
|
function getJSON (opts) {
|
||||||
|
@ -59,7 +59,7 @@ async function resolveVersion (platform, version) {
|
||||||
const downloadUrl = meta[host].tarball
|
const downloadUrl = meta[host].tarball
|
||||||
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
|
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
|
||||||
|
|
||||||
return { downloadUrl, variantName }
|
return { downloadUrl, variantName, version: useVersion || version }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in New Issue