Skip to content

Commit bd30b8c

Browse files
authored
Merge pull request #1804 from hydephp/improve-internal-monorepo-hydefront-handling
Internal: Improve the monorepo HydeFront versioning process
2 parents 254bbe7 + 287b194 commit bd30b8c

File tree

9 files changed

+139
-27
lines changed

9 files changed

+139
-27
lines changed

monorepo/docs/hydefront.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Internal HydeFront documentation
2+
3+
## Building and creating a new HydeFront version
4+
5+
### Prerequisites
6+
7+
- Make sure you have a Git submodule set up in `packages/hydefront` that points to the HydeFront repository.
8+
- Make sure you have authorization to publish the package to NPM and push to the HydeFront repository.
9+
10+
### Build and setup
11+
12+
```bash
13+
cd packages/hydefront
14+
git pull origin master
15+
npm run prod
16+
```
17+
18+
### Versioning
19+
20+
Head back to the monorepo root and run the following command to bump the version of the HydeFront package:
21+
22+
```bash
23+
php packages/hydefront/.github/scripts/version.php patch|minor|major
24+
```
25+
26+
This will create commits in both the monorepo and submodule. Now follow the following steps:
27+
28+
1. Verify that both commits are correct.
29+
2. Push the submodule commit to the HydeFront repository.
30+
3. Create the release on GitHub. Make sure to use the same version number as the one you just bumped.
31+
4. Refetch the submodule origin to get the new tag created by the release.
32+
5. Publish the package to NPM. (In the future, this could be automated with a GitHub action from the release.)
33+
34+
### Updating the monorepo
35+
36+
After the HydeFront package has been published, you can update the monorepo to use the new version. Run the following command:
37+
38+
```bash
39+
npm update hydefront
40+
```
41+
42+
Now, you may want to amend the monorepo commit with the updated lock file, then it can be pushed to the monorepo repository.
43+

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hydefront/.github/scripts/post-build.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
$hydeFrontPackageLock = $rootPackageLock['dependencies']['hydefront'];
1717
$hydeFrontPackage = json_decode(file_get_contents($baseDir.'../../packages/hydefront/package.json'), true);
1818
$hydeFrontVersion = $hydeFrontPackage['version'];
19-
if ($hydeFrontPackageLock['version'] !== $hydeFrontVersion) {
20-
$this->error('Version mismatch in root package-lock.json and packages/hydefront/package.json:');
21-
$this->warning("Expected hydefront to have version '$hydeFrontPackageLock[version]', but found '$hydeFrontVersion'");
22-
$this->warning("Please run 'npm update hydefront'");
23-
return 1;
24-
} else {
25-
$this->info('Root package lock verified. All looks good!');
26-
$this->line();
19+
20+
if (! $this->hasOption('skip-root-version-check')) {
21+
if ($hydeFrontPackageLock['version'] !== $hydeFrontVersion) {
22+
$this->error('Version mismatch in root package-lock.json and packages/hydefront/package.json:');
23+
$this->warning("Expected hydefront to have version '$hydeFrontPackageLock[version]', but found '$hydeFrontVersion'");
24+
$this->warning("Please run 'npm update hydefront'");
25+
return 1;
26+
} else {
27+
$this->info('Root package lock verified. All looks good!');
28+
$this->line();
29+
}
2730
}
2831
}
2932

@@ -80,15 +83,11 @@
8083
if (isset($filesChanged)) {
8184
$this->info('Build files fixed');
8285

83-
// Run the script again to verify the changes, but without the --fix option
84-
$this->info('Verifying build files again...');
85-
$this->line('---');
86-
passthru('php packages/hydefront/.github/scripts/post-build.php', $verifyExitCode);
87-
return $verifyExitCode;
86+
$this->info('Tip: You may want to verify the changes again.');
8887
} else {
8988
$this->warning('Nothing to fix!');
90-
return 0;
9189
}
90+
return 0;
9291
}
9392

9493
if ($version !== $hydeCssVersion) {

packages/hydefront/.github/scripts/version.php

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
return 1;
1212
}
1313

14+
$baseDir = getcwd().'/packages/hydefront';
15+
1416
global $argv;
1517
$versionType = $argv[1] ?? null;
1618
if ($versionType === null) {
@@ -25,17 +27,31 @@
2527
return 1;
2628
}
2729

