diff --git a/.github/scripts/release-native-template.mjs b/.github/scripts/release-native-template.mjs index 86be5aa8..e23166c4 100644 --- a/.github/scripts/release-native-template.mjs +++ b/.github/scripts/release-native-template.mjs @@ -30,6 +30,11 @@ const STUDIO_PRO_MAJOR = process.env.STUDIO_PRO_MAJOR; const GIT_AUTHOR_NAME = "MendixMobile"; const GIT_AUTHOR_EMAIL = "moo@mendix.com"; +// Native Template Repo Settings +const NT_REPO_OWNER = process.env.GITHUB_REPOSITORY_OWNER; +const NT_REPO_NAME = process.env.GITHUB_REPOSITORY.split("/")[1]; +const NT_CHANGELOG_BRANCH_NAME = `update-changelog-v${NATIVE_TEMPLATE_VERSION}`; + // Docs Repo Settings const DOCS_REPO_NAME = "docs"; const DOCS_REPO_OWNER = "MendixMobile"; @@ -41,6 +46,14 @@ const TARGET_FILE = `${DOCS_PARENT_DIR}/nt-${NATIVE_TEMPLATE_MAJOR}-rn.md`; const octokit = new Octokit({ auth: MENDIX_MOBILE_DOCS_PR_GITHUB_PAT }); +function getToday() { + const today = new Date(); + const yyyy = today.getFullYear(); + const mm = String(today.getMonth() + 1).padStart(2, "0"); + const dd = String(today.getDate()).padStart(2, "0"); + return `${yyyy}-${mm}-${dd}`; +} + function extractUnreleasedChangelog() { const changelogPath = path.resolve( path.join(__dirname, "..", "..", "CHANGELOG.md"), @@ -52,19 +65,80 @@ function extractUnreleasedChangelog() { if (!match) throw new Error("No [Unreleased] section found!"); const unreleasedContent = match[1].trim(); if (!unreleasedContent) throw new Error("No changes under [Unreleased]!"); - return unreleasedContent; + return { changelog, unreleasedContent, changelogPath }; } function buildFrontmatter() { return `---\ntitle: "Native Template ${NATIVE_TEMPLATE_MAJOR}"\nurl: /releasenotes/mobile/nt-${NATIVE_TEMPLATE_MAJOR}-rn/\nweight: 1\ndescription: "Native Template ${NATIVE_TEMPLATE_MAJOR}"\n---`; } +// Changelog Update for Native Template Repo +function updateChangelog({ changelog, unreleasedContent, changelogPath }) { + const today = getToday(); + const newSection = `## [${NATIVE_TEMPLATE_VERSION}] - ${today}\n\n${unreleasedContent}\n\n`; + const unreleasedRegex = + /^## \[Unreleased\](.*?)(?=^## \[\d+\.\d+\.\d+\][^\n]*|\Z)/ms; + const updatedChangelog = changelog.replace( + unreleasedRegex, + `## [Unreleased]\n\n${newSection}` + ); + fs.writeFileSync(changelogPath, updatedChangelog, "utf-8"); +} + +// Raise a PR to update the CHANGELOG.md in the native-template repo +async function createPRUpdateChangelog() { + const git = simpleGit(); + + await git.addConfig("user.name", GIT_AUTHOR_NAME, ["--global"]); + await git.addConfig("user.email", GIT_AUTHOR_EMAIL, ["--global"]); + + // Get the current branch name (the one selected in GitHub Actions UI) + const currentBranch = await git.revparse(["--abbrev-ref", "HEAD"]); + + await git.checkoutLocalBranch(NT_CHANGELOG_BRANCH_NAME); + + await git.add("CHANGELOG.md"); + await git.commit(`chore: update CHANGELOG for v${NATIVE_TEMPLATE_VERSION}`); + await git.push("origin", NT_CHANGELOG_BRANCH_NAME, ["--force"]); + + const prBody = ` +Automated update of CHANGELOG.md for v${NATIVE_TEMPLATE_VERSION}. + +This PR moves the \`[Unreleased]\` section content to a new versioned section \`[${NATIVE_TEMPLATE_VERSION}]\`. + +--- + +**Note:** +This pull request was automatically generated by an automation process managed by the Mobile team. +**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: NT_REPO_OWNER, + repo: NT_REPO_NAME, + title: `Update CHANGELOG for v${NATIVE_TEMPLATE_VERSION}`, + head: NT_CHANGELOG_BRANCH_NAME, + base: currentBranch, + body: prBody, + draft: true, + }); +} + +async function updateNTChangelog(changelog, unreleasedContent, changelogPath) { + try { + updateChangelog({ changelog, unreleasedContent, changelogPath }); + await createPRUpdateChangelog(); + } catch (err) { + console.error("❌ Updating NT Changelog failed:", err); + process.exit(1); + } +} + // Docs function injectUnreleasedToDoc(docPath, unreleasedContent) { if (!fs.existsSync(DOCS_PARENT_DIR)) { - throw new Error( - `Parent directory not found: ${DOCS_PARENT_DIR}\nA new Studio Pro parent folder requires manual setup in the docs repo.`, - ); + console.log(`Parent directory not found. Creating: ${DOCS_PARENT_DIR}`); + fs.mkdirSync(DOCS_PARENT_DIR, { recursive: true }); } const date = new Date(); @@ -99,10 +173,6 @@ function injectUnreleasedToDoc(docPath, unreleasedContent) { return `${frontmatter}\n\n${beforeReleases}${releaseHeading}\n\n${unreleasedContent}\n\n${releaseSections}`; } -// This file exists only in the fork (MendixMobile/docs) and not in upstream (mendix/docs). -// Removing it in our branch ensures it doesn't appear in the cross-fork PR diff. -const FORK_SYNC_FILE = ".github/workflows/sync.yml"; - async function cloneDocsRepo() { const git = simpleGit(); const docsCloneDir = fs.mkdtempSync( @@ -131,10 +201,6 @@ async function updateDocsNTReleaseNotes(unreleasedContent) { } async function createPRUpdateDocsNTReleaseNotes(git) { - // Remove the fork's sync.yml so it doesn't appear in the cross-fork PR diff. - if (fs.existsSync(FORK_SYNC_FILE)) { - await git.rm(FORK_SYNC_FILE); - } await git.add(TARGET_FILE); await git.commit( `docs: update mobile release notes for v${NATIVE_TEMPLATE_VERSION}`, @@ -171,7 +237,7 @@ async function updateNTReleaseNotes(unreleasedContent) { updateDocsNTReleaseNotes(unreleasedContent); await createPRUpdateDocsNTReleaseNotes(git); } catch (err) { - console.error("❌ Updating NT Release Notes failed:", err); + console.error("❌ Updating NT Release Notes in Docs failed:", err); process.exit(1); } } @@ -185,7 +251,12 @@ function readVersionFromPackageJson() { } (async () => { - const unreleasedContent = extractUnreleasedChangelog(); + const { changelog, unreleasedContent, changelogPath } = + extractUnreleasedChangelog(); + + // Update CHANGELOG.md in native-template repo + await updateNTChangelog(changelog, unreleasedContent, changelogPath); + // Update release notes in docs repo await updateNTReleaseNotes(unreleasedContent); })(); diff --git a/.github/workflows/publish-changelog-to-docs.yml b/.github/workflows/publish-changelog-to-docs.yml deleted file mode 100644 index e1c0e693..00000000 --- a/.github/workflows/publish-changelog-to-docs.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Publish Changelog to Mendix Docs - -on: - workflow_dispatch: - inputs: - branch: - description: 'Branch to read the changelog and version from' - required: true - default: 'master' - type: string - studio_pro_version: - description: 'Studio Pro major version (determines the docs parent folder)' - required: true - default: 'Studio Pro 11.x' - type: choice - options: - - 'Studio Pro 10.x' - - 'Studio Pro 11.x' - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.branch }} - - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - - name: Install docs release script dependencies - run: npm ci --prefix .github/scripts - - - name: Create release notes PR in mendix/docs Github repository - env: - MENDIX_MOBILE_DOCS_PR_GITHUB_PAT: ${{ secrets.MENDIX_MOBILE_DOCS_PR_GITHUB_PAT }} - STUDIO_PRO_MAJOR: ${{ github.event.inputs.studio_pro_version == 'Studio Pro 10.x' && '10' || '11' }} - run: node .github/scripts/release-native-template.mjs diff --git a/.github/workflows/release-it.yml b/.github/workflows/release-it.yml index 49bf65b5..6b0fd916 100644 --- a/.github/workflows/release-it.yml +++ b/.github/workflows/release-it.yml @@ -15,6 +15,14 @@ on: - preminor - premajor - prepatch + studio_pro_version: + description: 'Studio Pro major version (determines the docs parent folder for changelog publishing)' + required: true + default: 'Studio Pro 11.x' + type: choice + options: + - 'Studio Pro 10.x' + - 'Studio Pro 11.x' jobs: release: @@ -37,4 +45,19 @@ jobs: git config --global user.name "github-action" release-it -VV --increment=${{ github.event.inputs.version }} --ci --github.release --github.draft --git.commitMessage="chore: release v\${version}" --git.tagName="v\${version}" - + - name: Sync docs fork with upstream + if: ${{ contains(fromJSON('["patch","minor","major"]'), github.event.inputs.version) }} + run: gh repo sync MendixMobile/docs --branch development --force + env: + GH_TOKEN: ${{ secrets.MENDIX_MOBILE_DOCS_PR_GITHUB_PAT }} + + - name: Install docs release script dependencies + if: ${{ contains(fromJSON('["patch","minor","major"]'), github.event.inputs.version) }} + run: npm ci --prefix .github/scripts + + - name: Create Changelog PR in native-template and release notes PR in mendix/docs + if: ${{ contains(fromJSON('["patch","minor","major"]'), github.event.inputs.version) }} + env: + MENDIX_MOBILE_DOCS_PR_GITHUB_PAT: ${{ secrets.MENDIX_MOBILE_DOCS_PR_GITHUB_PAT }} + STUDIO_PRO_MAJOR: ${{ github.event.inputs.studio_pro_version == 'Studio Pro 10.x' && '10' || '11' }} + run: node .github/scripts/release-native-template.mjs diff --git a/.github/workflows/sync-docs-fork-daily.yml b/.github/workflows/sync-docs-fork-daily.yml new file mode 100644 index 00000000..2da07aa9 --- /dev/null +++ b/.github/workflows/sync-docs-fork-daily.yml @@ -0,0 +1,15 @@ +name: Sync Docs Fork Daily + +on: + schedule: + - cron: '0 0 * * *' # Daily at midnight UTC + workflow_dispatch: # Allow manual trigger + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Sync MendixMobile/docs fork with upstream + run: gh repo sync MendixMobile/docs --branch development --force + env: + GH_TOKEN: ${{ secrets.MENDIX_MOBILE_DOCS_PR_GITHUB_PAT }} diff --git a/.github/workflows/update_releases_list.yml b/.github/workflows/update_releases_list.yml index 79bce7ec..f2076010 100644 --- a/.github/workflows/update_releases_list.yml +++ b/.github/workflows/update_releases_list.yml @@ -56,6 +56,4 @@ jobs: A new version of Native Template has been released with updated version compatibility information. - Please review the PR for more details: ${{ github.server_url }}/${{ github.repository }}/pull/${{ steps.pr.outputs.number }} - - 📝 *Reminder:* Run the <${{ github.server_url }}/${{ github.repository }}/actions/workflows/publish-changelog-to-docs.yml|Publish Changelog to Mendix Docs> workflow to publish the release notes to the docs repo. + Please review the PR for more details: ${{ github.server_url }}/${{ github.repository }}/pull/${{ steps.pr.outputs.number }} \ No newline at end of file