Skip to content

Commit ea5c044

Browse files
author
Maxim Lobanov
committed
update regex to support preview versions
1 parent fea4cbe commit ea5c044

File tree

11 files changed

+177
-83
lines changed

11 files changed

+177
-83
lines changed

Diff for: .github/workflows/test.yml

+21-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- cron: 0 0 * * *
99

1010
jobs:
11-
version-with-preinstalled:
11+
replace-pre-installed:
1212
name: replace pre-installed version
1313
runs-on: macos-latest
1414
steps:
@@ -23,7 +23,7 @@ jobs:
2323
- name: Validate version
2424
run: pod --version | grep "1.9.0"
2525

26-
version-without-preinstalled:
26+
install-on-clean-machine:
2727
name: install on clean machine
2828
runs-on: macos-latest
2929
steps:
@@ -77,8 +77,8 @@ jobs:
7777
- name: Validate version
7878
run: pod --version
7979

80-
podfile:
81-
name: install version from podfile.lock
80+
podfile-stable:
81+
name: install stable version from podfile.lock
8282
runs-on: macos-latest
8383
steps:
8484
- name: Checkout
@@ -98,15 +98,30 @@ jobs:
9898
podfile-path: __tests__/podfile-example/Podfile2.lock
9999

100100
- name: Validate version
101-
run: pod --version | grep "1.3.1"
101+
run: pod --version | grep "1.9.3"
102+
103+
podfile-preview:
104+
name: install stable version from podfile.lock
105+
runs-on: macos-latest
106+
steps:
107+
- name: Checkout
108+
uses: actions/checkout@v2
102109

103110
- name: setup-cocoapods
104111
uses: ./
105112
with:
106113
podfile-path: __tests__/podfile-example/Podfile3.lock
107114

108115
- name: Validate version
109-
run: pod --version | grep "1.9.1"
116+
run: pod --version | grep "1.10.0.rc.1"
117+
118+
- name: setup-cocoapods
119+
uses: ./
120+
with:
121+
podfile-path: __tests__/podfile-example/Podfile4.lock
122+
123+
- name: Validate version
124+
run: pod --version | grep "1.9.0.beta.2"
110125

111126
ubuntu-install:
112127
name: install cocoapods on ubuntu

Diff for: __tests__/installer.test.ts

-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as path from "path";
21
import * as exec from "@actions/exec";
32
import { CocoapodsInstaller } from "../src/installer";
43

@@ -30,20 +29,4 @@ describe("CocoapodsInstaller", () => {
3029
expect(execCommandSpy).toHaveBeenCalledTimes(0);
3130
});
3231
});
33-
34-
describe("getVersionFromPodfile", () => {
35-
it.each([
36-
["Podfile.lock", "1.5.3"],
37-
["Podfile2.lock", "1.3.1"],
38-
["Podfile3.lock", "1.9.1"],
39-
["Podfile4.lock", null]
40-
])("test case %#", (input: string, expected: string | null) => {
41-
const testCasePath = path.resolve(path.join(__dirname, "podfile-example", input));
42-
if (expected) {
43-
expect(CocoapodsInstaller.getVersionFromPodfile(testCasePath)).toBe(expected);
44-
} else {
45-
expect(() => CocoapodsInstaller.getVersionFromPodfile(testCasePath)).toThrow();
46-
}
47-
});
48-
});
4932
});

Diff for: __tests__/podfile-example/Podfile2.lock

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
PODS:
2-
- Bond (6.2.10):
3-
- Diff (~> 0.4)
4-
- ReactiveKit (~> 3.6.0)
5-
- Diff (0.5.3)
6-
- ReactiveKit (3.6.0)
2+
- Alamofire (4.8.2)
73

84
DEPENDENCIES:
9-
- Bond
5+
- Alamofire
6+
7+
SPEC REPOS:
8+
https://github.com/cocoapods/specs.git:
9+
- Alamofire
1010

1111
SPEC CHECKSUMS:
12-
Bond: 8bafdefda68c4f525c9a751b60ef827b0548ef3c
13-
Diff: befa1d19c32726b2b36ce915d98793e2fbde8dcc
14-
ReactiveKit: b3037cb797aa79b58964d309cd724611bea033e6
12+
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3
1513

16-
PODFILE CHECKSUM: f0549efd571fb0d6e3b9828ef306c31ce0bfa0d0
14+
PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1
1715

18-
COCOAPODS: 1.3.1
16+
COCOAPODS: 1.9.3

Diff for: __tests__/podfile-example/Podfile3.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ SPEC CHECKSUMS:
1313

1414
PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1
1515

16-
COCOAPODS: 1.9.1
16+
COCOAPODS: 1.10.0.rc.1

Diff for: __tests__/podfile-example/Podfile4.lock

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ SPEC REPOS:
1111
SPEC CHECKSUMS:
1212
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3
1313

14-
PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1
14+
PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1
15+
16+
COCOAPODS: 1.9.0.beta.2

Diff for: __tests__/podfile-example/Podfile5.lock

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
PODS:
2+
- Alamofire (4.8.2)
3+
4+
DEPENDENCIES:
5+
- Alamofire
6+
7+
SPEC REPOS:
8+
https://github.com/cocoapods/specs.git:
9+
- Alamofire
10+
11+
SPEC CHECKSUMS:
12+
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3
13+
14+
PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1

Diff for: __tests__/podfile-parser.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as path from "path";
2+
import { getVersionFromPodfile, getVersionFromPodfileLine } from "../src/podfile-parser";
3+
4+
describe("getVersionFromPodfile", () => {
5+
it.each([
6+
["Podfile.lock", "1.5.3"],
7+
["Podfile2.lock", "1.9.3"],
8+
["Podfile3.lock", "1.10.0.rc.1"],
9+
["Podfile4.lock", "1.9.0.beta.2"],
10+
["Podfile5.lock", null]
11+
])("test case %#", (input: string, expected: string | null) => {
12+
const testCasePath = path.resolve(path.join(__dirname, "podfile-example", input));
13+
if (expected) {
14+
expect(getVersionFromPodfile(testCasePath)).toBe(expected);
15+
} else {
16+
expect(() => getVersionFromPodfile(testCasePath)).toThrow();
17+
}
18+
});
19+
});
20+
21+
describe("getVersionFromPodfileLine", () => {
22+
it.each([
23+
["COCOAPODS: 1.5.3", "1.5.3"],
24+
["COCOAPODS: 1.9.1", "1.9.1"],
25+
["COCOAPODS: 1.10.0.rc.1", "1.10.0.rc.1"],
26+
["COCOAPODS: 1.8.0.beta.2", "1.8.0.beta.2"],
27+
["COCOAPODS: 1.7.0.beta.1", "1.7.0.beta.1"],
28+
])("%s -> %s", (input: string, expected: string) => {
29+
const matchedVersion = getVersionFromPodfileLine(input);
30+
expect(matchedVersion).toBe(expected);
31+
});
32+
});

Diff for: dist/index.js

+59-21
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,62 @@ exports.issueCommand = issueCommand;
10271027

10281028
module.exports = require("child_process");
10291029

1030+
/***/ }),
1031+
1032+
/***/ 335:
1033+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
1034+
1035+
"use strict";
1036+
1037+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1038+
if (k2 === undefined) k2 = k;
1039+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1040+
}) : (function(o, m, k, k2) {
1041+
if (k2 === undefined) k2 = k;
1042+
o[k2] = m[k];
1043+
}));
1044+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1045+
Object.defineProperty(o, "default", { enumerable: true, value: v });
1046+
}) : function(o, v) {
1047+
o["default"] = v;
1048+
});
1049+
var __importStar = (this && this.__importStar) || function (mod) {
1050+
if (mod && mod.__esModule) return mod;
1051+
var result = {};
1052+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1053+
__setModuleDefault(result, mod);
1054+
return result;
1055+
};
1056+
Object.defineProperty(exports, "__esModule", { value: true });
1057+
exports.getVersionFromPodfile = exports.getVersionFromPodfileLine = void 0;
1058+
const fs = __importStar(__webpack_require__(747));
1059+
const path = __importStar(__webpack_require__(622));
1060+
const os_1 = __webpack_require__(87);
1061+
const podVersionRegex = /^COCOAPODS: ([\d.]+(beta|rc)?\.?\d*)$/i;
1062+
exports.getVersionFromPodfileLine = (line) => {
1063+
const match = line.match(podVersionRegex);
1064+
if (match && match.length >= 2) {
1065+
return match[1].trim();
1066+
}
1067+
return null;
1068+
};
1069+
exports.getVersionFromPodfile = (podfilePath) => {
1070+
const absolutePath = path.resolve(podfilePath);
1071+
if (!fs.existsSync(absolutePath)) {
1072+
throw new Error(`Podfile is not found on path '${absolutePath}'`);
1073+
}
1074+
const fileContent = fs.readFileSync(absolutePath);
1075+
const podLines = fileContent.toString().split(os_1.EOL);
1076+
for (const podLine of podLines) {
1077+
const matchedVersion = exports.getVersionFromPodfileLine(podLine);
1078+
if (matchedVersion) {
1079+
return matchedVersion;
1080+
}
1081+
}
1082+
throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
1083+
};
1084+
1085+
10301086
/***/ }),
10311087

