Skip to content

Commit aeb03c4

Browse files
committed
Support downloading the full SDK, too
This one is quite a bit trickier: it is offered as a `.tar.xz` because downloading from Azure Pipelines Artifacts is not the fastest thing (unless you can use some internal functionality, which the "Download build artifacts" task seems to be able to do, but a GitHub Action would not have access to that functionality). It would appear that there are no non-native Node.js packages that _can_ uncompress `.xz`, therefore we simply use the fact that Git for Windows is installed on the GitHub Actions' build agents, and that it includes a `tar.exe` and an `xz.exe` to do the job for us. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a5bcdc9 commit aeb03c4

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

src/downloader.ts

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import fs from 'fs'
22
import https from 'https'
3+
import {Readable} from 'stream'
34
import unzipper from 'unzipper'
5+
import {spawn} from 'child_process'
6+
import {delimiter} from 'path'
47

58
async function fetchJSONFromURL<T>(url: string): Promise<T> {
69
return new Promise<T>((resolve, reject) => {
@@ -50,7 +53,13 @@ async function unzip(
5053
url: string,
5154
stripPrefix: string,
5255
outputDirectory: string,
53-
verbose: boolean | number
56+
verbose: boolean | number,
57+
streamEntries?: (
58+
path: string,
59+
stream: Readable,
60+
directory: string,
61+
_verbose: boolean | number
62+
) => void
5463
): Promise<void> {
5564
let progress =
5665
verbose === false
@@ -72,6 +81,10 @@ async function unzip(
7281
res
7382
.pipe(unzipper.Parse())
7483
.on('entry', entry => {
84+
if (streamEntries) {
85+
streamEntries(entry.path, entry, outputDirectory, verbose)
86+
return
87+
}
7588
if (!entry.path.startsWith(stripPrefix)) {
7689
process.stderr.write(
7790
`warning: skipping ${entry.path} because it does not start with ${stripPrefix}\n`
@@ -95,6 +108,34 @@ async function unzip(
95108
})
96109
}
97110

111+
/* We're (ab-)using Git for Windows' `tar.exe` and `xz.exe` to do the job */
112+
function unpackTarXZEntry(
113+
path: string,
114+
stream: Readable,
115+
outputDirectory: string,
116+
verbose: boolean | number = false
117+
): void {
118+
if (path.endsWith('/')) return
119+
if (!path.endsWith('.tar.xz')) {
120+
process.stderr.write(`warning: unhandled entry: ${path}`)
121+
return
122+
}
123+
124+
const usrBinPath = 'C:/Program Files/Git/usr/bin'
125+
const tarXZ = spawn(
126+
`${usrBinPath}/tar.exe`,
127+
[verbose === true ? 'xJvf' : 'xJf', '-'],
128+
{
129+
cwd: outputDirectory,
130+
env: {
131+
PATH: `${usrBinPath}${delimiter}${process.env.PATH}`
132+
},
133+
stdio: ['pipe', 'inherit', 'inherit']
134+
}
135+
)
136+
stream.pipe(tarXZ.stdin)
137+
}
138+
98139
export async function get(
99140
flavor: string,
100141
architecture: string
@@ -127,8 +168,11 @@ export async function get(
127168
artifactName = 'git-sdk-64-makepkg-git'
128169
break
129170
case 'build-installers':
171+
case 'full':
130172
definitionId = architecture === 'i686' ? 30 : 29
131-
artifactName = `git-sdk-${architecture === 'i686' ? 32 : 64}-${flavor}`
173+
artifactName = `git-sdk-${architecture === 'i686' ? 32 : 64}-${
174+
flavor === 'full' ? 'full-sdk' : flavor
175+
}`
132176
break
133177
default:
134178
throw new Error(`Unknown flavor: '${flavor}`)
@@ -160,7 +204,13 @@ export async function get(
160204
)
161205
}
162206
const url = filtered[0].resource.downloadUrl
163-
await unzip(url, `${artifactName}/`, outputDirectory, verbose)
207+
await unzip(
208+
url,
209+
`${artifactName}/`,
210+
outputDirectory,
211+
verbose,
212+
flavor === 'full' ? unpackTarXZEntry : undefined
213+
)
164214
}
165215
return {download, id}
166216
}

0 commit comments

Comments
 (0)