Skip to content
This repository was archived by the owner on Oct 5, 2024. It is now read-only.

Commit 5d386f4

Browse files
authored
feat: support dev version spec with commit (#142)
* ci: test coverage 0.11 and dev tag Signed-off-by: tison <[email protected]> * support pin commit ver Signed-off-by: tison <[email protected]> * ncc Signed-off-by: tison <[email protected]> * run all Signed-off-by: tison <[email protected]> * fix master Signed-off-by: tison <[email protected]> * ncc Signed-off-by: tison <[email protected]> * fix ext Signed-off-by: tison <[email protected]> --------- Signed-off-by: tison <[email protected]>
1 parent 49a6f91 commit 5d386f4

File tree

4 files changed

+94
-36
lines changed

4 files changed

+94
-36
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
strategy:
6969
fail-fast: false
7070
matrix:
71-
zig: [ 0.10.0, 0.9.1, 0.8.1, master ]
71+
zig: [ 0.12.0-dev.1710+2bffd8101, 0.11.0, 0.10.0, master ]
7272
os: [ ubuntu-latest, windows-latest, macos-latest ]
7373
runs-on: ${{ matrix.os }}
7474
name: Zig ${{ matrix.zig }} on ${{ matrix.os }}

dist/index.js

Lines changed: 43 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,27 @@ interface DistroData {
2626
size: string
2727
}
2828

29-
async function resolveTargetPlatform(): Promise<string> {
29+
const platformPattern = /(?<arch>\w+)-(?<os>\w+)/
30+
31+
async function resolveArchPlatform(): Promise<{
32+
arch: string
33+
platform: string
34+
}> {
3035
const targetPlatform: string = core.getInput('target-platform')
3136
if (targetPlatform && targetPlatform.length > 0) {
32-
return targetPlatform
37+
const matches = platformPattern.exec(targetPlatform)
38+
if (matches && matches.groups) {
39+
return {
40+
arch: matches.groups.arch,
41+
platform: matches.groups.os
42+
}
43+
} else {
44+
throw new Error(`Unparsed target-platform: ${targetPlatform}`)
45+
}
3346
}
3447

3548
const platform = process.platform
36-
let resolvedPlatform
49+
let resolvedPlatform: string
3750
switch (platform) {
3851
case 'darwin':
3952
resolvedPlatform = 'macos'
@@ -58,7 +71,7 @@ async function resolveTargetPlatform(): Promise<string> {
5871
}
5972

6073
const arch = process.arch
61-
let resolvedArch
74+
let resolvedArch: string
6275
switch (arch) {
6376
case 'arm64':
6477
resolvedArch = 'aarch64'
@@ -76,7 +89,10 @@ async function resolveTargetPlatform(): Promise<string> {
7689
throw new Error(`Unsupported arch: ${arch}`)
7790
}
7891

79-
return `${resolvedArch}-${resolvedPlatform}`
92+
return {
93+
arch: resolvedArch,
94+
platform: resolvedPlatform
95+
}
8096
}
8197

8298
async function downloadZigDistrosMetadata(): Promise<any> {
@@ -89,31 +105,45 @@ async function main(): Promise<void> {
89105
const zigVersion: string = core.getInput('zig-version')
90106
const zigDistros = await downloadZigDistrosMetadata()
91107
const availableVersions = Object.keys(zigDistros)
92-
if (!availableVersions.includes(zigVersion)) {
93-
throw new Error(`Unsupported version: ${zigVersion}`)
94-
}
95108

96-
const zigVersionedDistro = (zigDistros as Record<string, any>)[zigVersion]
97-
const versionSpec = zigVersion !== 'master' ? zigVersion : zigVersionedDistro['version']
98-
core.info(`Using version ${versionSpec}...`)
109+
const {arch, platform} = await resolveArchPlatform()
110+
const targetPlatform = `${arch}-${platform}`
111+
core.info(`Targeting to platform ${targetPlatform}...`)
112+
113+
let versionSpec: string
114+
let tarballLink: string
99115

100-
const targetPlatform: string = await resolveTargetPlatform()
101-
const availablePlatform = Object.keys(zigVersionedDistro)
102-
if (!availablePlatform.includes(targetPlatform)) {
103-
throw new Error(`Unsupported platform: ${targetPlatform}`)
116+
if (!availableVersions.includes(zigVersion) && zigVersion !== 'master') {
117+
versionSpec = zigVersion
118+
let extension: string
119+
if (platform === 'windows') {
120+
extension = 'zip'
121+
} else {
122+
extension = 'tar.xz'
123+
}
124+
tarballLink = `https://ziglang.org/builds/zig-${platform}-${arch}-${versionSpec}.${extension}`
125+
core.info(`Using version ${versionSpec} with link ${tarballLink}`)
126+
} else {
127+
const zigVersionedDistro = (zigDistros as Record<string, any>)[zigVersion]
128+
versionSpec = zigVersion !== 'master' ? zigVersion : zigVersionedDistro['version']
129+
core.info(`Using version ${versionSpec}...`)
130+
const availablePlatform = Object.keys(zigVersionedDistro)
131+
if (!availablePlatform.includes(targetPlatform)) {
132+
throw new Error(`Unsupported platform: ${targetPlatform}`)
133+
}
134+
const zigDistro = (zigVersionedDistro as Record<string, DistroData>)[targetPlatform]
135+
tarballLink = zigDistro.tarball
136+
core.info(`Using link ${tarballLink}`)
104137
}
105-
core.info(`Targeting to platform ${targetPlatform}...`)
106138

107139
const toolPath = cache.find('zig', versionSpec, targetPlatform)
108140
if (toolPath) {
109141
core.info(`Cache hit ${toolPath}`)
110142
core.addPath(toolPath)
111143
return
112144
}
113-
114145
core.info(`Cache miss. Downloading...`)
115-
const zigDistro = (zigVersionedDistro as Record<string, DistroData>)[targetPlatform]
116-
const tarballLink = zigDistro.tarball
146+
117147
const tarballPath = await cache.downloadTool(tarballLink)
118148
let extractedPath: string
119149
if (tarballLink.endsWith('tar.xz')) {

0 commit comments

Comments
 (0)