diff --git a/.github/workflows/incrementVersionAndChangelog.js b/.github/workflows/incrementVersionAndChangelog.js index ac071abfd0..682c19a383 100644 --- a/.github/workflows/incrementVersionAndChangelog.js +++ b/.github/workflows/incrementVersionAndChangelog.js @@ -1,14 +1,12 @@ -const {Octokit} = require("@octokit/rest"); -const fs = require("fs"); - - +import {Octokit} from "@octokit/rest"; +import fs from "fs"; // To be run from the main Unciv repo directory // Summarizes and adds the summary to the changelog.md file // Meant to be run from a Github action as part of the preparation for version rollout //region Executed Code (async () => { - versionAndChangelog = await parseCommits(); + const versionAndChangelog = await parseCommits(); const newVersionString = versionAndChangelog[0] const changelogString = versionAndChangelog[1] @@ -30,27 +28,27 @@ async function parseCommits() { // no need to add auth: token since we're only reading from the commit list, which is public anyway const octokit = new Octokit({}); - var result = await octokit.repos.listCommits({ + const result = await octokit.repos.listCommits({ owner: "yairm210", repo: "Unciv", per_page: 50 }); - var commitSummary = ""; - var ownerToCommits = {}; - var reachedPreviousVersion = false; - var nextVersionString = ""; + let commitSummary = ""; + const ownerToCommits = {}; + let reachedPreviousVersion = false; + let nextVersionString = ""; result.data.forEach(commit => { // See https://github.com/yairm210/Unciv/actions/runs/4136712446/jobs/7151150557 for example of strange commit with null author if (reachedPreviousVersion || commit.author == null) return; - var author = commit.author.login; + const author = commit.author.login; if (author === "uncivbot[bot]") return; - var commitMessage = commit.commit.message.split("\n")[0]; + let commitMessage = commit.commit.message.split("\n")[0]; - var versionMatches = commitMessage.match(/^\d+\.\d+\.(\d+)$/); + const versionMatches = commitMessage.match(/^\d+\.\d+\.(\d+)$/); if (versionMatches) { // match EXACT version, like 3.4.55 ^ is for start-of-line, $ for end-of-line reachedPreviousVersion = true; - var minorVersion = Number(versionMatches[1]); + const minorVersion = Number(versionMatches[1]); console.log("Previous version: " + commitMessage); nextVersionString = commitMessage.replace(RegExp(minorVersion + "$"), minorVersion + 1); console.log("Next version: " + nextVersionString); @@ -81,30 +79,30 @@ async function parseCommits() { } function writeChangelog(nextVersionString, changelogString){ - var textToAddToChangelog = "## " + nextVersionString + changelogString + "\n\n"; + const textToAddToChangelog = "## " + nextVersionString + changelogString + "\n\n"; - var changelogPath = 'changelog.md'; - var currentChangelog = fs.readFileSync(changelogPath).toString(); + const changelogPath = 'changelog.md'; + const currentChangelog = fs.readFileSync(changelogPath).toString(); if (!currentChangelog.startsWith(textToAddToChangelog)) { // minor idempotency - don't add twice - var newChangelog = textToAddToChangelog + currentChangelog; + const newChangelog = textToAddToChangelog + currentChangelog; fs.writeFileSync(changelogPath, newChangelog); } } function updateBuildConfig(nextVersionString) { - var buildConfigPath = "buildSrc/src/main/kotlin/BuildConfig.kt"; - var buildConfigString = fs.readFileSync(buildConfigPath).toString(); + const buildConfigPath = "buildSrc/src/main/kotlin/BuildConfig.kt"; + let buildConfigString = fs.readFileSync(buildConfigPath).toString(); console.log("Original: " + buildConfigString); // Javascript string.match returns a regex string array, where array[0] is the entirety of the captured string, // and array[1] is the first group, array[2] is the second group etc. - var appVersionMatch = buildConfigString.match(/appVersion = "(.*)"/); + const appVersionMatch = buildConfigString.match(/appVersion = "(.*)"/); const curVersion = appVersionMatch[1]; if (curVersion !== nextVersionString) { buildConfigString = buildConfigString.replace(appVersionMatch[0], appVersionMatch[0].replace(curVersion, nextVersionString)); - var appCodeNumberMatch = buildConfigString.match(/appCodeNumber = (\d*)/); + const appCodeNumberMatch = buildConfigString.match(/appCodeNumber = (\d*)/); let currentAppCodeNumber = appCodeNumberMatch[1]; console.log("Current incremental version: " + currentAppCodeNumber); const nextAppCodeNumber = Number(currentAppCodeNumber) + 1; @@ -121,7 +119,7 @@ function updateBuildConfig(nextVersionString) { function createFastlaneFile(newAppCodeNumber, changelogString){ // A new, discrete changelog file for fastlane (F-Droid support): - var fastlaneChangelogPath = "fastlane/metadata/android/en-US/changelogs/" + newAppCodeNumber + ".txt"; + const fastlaneChangelogPath = "fastlane/metadata/android/en-US/changelogs/" + newAppCodeNumber + ".txt"; fs.writeFileSync(fastlaneChangelogPath, changelogString); } diff --git a/.github/workflows/mergeTranslations.js b/.github/workflows/mergeTranslations.js index 341ad7442f..0c51355f12 100644 --- a/.github/workflows/mergeTranslations.js +++ b/.github/workflows/mergeTranslations.js @@ -1,9 +1,5 @@ - -const { Octokit } = require("@octokit/rest"); -const { version } = require("os"); -const internal = require("stream"); -const fs = require("fs"); -const { argv } = require("process"); +import {Octokit} from "@octokit/rest"; +import {argv} from "process"; // To be run from the main Unciv repo directory @@ -12,14 +8,14 @@ const { argv } = require("process"); async function main(){ - var args = argv.slice(2) // remove 'node' and filename parameters + const args = argv.slice(2); // remove 'node' and filename parameters - var auth = args[0] - var issue_to_comment_on = 0 // 0 means no issue + const auth = args[0]; + let issue_to_comment_on = 0; // 0 means no issue if (args[1]) issue_to_comment_on = Number(args[1]) - var branch_to_merge_to = "translations" + let branch_to_merge_to = "translations"; if(args[2]) branch_to_merge_to = args[2] @@ -42,19 +38,19 @@ async function main(){ } async function getDefaultBranch() { - var repoData = await github.repos.get(repo) - return repoData.data.default_branch + const repoData = await github.repos.get(repo); + return repoData.data.default_branch } async function createTranslationBranchIfNeeded() { if (await branchExists(branch_to_merge_to)) return - var defaultBranch = await getDefaultBranch() - - var currentHead = await github.git.getRef({...repo, ref: 'heads/' + defaultBranch }) - - var currentSha = currentHead.data.object.sha - console.log("Current sha: " + currentSha) + const defaultBranch = await getDefaultBranch(); + + const currentHead = await github.git.getRef({...repo, ref: 'heads/' + defaultBranch}); + + const currentSha = currentHead.data.object.sha; + console.log("Current sha: " + currentSha) await github.git.createRef({...repo, ref: `refs/heads/` + branch_to_merge_to, @@ -67,9 +63,9 @@ async function main(){ } async function mergeExistingTranslationsIntoBranch(){ - var translationPrs = await github.pulls.list({ ...repo, state: "open" }) - - // When we used a forEach loop here, only one merge would happen at each run, + const translationPrs = await github.pulls.list({...repo, state: "open"}); + + // When we used a forEach loop here, only one merge would happen at each run, // because we essentially started multiple async tasks in parallel and they conflicted. // Instead, we use X of Y as per https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop for (const pr of translationPrs.data) { @@ -97,16 +93,20 @@ async function main(){ async function createTranslationPrIfNeeded() { - var translationPulls = await github.pulls.list({...repo, - state: "open", - head: repo.owner + ":" + branch_to_merge_to }); + const translationPulls = await github.pulls.list({ + ...repo, + state: "open", + head: repo.owner + ":" + branch_to_merge_to + }); - if (translationPulls.data.length == 0) { // no pr exists yet - var defaultBranch = await getDefaultBranch(); - var result = await github.pulls.create({...repo, - title: "Version rollout", - head: branch_to_merge_to, - base: defaultBranch }); + if (translationPulls.data.length == 0) { // no pr exists yet + const defaultBranch = await getDefaultBranch(); + const result = await github.pulls.create({ + ...repo, + title: "Version rollout", + head: branch_to_merge_to, + base: defaultBranch + }); if (issue_to_comment_on != 0) await github.issues.createComment({...repo, diff --git a/.github/workflows/releasePatch.js b/.github/workflows/releasePatch.js index ac1fec38fe..c26e91458f 100644 --- a/.github/workflows/releasePatch.js +++ b/.github/workflows/releasePatch.js @@ -1,6 +1,4 @@ -const fs = require("fs"); - - +import fs from "fs"; // To be run from the main Unciv repo directory // Increments the latest code version to include 'patch-X' // Meant to be run from a Github action as part of patch release @@ -14,34 +12,33 @@ const fs = require("fs"); })(); //endregion - //region Function Definitions function getNextPatchVersion(currentVersion){ if (currentVersion.match(/^\d+\.\d+\.\d+$/)) return currentVersion + "-patch1" - var patchVersionRegexMatch = currentVersion.match(/^(\d+\.\d+\.\d+)-patch(\d+)$/) + const patchVersionRegexMatch = currentVersion.match(/^(\d+\.\d+\.\d+)-patch(\d+)$/); if (!patchVersionRegexMatch) throw "Unrecognizable version format!" - var patchVersion = parseInt(patchVersionRegexMatch[2]) + 1 + const patchVersion = parseInt(patchVersionRegexMatch[2]) + 1; return patchVersionRegexMatch[1] + "-patch" + patchVersion } function updateBuildConfig() { - var buildConfigPath = "buildSrc/src/main/kotlin/BuildConfig.kt"; - var buildConfigString = fs.readFileSync(buildConfigPath).toString(); + const buildConfigPath = "buildSrc/src/main/kotlin/BuildConfig.kt"; + let buildConfigString = fs.readFileSync(buildConfigPath).toString(); // console.log("Original: " + buildConfigString); // Javascript string.match returns a regex string array, where array[0] is the entirety of the captured string, // and array[1] is the first group, array[2] is the second group etc. - var appVersionMatch = buildConfigString.match(/appVersion = "(.*)"/); + const appVersionMatch = buildConfigString.match(/appVersion = "(.*)"/); const curVersion = appVersionMatch[1]; const newVersion = getNextPatchVersion(curVersion) // console.log("New version: "+newVersion) buildConfigString = buildConfigString.replace(appVersionMatch[0], appVersionMatch[0].replace(curVersion, newVersion)); - var appCodeNumberMatch = buildConfigString.match(/appCodeNumber = (\d*)/); + const appCodeNumberMatch = buildConfigString.match(/appCodeNumber = (\d*)/); let currentAppCodeNumber = appCodeNumberMatch[1]; // console.log("Current incremental version: " + currentAppCodeNumber); const nextAppCodeNumber = Number(currentAppCodeNumber) + 1;