Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Apr 17, 2020
1 parent 8a650f4 commit a4698fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
23 changes: 12 additions & 11 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const io = __importStar(require("@actions/io"));
const fs = __importStar(require("fs"));
const util = __importStar(require("util"));
const path = __importStar(require("path"));
async function cmd(cmd, args, failOnStdErr = true) {
async function runCmd(cmd, args, failOnStdErr = true) {
let stdOut = '';
await exec.exec(cmd, args, {
failOnStdErr: failOnStdErr,
Expand All @@ -41,14 +41,14 @@ async function install(installBase, branchName, versionTag, platform) {
]);
});
await core.group('Verifying files', async () => {
await cmd('gpg', ['--import', allKeysFile], false);
await cmd('gpg', ['--verify', '--quiet', swiftSig, swiftPkg], false);
await runCmd('gpg', ['--import', allKeysFile], false);
await runCmd('gpg', ['--verify', '--quiet', swiftSig, swiftPkg], false);
});
await core.group('Unpacking files', async () => {
// We need to pass 'strip-components', so we cannot use 'tools.extractTar'
await cmd('tar', ['x', '--strip-components=1', '-C', installBase, '-f', swiftPkg]);
await runCmd('tar', ['x', '--strip-components=1', '-C', installBase, '-f', swiftPkg]);
// We need the -R option and want to simply add r (not knowing what the other permissions are), so we use the command line here.
await cmd('chmod', ['-R', 'o+r', path.join(installBase, '/usr/lib/swift')]);
await runCmd('chmod', ['-R', 'o+r', path.join(installBase, '/usr/lib/swift')]);
});
await core.group('Cleaning up', async () => {
await io.rmRF(tempPath);
Expand Down Expand Up @@ -76,8 +76,8 @@ async function main() {
core.endGroup();
if (!skipApt) {
await core.group('Install dependencies', async () => {
await cmd('sudo', ['apt-get', '-q', 'update']);
await cmd('sudo', [
await runCmd('sudo', ['apt-get', '-q', 'update']);
await runCmd('sudo', [
'apt-get', '-q', 'install', '-y',
'libatomic1',
'libbsd0',
Expand All @@ -100,9 +100,10 @@ async function main() {
else {
core.info("Skipping installation of dependencies...");
}
const mangledName = `swift.${swiftBranch}-${swiftVersion}-${swiftPlatform}`;
const versionIdentifier = `${swiftBranch}-${swiftVersion}-${swiftPlatform}`;
const mangledName = `swift.${versionIdentifier}`;
const cachedVersion = tools.find(mangledName, '1.0.0');
const swiftInstallBase = path.join('/opt/swift', mangledName);
const swiftInstallBase = path.join('/opt/swift', versionIdentifier);
if (cachedVersion) {
core.info("Using cached version!");
await io.cp(cachedVersion, swiftInstallBase, { recursive: true });
Expand All @@ -113,9 +114,9 @@ async function main() {
}
if (swiftRelease) {
await core.group('Validating installation', async () => {
const version = await cmd(path.join(swiftInstallBase, '/usr/bin/swift'), ['--version']);
const version = await runCmd(path.join(swiftInstallBase, '/usr/bin/swift'), ['--version']);
if (!version.includes(swiftRelease)) {
core.setFailed(`Swift installation of version '${swiftRelease}' seems to have failed. 'swift --version' output: ${version}`);
throw new Error(`Swift installation of version '${swiftRelease}' seems to have failed. 'swift --version' output: ${version}`);
}
});
}
Expand Down
23 changes: 12 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fs from "fs";
import * as util from "util";
import * as path from "path";

async function cmd(cmd: string, args?: string[], failOnStdErr: boolean = true): Promise<string> {
async function runCmd(cmd: string, args?: string[], failOnStdErr: boolean = true): Promise<string> {
let stdOut = '';
await exec.exec(cmd, args, {
failOnStdErr: failOnStdErr,
Expand Down Expand Up @@ -36,15 +36,15 @@ async function install(installBase: string, branchName: string, versionTag: stri
});

await core.group('Verifying files', async () => {
await cmd('gpg', ['--import', allKeysFile], false);
await cmd('gpg', ['--verify', '--quiet', swiftSig, swiftPkg], false);
await runCmd('gpg', ['--import', allKeysFile], false);
await runCmd('gpg', ['--verify', '--quiet', swiftSig, swiftPkg], false);
});

await core.group('Unpacking files', async () => {
// We need to pass 'strip-components', so we cannot use 'tools.extractTar'
await cmd('tar', ['x', '--strip-components=1', '-C', installBase, '-f', swiftPkg]);
await runCmd('tar', ['x', '--strip-components=1', '-C', installBase, '-f', swiftPkg]);
// We need the -R option and want to simply add r (not knowing what the other permissions are), so we use the command line here.
await cmd('chmod', ['-R', 'o+r', path.join(installBase, '/usr/lib/swift')]);
await runCmd('chmod', ['-R', 'o+r', path.join(installBase, '/usr/lib/swift')]);

});

Expand Down Expand Up @@ -78,8 +78,8 @@ async function main() {

if (!skipApt) {
await core.group('Install dependencies', async () => {
await cmd('sudo', ['apt-get', '-q', 'update']);
await cmd('sudo', [
await runCmd('sudo', ['apt-get', '-q', 'update']);
await runCmd('sudo', [
'apt-get', '-q', 'install', '-y',
'libatomic1',
'libbsd0',
Expand All @@ -102,9 +102,10 @@ async function main() {
core.info("Skipping installation of dependencies...");
}

const mangledName = `swift.${swiftBranch}-${swiftVersion}-${swiftPlatform}`;
const versionIdentifier = `${swiftBranch}-${swiftVersion}-${swiftPlatform}`
const mangledName = `swift.${versionIdentifier}`;
const cachedVersion = tools.find(mangledName, '1.0.0');
const swiftInstallBase = path.join('/opt/swift', mangledName);
const swiftInstallBase = path.join('/opt/swift', versionIdentifier);
if (cachedVersion) {
core.info("Using cached version!");
await io.cp(cachedVersion, swiftInstallBase, { recursive: true });
Expand All @@ -115,9 +116,9 @@ async function main() {

if (swiftRelease) {
await core.group('Validating installation', async () => {
const version = await cmd(path.join(swiftInstallBase, '/usr/bin/swift'), ['--version']);
const version = await runCmd(path.join(swiftInstallBase, '/usr/bin/swift'), ['--version']);
if (!version.includes(swiftRelease)) {
core.setFailed(`Swift installation of version '${swiftRelease}' seems to have failed. 'swift --version' output: ${version}`);
throw new Error(`Swift installation of version '${swiftRelease}' seems to have failed. 'swift --version' output: ${version}`);
}
});
}
Expand Down

0 comments on commit a4698fb

Please sign in to comment.