Skip to content

Commit 2a16de2

Browse files
authored
Merge pull request #611 from formio/monorepo-sync
Monorepo sync
2 parents 52bed4a + 83fa8ef commit 2a16de2

File tree

6 files changed

+93
-16
lines changed

6 files changed

+93
-16
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { syncfromGithubAction } from 'monorepo-sync';
2+
3+
syncfromGithubAction()
4+
.then(() => {
5+
console.log('Sync completed successfully');
6+
process.exit(0);
7+
})
8+
.catch((error) => {
9+
console.error('Error during sync:', error);
10+
process.exit(1);
11+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Sync Merged PR to Monorepo
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
- master
9+
10+
jobs:
11+
sync-to-monorepo:
12+
if: github.event.pull_request.merged == true
13+
runs-on: ubuntu-latest
14+
env:
15+
GH_TOKEN: ${{ secrets.MONOREPO_SYNC_TOKEN }}
16+
PR_NUMBER: ${{ github.event.pull_request.number }}
17+
PR_TITLE: ${{ github.event.pull_request.title }}
18+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
19+
SOURCE_REPO_NAME: ${{ github.event.repository.name }}
20+
MONOREPO_PACKAGE_LOCATION: packages/${{ github.event.repository.name }}
21+
MONOREPO_PATH: ${{ github.workspace }}/monorepo
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 1
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: '18'
33+
34+
- name: Install dependencies
35+
# Install project dependencies (including dev dependencies)
36+
run: npm install
37+
- name: Install zx
38+
run: npm install zx
39+
40+
- name: Install monorepo-sync package
41+
run: npm install git+https://github.com/formio/monorepo-sync.git
42+
- name: Clone Monorepo
43+
run: |
44+
gh repo clone formio/formio-monorepo monorepo -- --depth=1
45+
46+
- name: Sync to Monorepo
47+
run: |
48+
echo "Syncing PR #${PR_NUMBER}: ${PR_TITLE}"
49+
node .github/workflows/sync-monorepo.mjs

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"jest-transform-css": "^6.0.1",
5858
"jsdom": "^22.1.0",
5959
"prettier": "3.2.4",
60+
"monorepo-sync": "git+https://github.com/johnformio/monorepo-sync.git",
6061
"react": "^19.0.0",
6162
"react-dom": "^19.0.0",
6263
"ts-jest": "^29.1.2",

src/components/Form.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ const getEffectiveProps = (props: FormProps) => {
252252
export const Form = (props: FormProps) => {
253253
const renderElement = useRef<HTMLDivElement | null>(null);
254254
const currentFormJson = useRef<FormType | null>(null);
255-
const { formConstructor, formSource, formReadyCallback } = getEffectiveProps(props);
255+
const { formConstructor, formSource, formReadyCallback } =
256+
getEffectiveProps(props);
256257
const {
257258
src,
258259
form,
@@ -295,9 +296,10 @@ export const Form = (props: FormProps) => {
295296
console.warn('Form source not found');
296297
return;
297298
}
298-
currentFormJson.current = formSource && typeof formSource !== 'string'
299-
? structuredClone(formSource)
300-
: null;
299+
currentFormJson.current =
300+
formSource && typeof formSource !== 'string'
301+
? structuredClone(formSource)
302+
: null;
301303
const instance = await createWebformInstance(
302304
formConstructor,
303305
currentFormJson.current || formSource,
@@ -338,7 +340,8 @@ export const Form = (props: FormProps) => {
338340
useEffect(() => {
339341
let onAnyHandler = null;
340342
if (formInstance && Object.keys(handlers).length > 0) {
341-
onAnyHandler = (...args: [string, ...any[]]) => onAnyEvent(handlers, ...args);
343+
onAnyHandler = (...args: [string, ...any[]]) =>
344+
onAnyEvent(handlers, ...args);
342345
formInstance.onAny(onAnyHandler);
343346
}
344347

src/components/Report.jsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,19 @@ export const Report = (props) => {
6767
// eslint-disable-next-line no-undef
6868
if (report && !_isEqual(report, jsonReport.current)) {
6969
jsonReport.current = cloneDeep(report);
70-
createReportInstance(report).then(() => {
71-
if (formio) {
72-
formio.form = { components: [], report };
73-
return formio;
74-
}
75-
}).catch((err) => {
76-
console.error(err);
77-
if (formio?.form?.report ) {
78-
formio.form.report = {};
79-
}
80-
});
70+
createReportInstance(report)
71+
.then(() => {
72+
if (formio) {
73+
formio.form = { components: [], report };
74+
return formio;
75+
}
76+
})
77+
.catch((err) => {
78+
console.error(err);
79+
if (formio?.form?.report) {
80+
formio.form.report = {};
81+
}
82+
});
8183
initializeFormio();
8284
}
8385
}, [props.report]);

yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,6 +3908,12 @@ moment@^2.29.4:
39083908
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
39093909
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==
39103910

3911+
"monorepo-sync@git+https://github.com/johnformio/monorepo-sync.git":
3912+
version "1.0.0"
3913+
resolved "git+https://github.com/johnformio/monorepo-sync.git#7865350762a51f65be5a7c10314a18d0a1905f1e"
3914+
dependencies:
3915+
zx "^8.5.4"
3916+
39113917
39123918
version "2.1.2"
39133919
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
@@ -5310,3 +5316,8 @@ yocto-queue@^0.1.0:
53105316
version "0.1.0"
53115317
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
53125318
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
5319+
5320+
zx@^8.5.4:
5321+
version "8.5.4"
5322+
resolved "https://registry.yarnpkg.com/zx/-/zx-8.5.4.tgz#1f5cc658ad69cf093aca1c5cfa943393e8db85f3"
5323+
integrity sha512-44oKea9Sa8ZnOkTnS6fRJpg3quzgnbB43nLrVfYnqE86J4sxgZMUDLezzKET/FdOAVkF4X+Alm9Bume+W+RW9Q==

0 commit comments

Comments
 (0)