diff --git a/scripts/package.json b/scripts/package.json index 6daa8cc..a2ff013 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -1,4 +1,5 @@ { + "type": "module", "scripts": { "bump-version:android": "ts-node update-repository-with-new-version.ts --store-name google-play", "bump-version:ios": "ts-node update-repository-with-new-version.ts --store-name apple-store" diff --git a/scripts/release-make-it-native.js b/scripts/release-make-it-native.js index fb76341..f07268e 100644 --- a/scripts/release-make-it-native.js +++ b/scripts/release-make-it-native.js @@ -1,25 +1,36 @@ -const fs = require("fs"); -const path = require("path"); -const { Octokit } = require("@octokit/rest"); -const simpleGit = require("simple-git"); +import fs from "fs"; +import path from "path"; +import { Octokit } from "@octokit/rest"; +import simpleGit from "simple-git"; + +const docsRepo = { + owner: "MendixMobile", + repo: "docs", +}; + +const currentRepo = { + owner: "mendix", + repo: "make-it-native", +}; const VERSION = process.env.VERSION; const GITHUB_TOKEN = process.env.GITHUB_TOKEN; const PAT = process.env.PAT || GITHUB_TOKEN; -const REPO_OWNER = "MendixMobile"; -const REPO_NAME = "docs"; -const UPSTREAM_OWNER = "MendixMobile"; -// const UPSTREAM_OWNER = "mendix"; -const BRANCH_NAME = `update-mobile-release-notes-v${VERSION}`; -const TARGET_FILE = - "content/en/docs/releasenotes/mobile/make-it-native-parent/make-it-native-10.md"; if (!VERSION) { console.error("VERSION env variable is required!"); process.exit(1); } +const CHANGELOG_BRANCH = `changelog-update-v${VERSION}`; + +// Docs specific variables +const RELEASE_NOTES_BRANCH_NAME = `update-mobile-release-notes-v${VERSION}`; +const localDocsRepoPath = path.join(process.cwd(), "../test/", docsRepo.repo); +const TARGET_FILE = `${localDocsRepoPath}/content/en/docs/releasenotes/mobile/make-it-native-parent/make-it-native-10.md`; + const octokit = new Octokit({ auth: GITHUB_TOKEN }); +const docsOctokit = new Octokit({ auth: PAT }); function getToday() { const today = new Date(); @@ -76,14 +87,13 @@ async function prChangelogUpdate() { const git = simpleGit(); await git.checkoutLocalBranch(CHANGELOG_BRANCH); - await git.add("CHANGELOG.md"); await git.commit(`chore: update CHANGELOG for v${VERSION}`); await git.push("origin", CHANGELOG_BRANCH, ["--force"]); await octokit.pulls.create({ - owner: MAKE_IT_NATIVE_OWNER, - repo: MAKE_IT_NATIVE_REPO, + owner: currentRepo.owner, + repo: currentRepo.repo, title: `Update CHANGELOG for v${VERSION}`, head: CHANGELOG_BRANCH, base: "development", @@ -95,12 +105,33 @@ async function prChangelogUpdate() { } async function updateDocs(unreleasedContent) { + const currentPath = process.cwd(); + console.log("Cloning docs repo"); const git = simpleGit(); - await git.clone( - `https://x-access-token:${PAT}@github.com/${REPO_OWNER}/${REPO_NAME}.git` - ); - process.chdir(REPO_NAME); - await git.checkoutLocalBranch(BRANCH_NAME); + await git + .outputHandler((command, stdout, stderr) => { + stdout.pipe(process.stdout); + stderr.pipe(process.stderr); + + stdout.on("data", (data) => { + // Print data + console.log(data.toString("utf8")); + }); + }) + .clone( + `https://x-access-token:${PAT}@github.com/${docsRepo.owner}/${docsRepo.repo}.git`, + localDocsRepoPath, + { + "--depth": "1", + } + ); + + console.log("Cloned docs repo"); + process.chdir(localDocsRepoPath); + const docsGit = simpleGit(); + console.log("Checking out branch"); + await docsGit.checkoutLocalBranch(RELEASE_NOTES_BRANCH_NAME); + console.log("Checked out branch"); function injectUnreleasedToDoc(docPath, unreleasedContent) { const doc = fs.readFileSync(docPath, "utf-8"); @@ -118,11 +149,16 @@ async function updateDocs(unreleasedContent) { } const newDocContent = injectUnreleasedToDoc(TARGET_FILE, unreleasedContent); + console.log("Writing new doc content"); fs.writeFileSync(TARGET_FILE, newDocContent, "utf-8"); + console.log("New doc content written"); - await git.add(TARGET_FILE); - await git.commit(`docs: update mobile release notes for v${VERSION}`); - await git.push("origin", BRANCH_NAME, ["--force"]); + await docsGit.add(TARGET_FILE); + console.log("Added file"); + await docsGit.commit(`docs: update mobile release notes for v${VERSION}`); + console.log("Committed file"); + await docsGit.push("origin", RELEASE_NOTES_BRANCH_NAME, ["--force"]); + console.log("Pushed file"); const prBody = ` Automated sync of the latest release notes for v${VERSION} from [make-it-native](https://github.com/mendix/make-it-native). @@ -134,17 +170,18 @@ This pull request was automatically generated by an automation process managed b **Please do not take any action on this pull request unless it has been reviewed and approved by a member of the Mobile team.** `; - await octokit.pulls.create({ - owner: UPSTREAM_OWNER, - repo: REPO_NAME, + await docsOctokit.pulls.create({ + owner: docsRepo.owner, + repo: docsRepo.repo, title: `Update mobile app release notes for v${VERSION}`, - head: `${REPO_OWNER}:${BRANCH_NAME}`, + head: `${docsRepo.owner}:${RELEASE_NOTES_BRANCH_NAME}`, base: "development", body: prBody, draft: true, }); - process.chdir(".."); + process.chdir(currentPath); + console.log("Changed directory"); } (async () => {