10321088
/***/ 357:
@@ -1623,9 +1679,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
16231679
};
16241680
Object.defineProperty(exports, "__esModule", { value: true });
16251681
exports.CocoapodsInstaller = void 0;
1626-
const fs = __importStar(__webpack_require__(747));
1627-
const path = __importStar(__webpack_require__(622));
1628-
const os_1 = __webpack_require__(87);
16291682
const exec = __importStar(__webpack_require__(986));
16301683
const core = __importStar(__webpack_require__(470));
16311684
class CocoapodsInstaller {
@@ -1643,21 +1696,6 @@ class CocoapodsInstaller {
16431696
await exec.exec("gem", ["install", "cocoapods", ...versionArguments, "--no-document"]);
16441697
core.info(`Cocoapods ${versionSpec} has been installed successfully`);
16451698
}
1646-
static getVersionFromPodfile(podfilePath) {
1647-
const absolutePath = path.resolve(podfilePath);
1648-
if (!fs.existsSync(absolutePath)) {
1649-
throw new Error(`Podfile is not found on path '${absolutePath}'`);
1650-
}
1651-
const fileContent = fs.readFileSync(absolutePath);
1652-
const podLines = fileContent.toString().split(os_1.EOL);
1653-
for (const podLine of podLines) {
1654-
const match = podLine.match(this.podVersionRegex);
1655-
if (match && match.length >= 2) {
1656-
return match[1].trim();
1657-
}
1658-
}
1659-
throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
1660-
}
16611699
static async getInstalledVersion() {
16621700
let stdOutput = "";
16631701
const options = {
@@ -1675,7 +1713,6 @@ class CocoapodsInstaller {
16751713
}
16761714
}
16771715
exports.CocoapodsInstaller = CocoapodsInstaller;
1678-
CocoapodsInstaller.podVersionRegex = /^COCOAPODS: ([\d.]+)$/i;
16791716

16801717

16811718
/***/ }),
@@ -1707,6 +1744,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
17071744
Object.defineProperty(exports, "__esModule", { value: true });
17081745
const core = __importStar(__webpack_require__(470));
17091746
const installer_1 = __webpack_require__(749);
1747+
const podfile_parser_1 = __webpack_require__(335);
17101748
const run = async () => {
17111749
try {
17121750
if (process.platform !== "darwin" && process.platform !== "linux") {
@@ -1715,11 +1753,11 @@ const run = async () => {
17151753
let versionSpec = core.getInput("version", { required: false });
17161754
const podfilePath = core.getInput("podfile-path", { required: false });
17171755
if (!!versionSpec === !!podfilePath) {
1718-
throw new Error("Invalid input parameters usage. Only 'version' or 'podfile-path' should be defined");
1756+
throw new Error("Invalid input parameters usage. Either 'version' or 'podfile-path' should be specified. Not the both ones.");
17191757
}
17201758
if (!versionSpec) {
17211759
core.debug("Reading Podfile to determine the version of Cocoapods...");
1722-
versionSpec = installer_1.CocoapodsInstaller.getVersionFromPodfile(podfilePath);
1760+
versionSpec = podfile_parser_1.getVersionFromPodfile(podfilePath);
17231761
core.info(`Podfile points to the Cocoapods ${versionSpec}`);
17241762
}
17251763
await installer_1.CocoapodsInstaller.install(versionSpec);

Diff for: src/installer.ts

-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import * as fs from "fs";
2-
import * as path from "path";
3-
import { EOL } from "os";
41
import * as exec from "@actions/exec";
52
import * as core from "@actions/core";
63
import { ExecOptions } from "@actions/exec/lib/interfaces";
74

85
export class CocoapodsInstaller {
9-
private static podVersionRegex = /^COCOAPODS: ([\d.]+)$/i;
106
public static async install(versionSpec: string): Promise<void> {
117
// Checking pre-installed version of Cocoapods
128
const installedVersion = await this.getInstalledVersion();
@@ -25,26 +21,6 @@ export class CocoapodsInstaller {
2521
core.info(`Cocoapods ${versionSpec} has been installed successfully`);
2622
}
2723

28-
public static getVersionFromPodfile(podfilePath: string): string {
29-
const absolutePath = path.resolve(podfilePath);
30-
31-
if (!fs.existsSync(absolutePath)) {
32-
throw new Error(`Podfile is not found on path '${absolutePath}'`);
33-
}
34-
35-
const fileContent = fs.readFileSync(absolutePath);
36-
const podLines = fileContent.toString().split(EOL);
37-
38-
for (const podLine of podLines) {
39-
const match = podLine.match(this.podVersionRegex);
40-
if (match && match.length >= 2) {
41-
return match[1].trim();
42-
}
43-
}
44-
45-
throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
46-
}
47-
4824
private static async getInstalledVersion(): Promise<string | null> {
4925
let stdOutput = "";
5026
const options: ExecOptions = {

Diff for: src/podfile-parser.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
import { EOL } from "os";
4+
5+
const podVersionRegex = /^COCOAPODS: ([\d.]+(beta|rc)?\.?\d*)$/i;
6+
7+
export const getVersionFromPodfileLine = (line: string): string | null => {
8+
const match = line.match(podVersionRegex);
9+
if (match && match.length >= 2) {
10+
return match[1].trim();
11+
}
12+
13+
return null;
14+
};
15+
16+
export const getVersionFromPodfile = (podfilePath: string): string => {
17+
const absolutePath = path.resolve(podfilePath);
18+
19+
if (!fs.existsSync(absolutePath)) {
20+
throw new Error(`Podfile is not found on path '${absolutePath}'`);
21+
}
22+
23+
const fileContent = fs.readFileSync(absolutePath);
24+
const podLines = fileContent.toString().split(EOL);
25+
26+
for (const podLine of podLines) {
27+
const matchedVersion = getVersionFromPodfileLine(podLine);
28+
if (matchedVersion) {
29+
return matchedVersion;
30+
}
31+
}
32+
33+
throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
34+
};
35+

0 commit comments

Comments
 (0)