Skip to content

Commit f0271aa

Browse files
Merge pull request #1219 from mendix/MOO-2305-docs-pr-manual-trigger
[MOO-2305] move docs changelog publish to manual workflow with branch/stu…
2 parents 8b549d0 + b0b4ee0 commit f0271aa

4 files changed

Lines changed: 73 additions & 54 deletions

File tree

.github/scripts/release-native-template.mjs

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import simpleGit from "simple-git";
77

88
const required = [
99
"MENDIX_MOBILE_DOCS_PR_GITHUB_PAT",
10-
"NATIVE_TEMPLATE_VERSION_BUMP_TYPE",
10+
"STUDIO_PRO_MAJOR",
1111
];
1212

1313
const missing = required.filter((k) => !process.env[k]);
@@ -20,15 +20,12 @@ const __filename = fileURLToPath(import.meta.url);
2020
const __dirname = path.dirname(__filename);
2121
const DOCS_CLONE_PREFIX = "mendix-docs-";
2222

23-
const NATIVE_TEMPLATE_VERSION_BUMP_TYPE =
24-
process.env.NATIVE_TEMPLATE_VERSION_BUMP_TYPE; // patch, minor, major
25-
2623
const MENDIX_MOBILE_DOCS_PR_GITHUB_PAT =
2724
process.env.MENDIX_MOBILE_DOCS_PR_GITHUB_PAT;
2825

29-
const NATIVE_TEMPLATE_VERSION = determineVersionFromBumpType(
30-
NATIVE_TEMPLATE_VERSION_BUMP_TYPE,
31-
);
26+
const NATIVE_TEMPLATE_VERSION = readVersionFromPackageJson();
27+
const NATIVE_TEMPLATE_MAJOR = NATIVE_TEMPLATE_VERSION.split(".")[0];
28+
const STUDIO_PRO_MAJOR = process.env.STUDIO_PRO_MAJOR;
3229

3330
const GIT_AUTHOR_NAME = "MendixMobile";
3431
const GIT_AUTHOR_EMAIL = "moo@mendix.com";
@@ -39,11 +36,8 @@ const DOCS_REPO_OWNER = "MendixMobile";
3936
const DOCS_UPSTREAM_OWNER = "mendix";
4037
const DOCS_BRANCH_NAME = `update-native-template-release-notes-v${NATIVE_TEMPLATE_VERSION}`;
4138

42-
const TARGET_FILE =
43-
"content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-11-parent/nt-17-rn.md";
44-
// Other options:
45-
// - content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-11-parent/nt-15-rn.md
46-
// - content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-11-parent/nt-16-rn.md
39+
const DOCS_PARENT_DIR = `content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-${STUDIO_PRO_MAJOR}-parent`;
40+
const TARGET_FILE = `${DOCS_PARENT_DIR}/nt-${NATIVE_TEMPLATE_MAJOR}-rn.md`;
4741

4842
const octokit = new Octokit({ auth: MENDIX_MOBILE_DOCS_PR_GITHUB_PAT });
4943

@@ -61,8 +55,31 @@ function extractUnreleasedChangelog() {
6155
return unreleasedContent;
6256
}
6357

58+
function buildFrontmatter() {
59+
return `---\ntitle: "Native Template ${NATIVE_TEMPLATE_MAJOR}"\nurl: /releasenotes/mobile/nt-${NATIVE_TEMPLATE_MAJOR}-rn/\nweight: 1\ndescription: "Native Template ${NATIVE_TEMPLATE_MAJOR}"\n---`;
60+
}
61+
6462
// Docs
6563
function injectUnreleasedToDoc(docPath, unreleasedContent) {
64+
if (!fs.existsSync(DOCS_PARENT_DIR)) {
65+
throw new Error(
66+
`Parent directory not found: ${DOCS_PARENT_DIR}\nA new Studio Pro parent folder requires manual setup in the docs repo.`,
67+
);
68+
}
69+
70+
const date = new Date();
71+
const formattedDate = date.toLocaleDateString("en-US", {
72+
year: "numeric",
73+
month: "short",
74+
day: "numeric",
75+
});
76+
const releaseHeading = `## ${NATIVE_TEMPLATE_VERSION}\n\n**Release date: ${formattedDate}**`;
77+
78+
if (!fs.existsSync(docPath)) {
79+
console.log(`${docPath} not found — creating new file for Native Template ${NATIVE_TEMPLATE_MAJOR}.`);
80+
return `${buildFrontmatter()}\n\n${releaseHeading}\n\n${unreleasedContent}\n`;
81+
}
82+
6683
const doc = fs.readFileSync(docPath, "utf-8");
6784
const frontmatterMatch = doc.match(/^---[\s\S]*?---/);
6885
if (!frontmatterMatch) throw new Error("Frontmatter not found!");
@@ -79,15 +96,7 @@ function injectUnreleasedToDoc(docPath, unreleasedContent) {
7996
? rest.slice(firstReleaseHeadingIndex).trimStart()
8097
: rest.trimStart();
8198

82-
const date = new Date();
83-
const formattedDate = date.toLocaleDateString("en-US", {
84-
year: "numeric",
85-
month: "short",
86-
day: "numeric",
87-
});
88-
const title = `## ${NATIVE_TEMPLATE_VERSION}\n\n**Release date: ${formattedDate}**`;
89-
90-
return `${frontmatter}\n\n${beforeReleases}${title}\n\n${unreleasedContent}\n\n${releaseSections}`;
99+
return `${frontmatter}\n\n${beforeReleases}${releaseHeading}\n\n${unreleasedContent}\n\n${releaseSections}`;
91100
}
92101

93102
// This file exists only in the fork (MendixMobile/docs) and not in upstream (mendix/docs).
@@ -167,31 +176,12 @@ async function updateNTReleaseNotes(unreleasedContent) {
167176
}
168177
}
169178

