Skip to content

Commit a368b55

Browse files
committed
Add package name to path
1 parent f6978df commit a368b55

File tree

2 files changed

+10
-65
lines changed

2 files changed

+10
-65
lines changed

lib/macos-install.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ function install(version, system) {
3030
let swiftPath = toolCache.find('swift-macOS', version);
3131
if (swiftPath === null || swiftPath.trim().length == 0) {
3232
core.debug(`No matching installation found`);
33-
const path = yield download(swift_versions_1.swiftPackage(version, system));
34-
const extracted = yield unpack(path, version);
33+
const pkg = swift_versions_1.swiftPackage(version, system);
34+
const path = yield download(pkg);
35+
const extracted = yield unpack(pkg, path, version);
3536
swiftPath = extracted;
3637
}
3738
else {
@@ -71,43 +72,17 @@ function toolchainVersion(requestedVersion) {
7172
return match.groups.version;
7273
});
7374
}
74-
function setToolchainVersion(requestedVersion) {
75-
return __awaiter(this, void 0, void 0, function* () {
76-
let output = '';
77-
let error = '';
78-
const options = {
79-
listeners: {
80-
stdout: (data) => {
81-
output += data.toString();
82-
},
83-
stderr: (data) => {
84-
error += data.toString();
85-
}
86-
}
87-
};
88-
yield exec_1.exec('xcrun', ['--toolchain', requestedVersion, '--run', 'swift', '--version'], options);
89-
if (error) {
90-
throw new Error(error);
91-
}
92-
const match = output.match(/(?<version>[0-9]+\.[0-9+]+(\.[0-9]+)?)/) || { groups: { version: null } };
93-
if (!match.groups || !match.groups.version) {
94-
return null;
95-
}
96-
return match.groups.version;
97-
});
98-
}
9975
function download({ url }) {
10076
return __awaiter(this, void 0, void 0, function* () {
10177
core.debug('Downloading swift for macOS');
10278
return toolCache.downloadTool(url);
10379
});
10480
}
105-
function unpack(packagePath, version) {
81+
function unpack({ name }, packagePath, version) {
10682
return __awaiter(this, void 0, void 0, function* () {
10783
core.debug('Extracting package');
10884
const unpackedPath = yield extractXar(packagePath);
109-
yield exec_1.exec('ls', ['-las', unpackedPath]);
110-
const extractedPath = yield toolCache.extractTar(path.join(unpackedPath, 'Payload'));
85+
const extractedPath = yield toolCache.extractTar(path.join(unpackedPath, name, 'Payload'));
11186
core.debug('Package extracted');
11287
const cachedPath = yield toolCache.cacheDir(extractedPath, 'swift-macOS', version);
11388
core.debug('Package cached');

src/macos-install.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export async function install(version: string, system: System) {
1717
if (swiftPath === null || swiftPath.trim().length == 0) {
1818
core.debug(`No matching installation found`)
1919

20-
const path = await download(swiftPackage(version, system))
21-
const extracted = await unpack(path, version)
20+
const pkg = swiftPackage(version, system)
21+
const path = await download(pkg)
22+
const extracted = await unpack(pkg, path, version)
2223

2324
swiftPath = extracted
2425
} else {
@@ -66,46 +67,15 @@ async function toolchainVersion(requestedVersion: string) {
6667
return match.groups.version
6768
}
6869

69-
async function setToolchainVersion(requestedVersion: string) {
70-
let output = ''
71-
let error = ''
72-
73-
const options = {
74-
listeners: {
75-
stdout: (data: Buffer) => {
76-
output += data.toString()
77-
},
78-
stderr: (data: Buffer) => {
79-
error += data.toString()
80-
}
81-
}
82-
}
83-
84-
await exec('xcrun', ['--toolchain', requestedVersion, '--run', 'swift', '--version'], options)
85-
86-
if (error) {
87-
throw new Error(error)
88-
}
89-
90-
const match = output.match(/(?<version>[0-9]+\.[0-9+]+(\.[0-9]+)?)/) || { groups: { version: null } }
91-
92-
if (!match.groups || !match.groups.version) {
93-
return null
94-
}
95-
96-
return match.groups.version
97-
}
98-
9970
async function download({ url }: Package) {
10071
core.debug('Downloading swift for macOS')
10172
return toolCache.downloadTool(url)
10273
}
10374

104-
async function unpack(packagePath: string, version: string) {
75+
async function unpack({ name }: Package, packagePath: string, version: string) {
10576
core.debug('Extracting package')
10677
const unpackedPath = await extractXar(packagePath)
107-
await exec('ls', ['-las', unpackedPath])
108-
const extractedPath = await toolCache.extractTar(path.join(unpackedPath, 'Payload'))
78+
const extractedPath = await toolCache.extractTar(path.join(unpackedPath, name, 'Payload'))
10979
core.debug('Package extracted')
11080
const cachedPath = await toolCache.cacheDir(extractedPath, 'swift-macOS', version)
11181
core.debug('Package cached')

0 commit comments

Comments
 (0)