-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
655a2ed
commit cd5948e
Showing
2 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: "Release: Manage Versions" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
HandleVersionChange: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run script | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const script = require('./version-handling') | ||
script({ github, context, core }) | ||
- name: Commit changes | ||
id: commit_changes | ||
uses: EndBug/[email protected] | ||
with: | ||
add: "./Echo.xcodeproj/project.pbxproj" | ||
message: "[AUTO RELEASE]" |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const getNewVersion = (currentVersion, commit) => { | ||
const [major, minor, patch] = currentVersion.split("."); | ||
|
||
if (commit.includes("[PATCH]")) { | ||
return `${major}.${minor}.${parseInt(patch) + 1}`; | ||
} else if (commit.includes("[MINOR]")) { | ||
return `${major}.${parseInt(minor) + 1}.${0}`; | ||
} else if (commit.includes("[MAJOR]")) { | ||
return `${parseInt(major) + 1}.${0}.${0}`; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
module.exports = ({ github, context, core }) => { | ||
const commit = context.payload.commits.map((x) => x.message).join(" = "); | ||
|
||
console.log("Commit message:", commit); | ||
|
||
const projectFilePath = path.join( | ||
__dirname, | ||
"./DragToSpeak.xcodeproj/project.pbxproj" | ||
); | ||
|
||
console.log(`Getting project file: ${projectFilePath}`); | ||
|
||
const contents = fs | ||
.readFileSync(projectFilePath, { | ||
encoding: "utf8", | ||
}) | ||
.toString(); | ||
|
||
const regex = new RegExp(/MARKETING_VERSION = (\d+\.\d+\.\d+);/, "g"); | ||
|
||
const results = contents.matchAll(regex); | ||
|
||
let count = 0; | ||
let currentVersion = null; | ||
|
||
for (const result of results) { | ||
if (count == 0) { | ||
currentVersion = result[1]; | ||
} else { | ||
if (result[1] !== currentVersion) | ||
throw new Error("All versions didn't match"); | ||
} | ||
count++; | ||
} | ||
|
||
console.log(`Changing ${count} version numbers`); | ||
|
||
console.log("Current version is: ", currentVersion); | ||
|
||
const newVersion = getNewVersion(currentVersion, commit); | ||
|
||
if (newVersion === null) { | ||
console.log("You didn't ask for a new version"); | ||
} else { | ||
console.log("New version", newVersion); | ||
|
||
const newContents = contents.replaceAll(currentVersion, newVersion); | ||
|
||
fs.writeFileSync(projectFilePath, newContents); | ||
} | ||
}; |