170-
function determineVersionFromBumpType(bumpType = "patch") {
179+
function readVersionFromPackageJson() {
171180
const packageJsonPath = path.resolve(
172181
path.join(__dirname, "..", "..", "package.json"),
173182
);
174183
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
175-
const currentVersion = packageJson.version;
176-
177-
const [major, minor, patch] = currentVersion.split(".").map(Number);
178-
let newVersion;
179-
switch (bumpType) {
180-
case "major":
181-
newVersion = `${major + 1}.0.0`;
182-
break;
183-
case "minor":
184-
newVersion = `${major}.${minor + 1}.0`;
185-
break;
186-
case "patch":
187-
newVersion = `${major}.${minor}.${patch + 1}`;
188-
break;
189-
default:
190-
throw new Error(
191-
`Invalid bump type for docs release notes: ${bumpType}. Expected one of: patch, minor, major.`,
192-
);
193-
}
194-
return newVersion;
184+
return packageJson.version;
195185
}
196186

197187
(async () => {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Publish Changelog to Mendix Docs
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'Branch to read the changelog and version from'
8+
required: true
9+
default: 'master'
10+
type: string
11+
studio_pro_version:
12+
description: 'Studio Pro major version (determines the docs parent folder)'
13+
required: true
14+
default: 'Studio Pro 11.x'
15+
type: choice
16+
options:
17+
- 'Studio Pro 10.x'
18+
- 'Studio Pro 11.x'
19+
20+
jobs:
21+
publish:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
with:
26+
ref: ${{ github.event.inputs.branch }}
27+
28+
- uses: actions/setup-node@v3
29+
with:
30+
node-version-file: .nvmrc
31+
32+
- name: Install docs release script dependencies
33+
run: npm ci --prefix .github/scripts
34+
35+
- name: Create release notes PR in mendix/docs Github repository
36+
env:
37+
MENDIX_MOBILE_DOCS_PR_GITHUB_PAT: ${{ secrets.MENDIX_MOBILE_DOCS_PR_GITHUB_PAT }}
38+
STUDIO_PRO_MAJOR: ${{ github.event.inputs.studio_pro_version == 'Studio Pro 10.x' && '10' || '11' }}
39+
run: node .github/scripts/release-native-template.mjs

.github/workflows/release-it.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,7 @@ jobs:
2828
with:
2929
node-version-file: .nvmrc
3030

31-
- name: Install docs release script dependencies
32-
if: ${{ contains(fromJSON('["patch","minor","major"]'), github.event.inputs.version) }}
33-
run: npm ci --prefix .github/scripts
34-
35-
- name: Create release notes PR in mendix/docs Github repository
36-
if: ${{ contains(fromJSON('["patch","minor","major"]'), github.event.inputs.version) }}
37-
env:
38-
NATIVE_TEMPLATE_VERSION_BUMP_TYPE: ${{ github.event.inputs.version }}
39-
MENDIX_MOBILE_DOCS_PR_GITHUB_PAT: ${{ secrets.MENDIX_MOBILE_DOCS_PR_GITHUB_PAT }}
40-
run: node .github/scripts/release-native-template.mjs
41-
4231
- name: Release a new version
43-
if: success()
4432
env:
4533
GITHUB_TOKEN: ${{ secrets.PUBLIC_REPO_ADMIN_TOKEN }}
4634
run: |

.github/workflows/update_releases_list.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ jobs:
5757
A new version of Native Template has been released with updated version compatibility information.
5858
5959
Please review the PR for more details: ${{ github.server_url }}/${{ github.repository }}/pull/${{ steps.pr.outputs.number }}
60+
61+
📝 *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.

0 commit comments

Comments
 (0)