Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 85 additions & 14 deletions .github/scripts/release-native-template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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"),
Expand All @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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}`,
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
})();
39 changes: 0 additions & 39 deletions .github/workflows/publish-changelog-to-docs.yml

This file was deleted.

25 changes: 24 additions & 1 deletion .github/workflows/release-it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
15 changes: 15 additions & 0 deletions .github/workflows/sync-docs-fork-daily.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 1 addition & 3 deletions .github/workflows/update_releases_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Loading