@@ -26,14 +26,27 @@ interface DistroData {
26
26
size : string
27
27
}
28
28
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
+ } > {
30
35
const targetPlatform : string = core . getInput ( 'target-platform' )
31
36
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
+ }
33
46
}
34
47
35
48
const platform = process . platform
36
- let resolvedPlatform
49
+ let resolvedPlatform : string
37
50
switch ( platform ) {
38
51
case 'darwin' :
39
52
resolvedPlatform = 'macos'
@@ -58,7 +71,7 @@ async function resolveTargetPlatform(): Promise<string> {
58
71
}
59
72
60
73
const arch = process . arch
61
- let resolvedArch
74
+ let resolvedArch : string
62
75
switch ( arch ) {
63
76
case 'arm64' :
64
77
resolvedArch = 'aarch64'
@@ -76,7 +89,10 @@ async function resolveTargetPlatform(): Promise<string> {
76
89
throw new Error ( `Unsupported arch: ${ arch } ` )
77
90
}
78
91
79
- return `${ resolvedArch } -${ resolvedPlatform } `
92
+ return {
93
+ arch : resolvedArch ,
94
+ platform : resolvedPlatform
95
+ }
80
96
}
81
97
82
98
async function downloadZigDistrosMetadata ( ) : Promise < any > {
@@ -89,31 +105,45 @@ async function main(): Promise<void> {
89
105
const zigVersion : string = core . getInput ( 'zig-version' )
90
106
const zigDistros = await downloadZigDistrosMetadata ( )
91
107
const availableVersions = Object . keys ( zigDistros )
92
- if ( ! availableVersions . includes ( zigVersion ) ) {
93
- throw new Error ( `Unsupported version: ${ zigVersion } ` )
94
- }
95
108
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
99
115
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 } ` )
104
137
}
105
- core . info ( `Targeting to platform ${ targetPlatform } ...` )
106
138
107
139
const toolPath = cache . find ( 'zig' , versionSpec , targetPlatform )
108
140
if ( toolPath ) {
109
141
core . info ( `Cache hit ${ toolPath } ` )
110
142
core . addPath ( toolPath )
111
143
return
112
144
}
113
-
114
145
core . info ( `Cache miss. Downloading...` )
115
- const zigDistro = ( zigVersionedDistro as Record < string , DistroData > ) [ targetPlatform ]
116
- const tarballLink = zigDistro . tarball
146
+
117
147
const tarballPath = await cache . downloadTool ( tarballLink )
118
148
let extractedPath : string
119
149
if ( tarballLink . endsWith ( 'tar.xz' ) ) {
0 commit comments