Skip to content

Commit

Permalink
Merge pull request #8 from maxim-lobanov/support-preview-versions
Browse files Browse the repository at this point in the history
Add support for prerelease versions
  • Loading branch information
maxim-lobanov authored Oct 10, 2020
2 parents fea4cbe + ea5c044 commit 48d40c8
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 83 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- cron: 0 0 * * *

jobs:
version-with-preinstalled:
replace-pre-installed:
name: replace pre-installed version
runs-on: macos-latest
steps:
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Validate version
run: pod --version | grep "1.9.0"

version-without-preinstalled:
install-on-clean-machine:
name: install on clean machine
runs-on: macos-latest
steps:
Expand Down Expand Up @@ -77,8 +77,8 @@ jobs:
- name: Validate version
run: pod --version

podfile:
name: install version from podfile.lock
podfile-stable:
name: install stable version from podfile.lock
runs-on: macos-latest
steps:
- name: Checkout
Expand All @@ -98,15 +98,30 @@ jobs:
podfile-path: __tests__/podfile-example/Podfile2.lock

- name: Validate version
run: pod --version | grep "1.3.1"
run: pod --version | grep "1.9.3"

podfile-preview:
name: install stable version from podfile.lock
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: setup-cocoapods
uses: ./
with:
podfile-path: __tests__/podfile-example/Podfile3.lock

- name: Validate version
run: pod --version | grep "1.9.1"
run: pod --version | grep "1.10.0.rc.1"

- name: setup-cocoapods
uses: ./
with:
podfile-path: __tests__/podfile-example/Podfile4.lock

- name: Validate version
run: pod --version | grep "1.9.0.beta.2"

ubuntu-install:
name: install cocoapods on ubuntu
Expand Down
17 changes: 0 additions & 17 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from "path";
import * as exec from "@actions/exec";
import { CocoapodsInstaller } from "../src/installer";

Expand Down Expand Up @@ -30,20 +29,4 @@ describe("CocoapodsInstaller", () => {
expect(execCommandSpy).toHaveBeenCalledTimes(0);
});
});

describe("getVersionFromPodfile", () => {
it.each([
["Podfile.lock", "1.5.3"],
["Podfile2.lock", "1.3.1"],
["Podfile3.lock", "1.9.1"],
["Podfile4.lock", null]
])("test case %#", (input: string, expected: string | null) => {
const testCasePath = path.resolve(path.join(__dirname, "podfile-example", input));
if (expected) {
expect(CocoapodsInstaller.getVersionFromPodfile(testCasePath)).toBe(expected);
} else {
expect(() => CocoapodsInstaller.getVersionFromPodfile(testCasePath)).toThrow();
}
});
});
});
20 changes: 9 additions & 11 deletions __tests__/podfile-example/Podfile2.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
PODS:
- Bond (6.2.10):
- Diff (~> 0.4)
- ReactiveKit (~> 3.6.0)
- Diff (0.5.3)
- ReactiveKit (3.6.0)
- Alamofire (4.8.2)

DEPENDENCIES:
- Bond
- Alamofire

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Alamofire

SPEC CHECKSUMS:
Bond: 8bafdefda68c4f525c9a751b60ef827b0548ef3c
Diff: befa1d19c32726b2b36ce915d98793e2fbde8dcc
ReactiveKit: b3037cb797aa79b58964d309cd724611bea033e6
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3

PODFILE CHECKSUM: f0549efd571fb0d6e3b9828ef306c31ce0bfa0d0
PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1

COCOAPODS: 1.3.1
COCOAPODS: 1.9.3
2 changes: 1 addition & 1 deletion __tests__/podfile-example/Podfile3.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1

COCOAPODS: 1.9.1
COCOAPODS: 1.10.0.rc.1
4 changes: 3 additions & 1 deletion __tests__/podfile-example/Podfile4.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ SPEC REPOS:
SPEC CHECKSUMS:
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3

PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1
PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1

COCOAPODS: 1.9.0.beta.2
14 changes: 14 additions & 0 deletions __tests__/podfile-example/Podfile5.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PODS:
- Alamofire (4.8.2)

DEPENDENCIES:
- Alamofire

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Alamofire

SPEC CHECKSUMS:
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3

PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1
32 changes: 32 additions & 0 deletions __tests__/podfile-parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as path from "path";
import { getVersionFromPodfile, getVersionFromPodfileLine } from "../src/podfile-parser";

describe("getVersionFromPodfile", () => {
it.each([
["Podfile.lock", "1.5.3"],
["Podfile2.lock", "1.9.3"],
["Podfile3.lock", "1.10.0.rc.1"],
["Podfile4.lock", "1.9.0.beta.2"],
["Podfile5.lock", null]
])("test case %#", (input: string, expected: string | null) => {
const testCasePath = path.resolve(path.join(__dirname, "podfile-example", input));
if (expected) {
expect(getVersionFromPodfile(testCasePath)).toBe(expected);
} else {
expect(() => getVersionFromPodfile(testCasePath)).toThrow();
}
});
});

describe("getVersionFromPodfileLine", () => {
it.each([
["COCOAPODS: 1.5.3", "1.5.3"],
["COCOAPODS: 1.9.1", "1.9.1"],
["COCOAPODS: 1.10.0.rc.1", "1.10.0.rc.1"],
["COCOAPODS: 1.8.0.beta.2", "1.8.0.beta.2"],
["COCOAPODS: 1.7.0.beta.1", "1.7.0.beta.1"],
])("%s -> %s", (input: string, expected: string) => {
const matchedVersion = getVersionFromPodfileLine(input);
expect(matchedVersion).toBe(expected);
});
});
80 changes: 59 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,62 @@ exports.issueCommand = issueCommand;

module.exports = require("child_process");

/***/ }),

/***/ 335:
/***/ (function(__unusedmodule, exports, __webpack_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getVersionFromPodfile = exports.getVersionFromPodfileLine = void 0;
const fs = __importStar(__webpack_require__(747));
const path = __importStar(__webpack_require__(622));
const os_1 = __webpack_require__(87);
const podVersionRegex = /^COCOAPODS: ([\d.]+(beta|rc)?\.?\d*)$/i;
exports.getVersionFromPodfileLine = (line) => {
const match = line.match(podVersionRegex);
if (match && match.length >= 2) {
return match[1].trim();
}
return null;
};
exports.getVersionFromPodfile = (podfilePath) => {
const absolutePath = path.resolve(podfilePath);
if (!fs.existsSync(absolutePath)) {
throw new Error(`Podfile is not found on path '${absolutePath}'`);
}
const fileContent = fs.readFileSync(absolutePath);
const podLines = fileContent.toString().split(os_1.EOL);
for (const podLine of podLines) {
const matchedVersion = exports.getVersionFromPodfileLine(podLine);
if (matchedVersion) {
return matchedVersion;
}
}
throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
};


/***/ }),

