-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3f98a56
Showing
17 changed files
with
911 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.yml] | ||
indent_size = 2 |
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 @@ | ||
* text=auto eol=lf |
Validating CODEOWNERS rules …
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 @@ | ||
* @erkenes |
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,59 @@ | ||
name: Build Docker-Image | ||
|
||
on: | ||
push: | ||
tags: [ '*.*.*' ] | ||
|
||
env: | ||
# Use docker.io for Docker Hub if empty | ||
REGISTRY: ghcr.io | ||
# github.repository as <account>/<repo> | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
|
||
jobs: | ||
build-php: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Workaround: https://github.com/docker/build-push-action/issues/461 | ||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf | ||
|
||
# Login against a Docker registry except on PR | ||
# https://github.com/docker/login-action | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Extract metadata (tags, labels) for Docker | ||
# https://github.com/docker/metadata-action | ||
- name: Extract Docker metadata - php | ||
id: meta-php | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/php | ||
|
||
# Build and push Docker image with Buildx (don't push on PR) | ||
# https://github.com/docker/build-push-action | ||
- name: Build and push Docker image - php | ||
id: build-and-push-php | ||
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a | ||
with: | ||
context: . | ||
file: ./DockerfileBuild | ||
push: true | ||
tags: ${{ steps.meta-php.outputs.tags }} | ||
labels: ${{ steps.meta-php.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
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,3 @@ | ||
.idea/ | ||
vendor/ | ||
Slicer/git-subsplit-temporary |
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,137 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ErkEnes\MonorepoSplit; | ||
|
||
class Config | ||
{ | ||
public function __construct( | ||
private readonly string $repositoryProtocol, | ||
private readonly string $repositoryHost, | ||
private readonly string $repositoryOrganization, | ||
private readonly string $repositoryName, | ||
private readonly string $accessToken, | ||
private readonly string $allowedRefsPattern, | ||
private readonly string $defaultBranch, | ||
private readonly string $targetBranch, | ||
private readonly string $packageDirectory, | ||
private readonly string $remoteRepository, | ||
private readonly ?string $remoteRepositoryAccessToken = null | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRepositoryProtocol(): string | ||
{ | ||
return $this->repositoryProtocol; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRepositoryHost(): string | ||
{ | ||
return $this->repositoryHost; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRepositoryOrganization(): string | ||
{ | ||
return $this->repositoryOrganization; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRepositoryName(): string | ||
{ | ||
return $this->repositoryName; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAccessToken(): string | ||
{ | ||
return $this->accessToken; | ||
} | ||
|
||
/** | ||
* @param bool $withAccessToken | ||
* @return string | ||
*/ | ||
public function getRepositoryUrl(bool $withAccessToken = false): string | ||
{ | ||
$repositoryUrl = $this->repositoryHost . '/' . $this->repositoryOrganization . '/' . $this->repositoryName . '.git'; | ||
|
||
return $withAccessToken ? $this->repositoryProtocol . $this->accessToken . '@' . $repositoryUrl : $this->repositoryProtocol . $repositoryUrl; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAllowedRefsPattern(): string | ||
{ | ||
return $this->allowedRefsPattern; | ||
} | ||
|
||
public function getSplits(): array | ||
{ | ||
return [ | ||
$this->getPackageDirectory() . ':' . $this->getRemoteRepository() | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDefaultBranch(): string | ||
{ | ||
return $this->defaultBranch; | ||
} | ||
|
||
/** | ||
* @param bool $fullPath | ||
* @return string | ||
*/ | ||
public function getTargetBranch(bool $fullPath = false): string | ||
{ | ||
return $fullPath ? 'refs/heads/' . $this->targetBranch : $this->targetBranch; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPackageDirectory(): string | ||
{ | ||
return $this->packageDirectory; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRemoteRepository(): string | ||
{ | ||
return $this->remoteRepositoryAccessToken | ||
? $this->insertStringBetween($this->remoteRepository, 'https://', $this->remoteRepositoryAccessToken . '@') | ||
: $this->remoteRepository; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getRemoteRepositoryAccessToken(): ?string | ||
{ | ||
return $this->remoteRepositoryAccessToken; | ||
} | ||
|
||
private function insertStringBetween ($string, $keyword, $body): string | ||
{ | ||
return substr_replace($string, $body, strpos($string, $keyword) + strlen($keyword), 0); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ErkEnes\MonorepoSplit; | ||
|
||
use ErkEnes\MonorepoSplit\Exception\ConfigurationException; | ||
|
||
class ConfigFactory | ||
{ | ||
private const GITHUB = 'GITHUB'; | ||
private const DEFAULT_BRANCH = 'main'; | ||
|
||
private PublicAccessTokenResolver $publicAccessTokenResolver; | ||
|
||
public function __construct() | ||
{ | ||
$this->publicAccessTokenResolver = new PublicAccessTokenResolver(); | ||
} | ||
|
||
public function create(array $env): Config | ||
{ | ||
$accessToken = $this->publicAccessTokenResolver->resolve($env); | ||
|
||
return $this->createFormEnv($env, $accessToken, self::GITHUB); | ||
} | ||
|
||
protected function createFormEnv(array $env, string $accessToken, string $ciPlatform): Config | ||
{ | ||
$envPrefix = $ciPlatform === self::GITHUB ? 'INPUT_' : ''; | ||
|
||
return new Config( | ||
repositoryProtocol: $env[$envPrefix . 'REPOSITORY_PROTOCOL'] ?? throw new ConfigurationException('Repository Protocol is missing'), | ||
repositoryHost: $env[$envPrefix . 'REPOSITORY_HOST'] ?? throw new ConfigurationException('Repository Host is missing'), | ||
repositoryOrganization: $env[$envPrefix . 'REPOSITORY_ORGANIZATION'] ?? throw new ConfigurationException('Repository Organization is missing'), | ||
repositoryName: $env[$envPrefix . 'REPOSITORY_NAME'] ?? throw new ConfigurationException('Repository Name is missing'), | ||
accessToken: $accessToken ?? throw new ConfigurationException('Access Token is missing'), | ||
allowedRefsPattern: $env[$envPrefix . 'ALLOWED_REFS_PATTERN'] ?? throw new ConfigurationException('Allowed Refs Pattern is missing'), | ||
defaultBranch: $env[$envPrefix . 'DEFAULT_BRANCH'] ?? self::DEFAULT_BRANCH, | ||
targetBranch: $env[$envPrefix . 'TARGET_BRANCH'] ?? throw new ConfigurationException('Target Branch is missing'), | ||
packageDirectory: $env[$envPrefix . 'PACKAGE_DIRECTORY'] ?? throw new ConfigurationException('Package Directory is missing'), | ||
remoteRepository: $env[$envPrefix . 'REMOTE_REPOSITORY'] ?? throw new ConfigurationException('Remote Repository is missing'), | ||
remoteRepositoryAccessToken: $env[$envPrefix . 'REMOTE_REPOSITORY_ACCESS_TOKEN'] ?? null, | ||
); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ErkEnes\MonorepoSplit\Exception; | ||
|
||
use InvalidArgumentException; | ||
|
||
final class ConfigurationException extends InvalidArgumentException | ||
{ | ||
} |
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,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ErkEnes\MonorepoSplit; | ||
|
||
use ErkEnes\MonorepoSplit\Exception\ConfigurationException; | ||
|
||
final class PublicAccessTokenResolver | ||
{ | ||
private const GITHUB_TOKEN = 'GITHUB_TOKEN'; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private const POSSIBLE_TOKEN_ENVS = [ | ||
self::GITHUB_TOKEN | ||
]; | ||
|
||
/** | ||
* @param array<string, mixed> $env | ||
*/ | ||
public function resolve(array $env): string | ||
{ | ||
if (isset($env[self::GITHUB_TOKEN])) { | ||
return $env[self::GITHUB_TOKEN]; | ||
} | ||
|
||
$message = sprintf( | ||
'Public access token is missing, add it via: "%s"', | ||
implode('", "', self::POSSIBLE_TOKEN_ENVS) | ||
); | ||
|
||
throw new ConfigurationException($message); | ||
} | ||
} |
Oops, something went wrong.