forked from tempestphp/tempest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tempestphp#255 from tempestphp/add-console-subsplit
Adds console subsplit.
- Loading branch information
Showing
10 changed files
with
267 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,32 @@ __:white_check_mark: Good Example__ | |
> Value should be a valid email address | ||
__:x: Bad Example__ | ||
> Value should be a valid email address! | ||
> Value should be a valid email address! | ||
# Release Workflow | ||
|
||
> [!NOTE] | ||
> Tempest uses sub-splits to allow components to be installed as individual packages. The following outlines how this process works. | ||
## Workflow Steps | ||
|
||
1. **Trigger Event** | ||
- When a pull request is merged, or a new tag is created, the `.github/workflows/subsplit-packages.yml` action is run. | ||
|
||
2. **Package Information Retrieval** | ||
- When the `subsplit-packages.yml` is run, it calls `bin/get-packages`. | ||
- This PHP script uses a combination of Composer and the filesystem to return (in JSON) some information about every package. It returns the: | ||
- **Directory** | ||
- **Name** | ||
- **Package** | ||
- **Organization** | ||
- **Repository** | ||
|
||
3. **Action Matrix Creation** | ||
- The result of the `get-packages` command is then used to create an action matrix. | ||
- This ensures that the next steps are performed for _every_ package discovered. | ||
|
||
4. **Monorepo Split Action** | ||
- The `symplify/[email protected]` GitHub action is called for every package and provided the necessary information (destination repo, directory, etc.). | ||
- This action takes any changes and pushes them to the sub-split repository determined by combining the "Organization" and "Repository" values returned in step 2. | ||
- Depending on whether a tag is found or not, a tag is also supplied so the repository is tagged appropriately. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: 'Sub-split Packages' | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
tags: [ '*' ] | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} | ||
|
||
jobs: | ||
get_packages: | ||
name: Get Packages | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set Up PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.3 | ||
coverage: none | ||
|
||
- uses: actions/checkout@v2 | ||
|
||
- name: Get Packages | ||
id: get_json | ||
run: echo "::set-output name=json::$(bin/get-packages)" | ||
|
||
- name: Output Packages | ||
run: echo "${{ steps.get_json.outputs.json }}" | ||
outputs: | ||
matrix: ${{ steps.get_json.outputs.json }} | ||
|
||
packages_split: | ||
name: Split Package ${{ matrix.package.name }} | ||
needs: get_packages | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
package: ${{ fromJson(needs.get_packages.outputs.matrix) }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
# no tag | ||
- | ||
if: "!startsWith(github.ref, 'refs/tags/')" | ||
uses: "symplify/[email protected]" | ||
with: | ||
# ↓ split "src/Tempest/Console" directory | ||
package_directory: '${{ matrix.package.directory }}' | ||
|
||
# ↓ into https://github.com/tempestphp/tempest-console repository | ||
repository_organization: '${{ matrix.package.organization }}' | ||
repository_name: '${{ matrix.package.repository }}' | ||
|
||
# ↓ the user signed under the split commit | ||
user_name: "aidan-casey" | ||
user_email: "[email protected]" | ||
|
||
# with tag | ||
- | ||
if: "startsWith(github.ref, 'refs/tags/')" | ||
uses: "symplify/[email protected]" | ||
with: | ||
tag: ${GITHUB_REF#refs/tags/} | ||
|
||
# ↓ split "src/Tempest/Console" directory | ||
package_directory: '${{ matrix.package.directory }}' | ||
|
||
# ↓ into https://github.com/tempestphp/tempest-console repository | ||
repository_organization: '${{ matrix.package.organization }}' | ||
repository_name: '${{ matrix.package.repository }}' | ||
|
||
# ↓ the user signed under the split commit | ||
user_name: "aidan-casey" | ||
user_email: "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
.idea/ | ||
build/ | ||
sessions/ | ||
vendor/ | ||
src/Tempest/database.sqlite | ||
tests/Fixtures/database.sqlite | ||
tests/Unit/Console/test-console.log | ||
.env | ||
.php-cs-fixer.cache | ||
.phpunit.result.cache | ||
tests/fixtures/database.sqlite | ||
composer.lock | ||
*.cache.php | ||
sessions/ | ||
debug.log | ||
tempest.log | ||
tests/Unit/Console/test-console.log | ||
*.cache.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* The following is heavily borrowed from Ecotone. | ||
* | ||
* This script allows us to dynamically retrieve the package namespace | ||
* and directory from our composer file. This is then used by our GitHub | ||
* action to publish the packages to their appropriate repositories. | ||
* | ||
* @link https://github.com/ecotoneframework/ecotone-dev/blob/main/bin/get-packages | ||
*/ | ||
|
||
const PACKAGES_DIRECTORY = __DIR__ . '/../src/Tempest/'; | ||
|
||
function getPackageNameFromComposerFile(string $composerFile) | ||
{ | ||
$composer = json_decode(file_get_contents($composerFile), true); | ||
|
||
$name = $composer['name'] ?? throw new UnexpectedValueException( | ||
'The referenced package is invalid because it is missing a name: ' . $composerFile | ||
); | ||
|
||
return str_replace('tempest/', '', $name); | ||
} | ||
|
||
/** | ||
* @return array<array-key, array{ | ||
* directory: string, | ||
* name: string, | ||
* package: string, | ||
* organization: string, | ||
* repository: string | ||
* }> | ||
*/ | ||
function getPackages(): array { | ||
$packages = []; | ||
$directoryIterator = new DirectoryIterator(realpath(PACKAGES_DIRECTORY)); | ||
|
||
/** | ||
* @var DirectoryIterator $directory | ||
*/ | ||
foreach ($directoryIterator as $directory) { | ||
if ($directory->isDot()) { | ||
continue; | ||
} | ||
|
||
$file = $directory->getRealPath() . DIRECTORY_SEPARATOR . 'composer.json'; | ||
|
||
if (! file_exists($file)) { | ||
continue; | ||
} | ||
|
||
$name = getPackageNameFromComposerFile($file); | ||
$packages[] = [ | ||
'directory' => $directory->getRealPath(), | ||
'name' => $name, | ||
'package' => 'tempest/' . $name, | ||
'organization' => 'tempestphp', | ||
'repository' => sprintf('tempest-%s', $name), | ||
]; | ||
} | ||
|
||
return $packages; | ||
} | ||
|
||
echo json_encode(getPackages()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symplify\MonorepoBuilder\Config\MBConfig; | ||
|
||
return static function (MBConfig $mbConfig): void { | ||
$mbConfig->packageDirectories([__DIR__ . '/src/Tempest']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Exclude build/test files from the release | ||
.github/ export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
README.md export-ignore |