/***/ 357:
Expand Down Expand Up @@ -1623,9 +1679,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CocoapodsInstaller = void 0;
const fs = __importStar(__webpack_require__(747));
const path = __importStar(__webpack_require__(622));
const os_1 = __webpack_require__(87);
const exec = __importStar(__webpack_require__(986));
const core = __importStar(__webpack_require__(470));
class CocoapodsInstaller {
Expand All @@ -1643,21 +1696,6 @@ class CocoapodsInstaller {
await exec.exec("gem", ["install", "cocoapods", ...versionArguments, "--no-document"]);
core.info(`Cocoapods ${versionSpec} has been installed successfully`);
}
static getVersionFromPodfile(podfilePath) {
const absolutePath = path.resolve(podfilePath);
if (!fs.existsSync(absolutePath)) {
throw new Error(`Podfile is not found on path '${absolutePath}'`);
}
const fileContent = fs.readFileSync(absolutePath);
const podLines = fileContent.toString().split(os_1.EOL);
for (const podLine of podLines) {
const match = podLine.match(this.podVersionRegex);
if (match && match.length >= 2) {
return match[1].trim();
}
}
throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
}
static async getInstalledVersion() {
let stdOutput = "";
const options = {
Expand All @@ -1675,7 +1713,6 @@ class CocoapodsInstaller {
}
}
exports.CocoapodsInstaller = CocoapodsInstaller;
CocoapodsInstaller.podVersionRegex = /^COCOAPODS: ([\d.]+)$/i;


/***/ }),
Expand Down Expand Up @@ -1707,6 +1744,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const installer_1 = __webpack_require__(749);
const podfile_parser_1 = __webpack_require__(335);
const run = async () => {
try {
if (process.platform !== "darwin" && process.platform !== "linux") {
Expand All @@ -1715,11 +1753,11 @@ const run = async () => {
let versionSpec = core.getInput("version", { required: false });
const podfilePath = core.getInput("podfile-path", { required: false });
if (!!versionSpec === !!podfilePath) {
throw new Error("Invalid input parameters usage. Only 'version' or 'podfile-path' should be defined");
throw new Error("Invalid input parameters usage. Either 'version' or 'podfile-path' should be specified. Not the both ones.");
}
if (!versionSpec) {
core.debug("Reading Podfile to determine the version of Cocoapods...");
versionSpec = installer_1.CocoapodsInstaller.getVersionFromPodfile(podfilePath);
versionSpec = podfile_parser_1.getVersionFromPodfile(podfilePath);
core.info(`Podfile points to the Cocoapods ${versionSpec}`);
}
await installer_1.CocoapodsInstaller.install(versionSpec);
Expand Down
24 changes: 0 additions & 24 deletions src/installer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import * as fs from "fs";
import * as path from "path";
import { EOL } from "os";
import * as exec from "@actions/exec";
import * as core from "@actions/core";
import { ExecOptions } from "@actions/exec/lib/interfaces";

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

public static getVersionFromPodfile(podfilePath: string): string {
const absolutePath = path.resolve(podfilePath);

if (!fs.existsSync(absolutePath)) {
throw new Error(`Podfile is not found on path '${absolutePath}'`);
}

const fileContent = fs.readFileSync(absolutePath);
const podLines = fileContent.toString().split(EOL);

for (const podLine of podLines) {
const match = podLine.match(this.podVersionRegex);
if (match && match.length >= 2) {
return match[1].trim();
}
}

throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
}

private static async getInstalledVersion(): Promise<string | null> {
let stdOutput = "";
const options: ExecOptions = {
Expand Down
35 changes: 35 additions & 0 deletions src/podfile-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as fs from "fs";
import * as path from "path";
import { EOL } from "os";

const podVersionRegex = /^COCOAPODS: ([\d.]+(beta|rc)?\.?\d*)$/i;

export const getVersionFromPodfileLine = (line: string): string | null => {
const match = line.match(podVersionRegex);
if (match && match.length >= 2) {
return match[1].trim();
}

return null;
};

export const getVersionFromPodfile = (podfilePath: string): string => {
const absolutePath = path.resolve(podfilePath);

if (!fs.existsSync(absolutePath)) {
throw new Error(`Podfile is not found on path '${absolutePath}'`);
}

const fileContent = fs.readFileSync(absolutePath);
const podLines = fileContent.toString().split(EOL);

for (const podLine of podLines) {
const matchedVersion = getVersionFromPodfileLine(podLine);
if (matchedVersion) {
return matchedVersion;
}
}

throw new Error(`Podfile '${absolutePath}' doesn't contain COCOAPODS version.`);
};

Loading

0 comments on commit 48d40c8

Please sign in to comment.