30+
// Ensure the packages/hydefront Git submodule is up-to-date with the origin
31+
$this->info('Checking if the HydeFront submodule is up-to-date...');
32+
$status = performRemoteVersionCheck($baseDir);
33+
if ($status !== 'up-to-date') {
34+
return 1;
35+
}
36+
37+
FileBackupHelper::backup(
38+
$baseDir.'/package.json',
39+
$baseDir.'/package-lock.json',
40+
);
41+
2842
$this->info("Creating a new HydeFront $versionType version...");
2943
$version = trim(shell_exec('cd packages/hydefront && npm version ' . $versionType . ' --no-git-tag-version'));
3044
$this->line("Updated package.json version to $version");
3145

3246
$this->info('Updating version in dist files...');
3347
$this->line('---');
34-
passthru('php packages/hydefront/.github/scripts/post-build.php --fix', $fixExitCode);
48+
passthru('php packages/hydefront/.github/scripts/post-build.php --fix --skip-root-version-check', $fixExitCode);
3549
if ($fixExitCode !== 0) {
3650
$this->error('Failed to update version in dist files');
51+
FileBackupHelper::restore();
3752
return $fixExitCode;
3853
}
54+
FileBackupHelper::clear();
3955
$this->line('---');
4056

4157
$this->info('Committing changes in monorepo...');
@@ -53,3 +69,57 @@
5369

5470
return 0;
5571
}));
72+
73+
class FileBackupHelper
74+
{
75+
protected static array $backups = [];
76+
77+
public static function backup(string ...$paths): void
78+
{
79+
foreach ($paths as $path) {
80+
$backupPath = $path.'.bak';
81+
copy($path, $backupPath);
82+
self::$backups[$path] = $backupPath;
83+
}
84+
}
85+
86+
public static function restore(): void
87+
{
88+
foreach (self::$backups as $path => $backupPath) {
89+
copy($backupPath, $path);
90+
unlink($backupPath);
91+
}
92+
}
93+
94+
public static function clear(): void
95+
{
96+
foreach (self::$backups as $backupPath) {
97+
unlink($backupPath);
98+
}
99+
}
100+
}
101+
102+
function performRemoteVersionCheck(string $submodulePath): string
103+
{
104+
// Navigate to the submodule directory and fetch the latest changes from origin
105+
shell_exec("cd $submodulePath && git fetch");
106+
107+
// Get the status of the local branch compared to the origin
108+
$localStatus = trim(shell_exec("cd $submodulePath && git rev-parse @"));
109+
$remoteStatus = trim(shell_exec("cd $submodulePath && git rev-parse @{u}"));
110+
$baseStatus = trim(shell_exec("cd $submodulePath && git merge-base @ @{u}"));
111+
112+
// Check if local repository is up-to-date
113+
if ($localStatus === $remoteStatus) {
114+
echo "The local repository is up-to-date with the origin.\n";
115+
return 'up-to-date';
116+
} elseif ($localStatus === $baseStatus) {
117+
echo "The local repository is behind the origin. You need to pull the changes before proceeding.\n";
118+
} elseif ($remoteStatus === $baseStatus) {
119+
echo "The local repository is ahead of the origin. You need to push the changes before proceeding.\n";
120+
} else {
121+
echo "The local repository has diverged from the origin. You need to resolve the conflicts before proceeding.\n";
122+
}
123+
124+
return 'diverged';
125+
}

packages/hydefront/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ HydeFront is included with [HydePHP](https://github.com/hydephp/hyde) by default
3636

3737
## Supported Versions & Warranty
3838

39-
HydeFront is not intended to be used for standalone projects and comes with no warranties.
39+
HydeFront is not intended to be used for standalone projects and comes with no warranties for such usages.
4040

4141
Changes in HydeFront are tied to those in the Hyde Framework and differing versions may be incompatible.
4242

packages/hydefront/dist/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hydefront/dist/hyde.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hydefront/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hydefront/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hydefront",
3-
"version": "3.3.5",
3+
"version": "3.3.6",
44
"description": "Frontend assets for HydePHP",
55
"scripts": {
66
"prod": "sass hyde.scss dist/hyde.css --style=compressed && php .github/scripts/post-build.php --inject-version",

0 commit comments

Comments
 (0)