Skip to content

Commit ed7b78f

Browse files
authored
Merge pull request #1812 from belemaire/fix-code-push-release
Fix bug in code-push release
2 parents f3bf934 + bc35403 commit ed7b78f

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

ern-orchestrator/src/codepush.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,18 +371,30 @@ export async function performCodePushOtaUpdate(
371371
);
372372
}
373373

374-
const miniAppsToBeCodePushed = _.unionBy(
375-
referenceMiniAppsToCodePush,
374+
const miniAppsToBeCodePushedUnordered: PackagePath[] = _.unionBy(
376375
miniApps,
376+
referenceMiniAppsToCodePush,
377377
(x) => x.basePath,
378378
);
379379

380-
const jsApiImplsToBeCodePushed = _.unionBy(
381-
referenceJsApiImplsToCodePush,
380+
// Reorder MiniApps to preserve current order set in Cauldron
381+
const miniAppsToBeCodePushed: PackagePath[] = orderPackagePaths(
382+
referenceMiniAppsToCodePush,
383+
miniAppsToBeCodePushedUnordered,
384+
);
385+
386+
const jsApiImplsToBeCodePushedUnordered = _.unionBy(
382387
jsApiImpls,
388+
referenceJsApiImplsToCodePush,
383389
(x) => x.basePath,
384390
);
385391

392+
// Reorder JS API implementations to preserve current order set in Cauldron
393+
const jsApiImplsToBeCodePushed: PackagePath[] = orderPackagePaths(
394+
referenceJsApiImplsToCodePush,
395+
jsApiImplsToBeCodePushedUnordered,
396+
);
397+
386398
const pathsToMiniAppsToBeCodePushed = _.map(miniAppsToBeCodePushed, (m) =>
387399
PackagePath.fromString(m.toString()),
388400
);
@@ -658,3 +670,23 @@ export async function getCodePushAppName(
658670
}`
659671
);
660672
}
673+
674+
// Reorder packages to preserve current order as set in Cauldron
675+
export function orderPackagePaths(
676+
referencePackagePaths: PackagePath[],
677+
packagePaths: PackagePath[],
678+
): PackagePath[] {
679+
const packages: PackagePath[] = [];
680+
for (const m of referencePackagePaths) {
681+
const x = _.find(packagePaths, (p) => p.basePath === m.basePath) ?? m;
682+
packages.push(x);
683+
}
684+
// Add all new packages if any
685+
const newPackages: PackagePath[] = _.differenceBy(
686+
packagePaths,
687+
referencePackagePaths,
688+
(p) => p.basePath,
689+
);
690+
packages.push(...newPackages);
691+
return packages;
692+
}

ern-orchestrator/test/codepush-test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,4 +851,61 @@ describe('codepush', () => {
851851
expect(result).equal('app-android');
852852
});
853853
});
854+
855+
describe('orderPackagePaths', () => {
856+
const referencePackagePaths: PackagePath[] = [
857+
PackagePath.fromString(
858+
'git+ssh://[email protected]/foo/A.git#24f0eebdd714949ec5af5366a1adcf6aeb759bdf',
859+
),
860+
PackagePath.fromString(
861+
'git+ssh://[email protected]/foo/B.git#a4e7b1b1f4671330edac9d7ac09be66e29a56e43',
862+
),
863+
PackagePath.fromString(
864+
'git+ssh://[email protected]/foo/C.git#09f6a4f8c19ced184bad428272b1f02f76ffd5b8',
865+
),
866+
];
867+
const [originalPkgA, originalPkgB, originalPkgC] = referencePackagePaths;
868+
869+
const updatedPackagedPaths: PackagePath[] = [
870+
PackagePath.fromString(
871+
'git+ssh://[email protected]/foo/A.git#b554f6e7a3433f9118de8a677e34d27b161f501a',
872+
),
873+
PackagePath.fromString(
874+
'git+ssh://[email protected]/foo/B.git#683c50cd2e50c6146f87cc377b9db1e24e722de6',
875+
),
876+
PackagePath.fromString(
877+
'git+ssh://[email protected]/foo/C.git#9548e24c79830658be6f038177310b98298653b2',
878+
),
879+
];
880+
const [updatedPkgA, updatedPkgB, updatedPkgC] = updatedPackagedPaths;
881+
882+
it('should preserve packages reference order', () => {
883+
const res = sut.orderPackagePaths(referencePackagePaths, [
884+
updatedPkgC,
885+
updatedPkgA,
886+
updatedPkgB,
887+
]);
888+
expect(res).deep.equal([updatedPkgA, updatedPkgB, updatedPkgC]);
889+
});
890+
891+
it('should keep reference packages that are not updated', () => {
892+
const res = sut.orderPackagePaths(referencePackagePaths, [
893+
updatedPkgB,
894+
updatedPkgA,
895+
]);
896+
expect(res).deep.equal([updatedPkgA, updatedPkgB, originalPkgC]);
897+
});
898+
899+
it('should keep new packages that are not part of reference packages', () => {
900+
const newPkg = PackagePath.fromString(
901+
'git+ssh://[email protected]/foo/D.git#ccf32848ae53ce9e339090bb3a1b26c971041734',
902+
);
903+
const res = sut.orderPackagePaths(referencePackagePaths, [
904+
updatedPkgB,
905+
updatedPkgA,
906+
newPkg,
907+
]);
908+
expect(res).deep.equal([updatedPkgA, updatedPkgB, originalPkgC, newPkg]);
909+
});
910+
});
854911
});

0 commit comments

Comments
 (0)