Skip to content

Commit b3b663d

Browse files
author
Maxim Lobanov
committed
Update logic to handle errors
1 parent 4cfe03c commit b3b663d

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ jobs:
3838
- name: Validate version
3939
run: pod --version | grep "1.5.3"
4040

41+
version-already-installed:
42+
name: valid version - already installed
43+
runs-on: macos-latest
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v2
47+
48+
- name: Remove pre-installed version
49+
run: gem uninstall cocoapods --all --executables
50+
51+
- name: Install needed version
52+
run: gem install cocoapods -v 1.8.1
53+
54+
- name: setup-cocoapods
55+
uses: ./
56+
with:
57+
version: 1.8.1
58+
59+
- name: Validate version
60+
run: pod --version | grep "1.8.1"
61+
4162
version-latest:
4263
name: latest version
4364
runs-on: macos-latest

dist/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ class CocoapodsInstaller {
15111511
core.info(`Cocoapods ${versionSpec} has already installed. Not needed to re-install.`);
15121512
return;
15131513
}
1514-
const uninstallExitCode = await exec.exec("gem", ["uninstall", "cocoapods", "--all", "--executables"]);
1514+
const uninstallExitCode = await exec.exec("gem", ["uninstall", "cocoapods", "--all", "--executables"]).catch(error => error);
15151515
if (uninstallExitCode !== 0) {
15161516
core.info("Error during deleting existing version of cocoapods");
15171517
}
@@ -1539,7 +1539,7 @@ class CocoapodsInstaller {
15391539
}
15401540
}
15411541
};
1542-
const exitCode = await exec.exec("pod", ["--version"], options);
1542+
const exitCode = await exec.exec("pod", ["--version"], options).catch(error => error);
15431543
if (exitCode === 0 && stdOutput) {
15441544
return stdOutput.trim();
15451545
}

src/installer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "fs";
2-
import * as path from 'path';
2+
import * as path from "path";
33
import { EOL } from "os";
4-
import * as exec from '@actions/exec';
4+
import * as exec from "@actions/exec";
55
import * as core from "@actions/core";
66
import { ExecOptions } from "@actions/exec/lib/interfaces";
77

@@ -13,7 +13,7 @@ export class CocoapodsInstaller {
1313
return;
1414
}
1515

16-
const uninstallExitCode = await exec.exec("gem", ["uninstall", "cocoapods", "--all", "--executables"]);
16+
const uninstallExitCode = await exec.exec("gem", ["uninstall", "cocoapods", "--all", "--executables"]).catch(error => error);
1717
if (uninstallExitCode !== 0) {
1818
core.info("Error during deleting existing version of cocoapods");
1919
}
@@ -30,7 +30,7 @@ export class CocoapodsInstaller {
3030
const absolutePath = path.resolve(podfilePath);
3131

3232
if (!fs.existsSync(absolutePath)) {
33-
throw new Error(`podfile is not found on path '${absolutePath}'`)
33+
throw new Error(`podfile is not found on path '${absolutePath}'`);
3434
}
3535

3636
const fileContent = fs.readFileSync(absolutePath);
@@ -42,13 +42,13 @@ export class CocoapodsInstaller {
4242
let stdOutput = "";
4343
const options: ExecOptions = {
4444
listeners: {
45-
stdout: (data: Buffer) => {
45+
stdout: (data: Buffer): void => {
4646
stdOutput += data.toString();
4747
}
4848
}
4949
};
5050

51-
const exitCode = await exec.exec("pod", ["--version"], options);
51+
const exitCode = await exec.exec("pod", ["--version"], options).catch(error => error);
5252
if (exitCode === 0 && stdOutput) {
5353
return stdOutput.trim();
5454
}

src/setup-cocoapods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const run = async (): Promise<void> => {
1111
const podfilePathInput = core.getInput("podfile-path", { required: false });
1212

1313
if (!!versionInput === !!podfilePathInput) {
14-
throw new Error("Invalid input parameters. Only 'version' or 'podfile-path' should be defined")
14+
throw new Error("Invalid input parameters. Only 'version' or 'podfile-path' should be defined");
1515
}
1616

1717
const versionSpec = versionInput || CocoapodsInstaller.getVersionFromPodfile(podfilePathInput);

0 commit comments

Comments
 (0)