-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release: v2 with new param and handle fails
- Loading branch information
1 parent
2a3c09c
commit 971bc48
Showing
7 changed files
with
126 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,75 @@ | ||
import { bumpedVersion } from "./helpers"; | ||
|
||
import { setOutput } from '@actions/core' | ||
import { readFile, writeFile } from 'fs' | ||
import { setOutput } from "@actions/core"; | ||
import { readFile, writeFile } from "fs"; | ||
import { Output } from "./types"; | ||
|
||
const versionCodeRegex = new RegExp(/^(\s*versionCode(?:\s|=)\s*)(\d+.*)/, "g"); | ||
const versionNameRegex = new RegExp(/(versionName(?:\s|=)*)(.*)/, "g"); | ||
|
||
const getVersionCodeLine = (versionCodeLine: string, versionCode: string | string[]) => { | ||
const forceVersionCode = parseInt(typeof versionCode === 'string' ? versionCode : versionCode?.[0]?.toString()) | ||
const versionCodeLineArray = versionCodeLine.split(' ') | ||
const currentVersionCode = parseInt(versionCodeLineArray.pop()) + 1 | ||
const nextVersionCode = forceVersionCode || currentVersionCode | ||
const getVersionCodeLine = ( | ||
versionCodeLine: string, | ||
versionCode: string | string[] | ||
) => { | ||
const forceVersionCode = parseInt( | ||
typeof versionCode === "string" ? versionCode : versionCode?.[0]?.toString() | ||
); | ||
const versionCodeLineArray = versionCodeLine.split(" "); | ||
const currentVersionCode = parseInt(versionCodeLineArray.pop()) + 1; | ||
const nextVersionCode = forceVersionCode || currentVersionCode; | ||
|
||
setOutput(Output.AndroidVersionCode, nextVersionCode) | ||
return `${versionCodeLineArray.join(' ')} ${nextVersionCode}` | ||
} | ||
setOutput(Output.AndroidVersionCode, nextVersionCode); | ||
return `${versionCodeLineArray.join(" ")} ${nextVersionCode}`; | ||
}; | ||
|
||
const getVersionNameLine = (versionNameLine: string, bumpType: string) => { | ||
const versionNameLineArray = versionNameLine.split(' ') | ||
const currentVersionName = versionNameLineArray.pop().replace(new RegExp('"', 'g'), '') | ||
const nextVersionName = bumpedVersion(currentVersionName, bumpType) | ||
|
||
setOutput(Output.AndroidVersion, nextVersionName) | ||
return `${versionNameLineArray.join(' ')} "${nextVersionName}"` | ||
} | ||
const versionNameLineArray = versionNameLine.split(" "); | ||
const currentVersionName = versionNameLineArray | ||
.pop() | ||
.replace(new RegExp('"', "g"), ""); | ||
const nextVersionName = bumpedVersion(currentVersionName, bumpType); | ||
|
||
setOutput(Output.AndroidVersion, nextVersionName); | ||
return `${versionNameLineArray.join(" ")} "${nextVersionName}"`; | ||
}; | ||
|
||
export function bumpAndroidValues({ androidPath, versionCode, bumpType }: { androidPath: string; versionCode: string; bumpType: string }) { | ||
const gradlePath = `${androidPath}/app/build.gradle` | ||
export function bumpAndroidValues({ | ||
version, | ||
androidPath, | ||
versionCode, | ||
bumpType, | ||
}: { | ||
version?: string; | ||
androidPath: string; | ||
versionCode: string; | ||
bumpType: string; | ||
}) { | ||
const gradlePath = `${androidPath}/app/build.gradle`; | ||
|
||
readFile(gradlePath, 'utf8', (_, data) => { | ||
const fileLines = data.split("\n") | ||
const versionCodeLineIndex = fileLines.findIndex(line => line.match(versionCodeRegex)) | ||
const versionNameLineIndex = fileLines.findIndex(line => line.match(versionNameRegex)) | ||
readFile(gradlePath, "utf8", (_, data) => { | ||
const fileLines = data.split("\n"); | ||
const versionCodeLineIndex = fileLines.findIndex((line) => | ||
line.match(versionCodeRegex) | ||
); | ||
const versionNameLineIndex = fileLines.findIndex((line) => | ||
line.match(versionNameRegex) | ||
); | ||
|
||
fileLines[versionCodeLineIndex] = getVersionCodeLine(fileLines[versionCodeLineIndex], versionCode) | ||
fileLines[versionNameLineIndex] = getVersionNameLine(fileLines[versionNameLineIndex], bumpType) | ||
if (versionCodeLineIndex > 0) { | ||
fileLines[versionCodeLineIndex] = getVersionCodeLine( | ||
fileLines[versionCodeLineIndex], | ||
versionCode | ||
); | ||
} | ||
if (versionNameLineIndex > 0 || version) { | ||
fileLines[versionNameLineIndex] = version || getVersionNameLine( | ||
fileLines[versionNameLineIndex], | ||
bumpType | ||
); | ||
} | ||
|
||
writeFile(gradlePath, fileLines.join("\n"), (error) => { if (error) throw error }) | ||
}) | ||
writeFile(gradlePath, fileLines.join("\n"), (error) => { | ||
if (error) throw error; | ||
}); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,51 @@ | ||
import { setOutput } from "@actions/core" | ||
import { getExecOutput } from "@actions/exec" | ||
import { bumpedVersion } from "./helpers" | ||
import { Output } from "./types" | ||
import { setOutput } from "@actions/core"; | ||
import { getExecOutput } from "@actions/exec"; | ||
import { bumpedVersion } from "./helpers"; | ||
import { Output } from "./types"; | ||
|
||
async function bumpIosVersion(path: string, bumpType: string) { | ||
const options = { cwd: path } | ||
const { stdout: currentIosVersion } = await getExecOutput("agvtool", ["what-marketing-version", "-terse1"], options) | ||
const version = bumpedVersion(currentIosVersion.toString().trim(), bumpType) | ||
async function bumpIosVersion(path: string, bumpType: string, version?: string) { | ||
const options = { cwd: path }; | ||
const { stdout: currentIosVersion } = await getExecOutput( | ||
"agvtool", | ||
["what-marketing-version", "-terse1"], | ||
options | ||
); | ||
const newVersion = version || bumpedVersion(currentIosVersion.toString().trim(), bumpType); | ||
|
||
const { stdout: iosVersion } = await getExecOutput("agvtool", ["new-marketing-version", version], options) | ||
setOutput(Output.IosVersion, iosVersion.toString().trim()) | ||
if (newVersion) { | ||
const { stdout: iosVersion } = await getExecOutput( | ||
"agvtool", | ||
["new-marketing-version", newVersion], | ||
options | ||
); | ||
setOutput(Output.IosVersion, iosVersion.toString().trim()); | ||
} else { | ||
console.log("No version found for path:", path); | ||
} | ||
} | ||
|
||
async function bumpBuildNumber(path: string, buildNumber?: string) { | ||
const params = buildNumber ? ["new-version", "-all", buildNumber] : ["next-version", "-all"] | ||
const { stdout: iosBuildNumber } = await getExecOutput("agvtool", params, { cwd: path }) | ||
const params = buildNumber | ||
? ["new-version", "-all", buildNumber] | ||
: ["next-version", "-all"]; | ||
const { stdout: iosBuildNumber } = await getExecOutput("agvtool", params, { | ||
cwd: path, | ||
}); | ||
|
||
setOutput(Output.IosBuildNumber, iosBuildNumber.toString().trim()) | ||
setOutput(Output.IosBuildNumber, iosBuildNumber.toString().trim()); | ||
} | ||
|
||
export function bumpIosValues({ iosPath, buildNumber, bumpType }: { iosPath: string; buildNumber?: string; bumpType: string }) { | ||
bumpIosVersion(iosPath, bumpType) | ||
bumpBuildNumber(iosPath, buildNumber) | ||
export function bumpIosValues({ | ||
version, | ||
iosPath, | ||
buildNumber, | ||
bumpType, | ||
}: { | ||
version?: string; | ||
iosPath: string; | ||
buildNumber?: string; | ||
bumpType: string; | ||
}) { | ||
bumpIosVersion(iosPath, bumpType, version); | ||
bumpBuildNumber(iosPath, buildNumber); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters