Skip to content

Commit

Permalink
[Internal] Update monorepo builder
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Jun 30, 2024
1 parent ca20d88 commit 6a05964
Show file tree
Hide file tree
Showing 41 changed files with 1,739 additions and 3,677 deletions.
17 changes: 17 additions & 0 deletions .github/actions/git-split/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# THIS IS BASE IMAGE
FROM php:8.3-cli-alpine

RUN apk add --no-cache git git-subtree

RUN git config --system --add safe.directory /github/workspace

RUN git config --system --add safe.directory /tmp/monorepo_split/build_directory

# directory inside docker
WORKDIR /splitter

# make local content available inside docker - copies to /splitter
COPY entrypoint.sh .

# see https://nickjanetakis.com/blog/docker-tip-86-always-make-your-entrypoint-scripts-executable
ENTRYPOINT ["sh", "/splitter/entrypoint.sh"]
39 changes: 39 additions & 0 deletions .github/actions/git-split/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'Monorepo Split'
description: 'Split monorepo folder to repository'
author: "Martin Poirier Théorêt <[email protected]>"

inputs:
user_name:
description: 'Git User Name'
required: true
user_email:
description: 'Git User Email'
required: true
access_token:
description: 'GitHub Access Token'
required: true
git_ref:
description: 'Git Ref'
required: true
source_repository:
description: 'Source Repository'
required: true
source_directory:
description: 'Local package directory'
required: true
target_repository:
description: 'Target Repository'
required: true

runs:
using: 'docker'
image: 'Dockerfile'
args:
# "GitHub stores input parameters as environment variables" - important!!!
- ${{ inputs.user_name }} # => INPUT_USER_NAME
- ${{ inputs.user_email }}
- ${{ inputs.access_token }}
- ${{ inputs.git_ref }}
- ${{ inputs.source_repository }}
- ${{ inputs.source_directory }}
- ${{ inputs.target_repository }}
35 changes: 35 additions & 0 deletions .github/actions/git-split/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

set -e

echo "Configure git with user email ${INPUT_USER_EMAIL} and user name ${INPUT_USER_NAME}"
git config --global user.email "${INPUT_USER_EMAIL}"
git config --global user.name "${INPUT_USER_NAME}"

echo "Clone the source repository repository https://github.com/${INPUT_SOURCE_REPOSITORY}"
git clone https://${INPUT_ACCESS_TOKEN}@github.com/${INPUT_SOURCE_REPOSITORY} to_split
cd to_split

echo "Add the remote repository"
git remote add split https://${INPUT_ACCESS_TOKEN}@github.com/${INPUT_TARGET_REPOSITORY}.git

# Extract the tag or branch name from GITHUB_REF
REF_NAME="${INPUT_GIT_REF##*/}"

echo "INPUT_GIT_REF: ${INPUT_GIT_REF}"
echo "REF_NAME: ${REF_NAME}"

# Check if we are on a tag or branch
if git show-ref --tags "$REF_NAME" >/dev/null 2>&1; then
echo "We are on a tag"

git checkout -b temp_branch ${REF_NAME}
git subtree split --prefix=${INPUT_SOURCE_DIRECTORY} -b temp_split_branch
git push split temp_split_branch:refs/tags/${REF_NAME}
else
echo "We are on a branch"

git checkout ${REF_NAME}
git subtree split --prefix=${INPUT_SOURCE_DIRECTORY} -b temp_split_branch
git push split temp_split_branch:refs/heads/${REF_NAME}
fi
2 changes: 1 addition & 1 deletion .github/workflows/after_splitting_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: 'Composer Setup'
run: |
composer install --no-progress
vendor-bin/monorepo/vendor/bin/monorepo-builder localize-composer-paths
vendor-bin/monorepo/vendor/bin/monorepo-builder localize-composer-paths composer.json
cd packages/${{ matrix.package_name }}
composer update --no-progress
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/split.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Split Test

on:
push:
branches:
- 'master'

tags:
- '*'

jobs:
split:
runs-on: ubuntu-latest
strategy:
matrix:
packages:
- application
- aws-tool-kit
- console
- core
- cron-job
- dependency-injection
- doctrine-extra
- entity-migrator
- fixer
- framework-extra-bundle
- log
- mailer
- messenger
- open-api
- process
- profiling
- security
- sonata-import-bundle
- sonata-integration-bundle
- sonata-extra-bundle
- tester
- tester-bundle
- user-bundle
- validator
- workflow
steps:
-
uses: actions/checkout@v4
with:
fetch-depth: 0

-
uses: "./.github/actions/git-split"
with:
user_name: 'mpoiriert'
user_email: '[email protected]'
access_token: '${{ secrets.GH_ACCESS_TOKEN }}'
git_ref: '${{ github.ref }}'
source_repository: 'mpoiriert/test-monorepo'
source_directory: 'split/${{ matrix.packages }}'
target_repository: 'mpoiriert/${{ matrix.packages }}'
Loading

0 comments on commit 6a05964

Please sign in to comment.