diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7018538..789f1f0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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: @@ -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 @@ -98,7 +98,14 @@ 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: ./ @@ -106,7 +113,15 @@ jobs: 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 diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 42719dd..b9d7e80 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -1,4 +1,3 @@ -import * as path from "path"; import * as exec from "@actions/exec"; import { CocoapodsInstaller } from "../src/installer"; @@ -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(); - } - }); - }); }); \ No newline at end of file diff --git a/__tests__/podfile-example/Podfile2.lock b/__tests__/podfile-example/Podfile2.lock index becd371..fc8b2fe 100644 --- a/__tests__/podfile-example/Podfile2.lock +++ b/__tests__/podfile-example/Podfile2.lock @@ -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 \ No newline at end of file +COCOAPODS: 1.9.3 \ No newline at end of file diff --git a/__tests__/podfile-example/Podfile3.lock b/__tests__/podfile-example/Podfile3.lock index 9b2c4ab..a05a5d5 100644 --- a/__tests__/podfile-example/Podfile3.lock +++ b/__tests__/podfile-example/Podfile3.lock @@ -13,4 +13,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1 -COCOAPODS: 1.9.1 \ No newline at end of file +COCOAPODS: 1.10.0.rc.1 \ No newline at end of file diff --git a/__tests__/podfile-example/Podfile4.lock b/__tests__/podfile-example/Podfile4.lock index 7b7c538..4b30c9c 100644 --- a/__tests__/podfile-example/Podfile4.lock +++ b/__tests__/podfile-example/Podfile4.lock @@ -11,4 +11,6 @@ SPEC REPOS: SPEC CHECKSUMS: Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3 -PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1 \ No newline at end of file +PODFILE CHECKSUM: 6e25dc1d1d6302e538a09a3e0120a572a5fbd5d1 + +COCOAPODS: 1.9.0.beta.2 \ No newline at end of file diff --git a/__tests__/podfile-example/Podfile5.lock b/__tests__/podfile-example/Podfile5.lock new file mode 100644 index 0000000..7b7c538 --- /dev/null +++ b/__tests__/podfile-example/Podfile5.lock @@ -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 \ No newline at end of file diff --git a/__tests__/podfile-parser.test.ts b/__tests__/podfile-parser.test.ts new file mode 100644 index 0000000..53af41f --- /dev/null +++ b/__tests__/podfile-parser.test.ts @@ -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); + }); +}); \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 414c50b..ebe7c88 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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: @@ -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 { @@ -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 = { @@ -1675,7 +1713,6 @@ class CocoapodsInstaller { } } exports.CocoapodsInstaller = CocoapodsInstaller; -CocoapodsInstaller.podVersionRegex = /^COCOAPODS: ([\d.]+)$/i; /***/ }), @@ -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") { @@ -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); diff --git a/src/installer.ts b/src/installer.ts index 0a73283..4fa4350 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -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 { // Checking pre-installed version of Cocoapods const installedVersion = await this.getInstalledVersion(); @@ -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 { let stdOutput = ""; const options: ExecOptions = { diff --git a/src/podfile-parser.ts b/src/podfile-parser.ts new file mode 100644 index 0000000..1e36433 --- /dev/null +++ b/src/podfile-parser.ts @@ -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.`); +}; + diff --git a/src/setup-cocoapods.ts b/src/setup-cocoapods.ts index ebc5a2e..7c7a5bd 100644 --- a/src/setup-cocoapods.ts +++ b/src/setup-cocoapods.ts @@ -1,5 +1,6 @@ import * as core from "@actions/core"; import { CocoapodsInstaller } from "./installer"; +import { getVersionFromPodfile } from "./podfile-parser"; const run = async (): Promise => { try { @@ -11,12 +12,12 @@ const run = async (): Promise => { 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 = CocoapodsInstaller.getVersionFromPodfile(podfilePath); + versionSpec = getVersionFromPodfile(podfilePath); core.info(`Podfile points to the Cocoapods ${versionSpec}`); }