Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #936 from Symplify/monorepo-test
Browse files Browse the repository at this point in the history
[MonorepoBuilder] Make split command 1-process setup
  • Loading branch information
TomasVotruba authored Jul 2, 2018
2 parents 6cbc6dd + c571dc1 commit 3b166a3
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 171 deletions.
90 changes: 44 additions & 46 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ language: php
php:
- 7.1

#matrix:
# include:
# - php: 7.1
# env: PHPUNIT_FLAGS="--coverage-clover coverage.xml"
# - php: 7.1
# env: CODING_STANDARD=true
# - php: 7.1
# env: COMPOSER_FLAGS="--prefer-lowest"
# - php: 7.2
# env: MONOREPO_SPLIT=true
# env: PHPSTAN=true MONOREPO_SPLIT=true
# - php: 7.2
# env: STANDALONE=true
matrix:
include:
- php: 7.1
env: PHPUNIT_FLAGS="--coverage-clover coverage.xml"
- php: 7.1
env: CODING_STANDARD=true
- php: 7.1
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.2
env: PHPSTAN=true MONOREPO_SPLIT=true
- php: 7.2
env: STANDALONE=true

install:
- composer update $COMPOSER_FLAGS
Expand All @@ -27,42 +26,41 @@ before_script:
- if [[ $PHPUNIT_FLAGS = "" ]]; then phpenv config-rm xdebug.ini; fi

script:
- packages/MonorepoBuilder/bin/monorepo-builder split -v
# - vendor/bin/phpunit $PHPUNIT_FLAGS
# # disable xdebug
# - phpenv config-rm xdebug.ini || return 0
#
# # static analysis
# - if [[ $CODING_STANDARD != "" ]]; then packages/EasyCodingStandard/bin/ecs check packages; fi
# - if [[ $PHPSTAN != "" ]]; then vendor/bin/phpstan analyse packages --level max --configuration phpstan.neon; fi
# - |
# if [[ $STANDALONE != "" ]]; then
# vendor/bin/phpunit packages/BetterPhpDocParser
# vendor/bin/phpunit packages/ChangelogLinker
# vendor/bin/phpunit packages/CodingStandard
# vendor/bin/phpunit packages/EasyCodingStandard
# vendor/bin/phpunit packages/MonorepoBuilder
# vendor/bin/phpunit packages/PackageBuilder
# vendor/bin/phpunit packages/Statie
# vendor/bin/phpunit packages/TokenRunner
# fi
- vendor/bin/phpunit $PHPUNIT_FLAGS
# disable xdebug
- phpenv config-rm xdebug.ini || return 0

# static analysis
- if [[ $CODING_STANDARD != "" ]]; then packages/EasyCodingStandard/bin/ecs check packages; fi
- if [[ $PHPSTAN != "" ]]; then vendor/bin/phpstan analyse packages --level max --configuration phpstan.neon; fi
- |
if [[ $STANDALONE != "" ]]; then
vendor/bin/phpunit packages/BetterPhpDocParser
vendor/bin/phpunit packages/ChangelogLinker
vendor/bin/phpunit packages/CodingStandard
vendor/bin/phpunit packages/EasyCodingStandard
vendor/bin/phpunit packages/MonorepoBuilder
vendor/bin/phpunit packages/PackageBuilder
vendor/bin/phpunit packages/Statie
vendor/bin/phpunit packages/TokenRunner
fi
after_script:
# upload coverage.xml to Coveralls
# - |
# if [[ $PHPUNIT_FLAGS != "" ]]; then
# wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
# php coveralls.phar --verbose;
# fi
# split monorepo to packages (done via Travis Cron Job)
# - |
# if [[ $TRAVIS_EVENT_TYPE = "cron" && $MONOREPO_SPLIT != "" ]]; then
# if [[ $MONOREPO_SPLIT != "" ]]; then
# packages/MonorepoBuilder/bin/monorepo-builder split -v
# fi
# - |
# echo $TRAVIS_EVENT_TYPE
# echo $MONOREPO_SPLIT
- |
if [[ $PHPUNIT_FLAGS != "" ]]; then
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
php coveralls.phar --verbose;
fi
split monorepo to packages (done via Travis Cron Job)
- |
# if [[ $TRAVIS_EVENT_TYPE = "cron" && $MONOREPO_SPLIT != "" ]]; then
if [[ $MONOREPO_SPLIT != "" ]]; then
packages/MonorepoBuilder/bin/monorepo-builder split -v
fi
- |
echo $TRAVIS_EVENT_TYPE
echo $MONOREPO_SPLIT
notifications:
email: never
16 changes: 8 additions & 8 deletions monorepo-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ parameters:
'phpunit/phpunit': '*'

directories_to_repositories:
# packages/BetterPhpDocParser: 'git@github.com:Symplify/BetterPhpDocParser.git'
# packages/PackageBuilder: 'git@github.com:Symplify/PackageBuilder.git'
# packages/TokenRunner: 'git@github.com:Symplify/TokenRunner.git'
# packages/EasyCodingStandard: 'git@github.com:Symplify/EasyCodingStandard.git'
# packages/EasyCodingStandardTester: 'git@github.com:Symplify/EasyCodingStandardTester.git'
# packages/CodingStandard: 'git@github.com:Symplify/CodingStandard.git'
# packages/Statie: 'git@github.com:Symplify/Statie.git'
# packages/ChangelogLinker: 'git@github.com:Symplify/ChangelogLinker.git'
packages/BetterPhpDocParser: 'git@github.com:Symplify/BetterPhpDocParser.git'
packages/PackageBuilder: 'git@github.com:Symplify/PackageBuilder.git'
packages/TokenRunner: 'git@github.com:Symplify/TokenRunner.git'
packages/EasyCodingStandard: 'git@github.com:Symplify/EasyCodingStandard.git'
packages/EasyCodingStandardTester: 'git@github.com:Symplify/EasyCodingStandardTester.git'
packages/CodingStandard: 'git@github.com:Symplify/CodingStandard.git'
packages/Statie: 'git@github.com:Symplify/Statie.git'
packages/ChangelogLinker: 'git@github.com:Symplify/ChangelogLinker.git'
packages/MonorepoBuilder: 'git@github.com:Symplify/MonorepoBuilder.git'
190 changes: 97 additions & 93 deletions packages/MonorepoBuilder/packages/Split/bash/subsplit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@
#
# includes merge of PRs
# - https://github.com/dflydev/git-subsplit/pull/30/files
#
# exit code:
# 1 git add-remote/pull/fetch operation failed
# 2 git push operation failed
# 3 failed on git subtree command

# show help if there are no params passed
if [ $# -eq 0 ]; then
set -- -h
fi

OPTS_SPEC="\
subsplit.sh <splits> --branches=<branches> --tags=<tags>
subsplit.sh --from-directory=<from-directory> --to-repository=<to-repository> --repository=<repository> --branch=<branch> --tag=<tag>
For example:
subsplit.sh packages/MonorepoBuilder:git@github.com:Symplify/MonorepoBuilder.git --branches=master --tags=v5.0
subsplit.sh --from-directory=packages/MonorepoBuilder --to-repository=git@github.com:Symplify/MonorepoBuilder.git --branch=master --tag=v5.0
--
h,help show the help
debug show debug output
repository= repository to split from
branches= publish for listed branches, e.g '--branches=master', '--branches=master dev',
tags= publish for listed tags, e.g. '--tags=v5.0', '--tags=v5.0 v5.5'
from-directory= directory with the package to split, e.g. '--from-directory=packages/MonorepoBuilder'
to-repository= repository to split into, e.g. '--to-repository=git@github.com:Symplify/MonorepoBuilder.git'
repository= repository to split from, e.g. '--repository=.git' for current one
branch= publish branch, e.g '--branch=master'
tag= publish tag, e.g. '--tags=v5.0'
debug show debug output
h,help show the help
"

# show help if there are no params passed
if [ $# -eq 0 ]; then
set -- -h
fi

eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"

# We can run this from anywhere.
Expand All @@ -49,10 +47,11 @@ then
fi

COMMAND=
SPLITS=
FROM_DIRECTORY=
TO_REPOSITORY=
REPOSITORY=
BRANCHES=
TAGS=
BRANCH=
TAG=
DRY_RUN=
VERBOSE=

Expand All @@ -62,18 +61,31 @@ subsplit_main()
opt="$1"
shift
case "$opt" in
--debug) VERBOSE=1 ;;
--branches) BRANCHES="$1"; shift ;;
--tags) TAGS="$1"; shift ;;
--from-directory) FROM_DIRECTORY="$1"; shift ;;
--to-repository) TO_REPOSITORY="$1"; shift ;;
--repository) REPOSITORY="$1"; shift ;;
--branch) BRANCH="$1"; shift ;;
--tag) TAG="$1"; shift ;;
--debug) VERBOSE=1 ;;
--) break ;;
*) die "Unexpected option: $opt" ;;
esac
done

if [ $# -lt 1 ]; then die "publish command requires splits to be passed as first argument"; fi
SPLITS="$1"
shift
# report missing required options
if [ -z "$FROM_DIRECTORY" ]
then
echo "Command requires --from-repository option to be filled"
exit 1
fi

if [ -z "$TO_REPOSITORY" ]
then
echo "Command requires --to-repository option to be filled"
exit 1
fi

subsplit_init
subsplit_publish
}

Expand All @@ -87,83 +99,75 @@ subsplit_init()
fi

echo "Initializing subsplit from '${REPOSITORY}' to temp directory"

git clone -q "$REPOSITORY" . || (echo "Could not clone repository" && exit 1)
}

subsplit_publish()
{
subsplit_init
REMOTE_NAME=$(echo "$TO_REPOSITORY" | git hash-object --stdin)

for SPLIT in $SPLITS
do
SUBPATH=$(echo "$SPLIT" | cut -f1 -d:)
REMOTE_URL=$(echo "$SPLIT" | cut -f2- -d:)
REMOTE_NAME=$(echo "$SPLIT" | git hash-object --stdin)
if ! git remote | grep "^${REMOTE_NAME}$" >/dev/null
then
git remote add "$REMOTE_NAME" "$TO_REPOSITORY" || (echo "Failed adding remote $REMOTE_NAME $TO_REPOSITORY" && exit 1)
fi

echo "Syncing ${FROM_DIRECTORY} -> ${TO_REPOSITORY}"

if ! git remote | grep "^${REMOTE_NAME}$" >/dev/null
# split for branch
if [ -n "$BRANCH" ]
then
if ! git show-ref --quiet --verify -- "refs/remotes/origin/${BRANCH}"
then
git remote add "$REMOTE_NAME" "$REMOTE_URL" || (echo "Failed adding remote $REMOTE_NAME $REMOTE_URL" && exit 1)
echo " - skipping head '${BRANCH}' (does not exist)"
continue
fi
LOCAL_BRANCH="${REMOTE_NAME}-branch-${BRANCH}"

echo "Syncing ${SUBPATH} -> ${REMOTE_URL}"

# split for branches
for BRANCH in $BRANCHES
do
if ! git show-ref --quiet --verify -- "refs/remotes/origin/${BRANCH}"
then
echo " - skipping head '${BRANCH}' (does not exist)"
continue
fi
LOCAL_BRANCH="${REMOTE_NAME}-branch-${BRANCH}"

echo " - syncing branch '${BRANCH}'"

git checkout master >/dev/null 2>&1 || (echo "Failed while git checkout master" && exit 1)
git branch -D "$LOCAL_BRANCH" >/dev/null 2>&1
git branch -D "${LOCAL_BRANCH}-checkout" >/dev/null 2>&1
git checkout -b "${LOCAL_BRANCH}-checkout" "origin/${BRANCH}" >/dev/null 2>&1 || (echo "Failed while git checkout" && exit 1)
git subtree split -q --prefix="$SUBPATH" --branch="$LOCAL_BRANCH" "origin/${BRANCH}" >/dev/null || (echo "Failed while git subtree split for BRANCHES" && exit 1)
RETURNCODE=$?

if [ $RETURNCODE -eq 0 ]
then
git push -q --force $REMOTE_NAME ${LOCAL_BRANCH}:${BRANCH} || (echo "Failed pushing branchs to remote repo" && exit 1)
fi
done

# split for tags
for TAG in $TAGS
do
if ! git show-ref --quiet --verify -- "refs/tags/${TAG}"
then
echo " - skipping tag '${TAG}' (does not exist)"
continue
fi
LOCAL_TAG="${REMOTE_NAME}-tag-${TAG}"

if git branch | grep "${LOCAL_TAG}$" >/dev/null
then
echo " - skipping tag '${TAG}' (already synced)"
continue
fi

echo " - syncing tag '${TAG}'"
echo " - deleting '${LOCAL_TAG}'"
git branch -D "$LOCAL_TAG" >/dev/null 2>&1

echo " - subtree split for '${TAG}'"
git subtree split -q --prefix="$SUBPATH" --branch="$LOCAL_TAG" "$TAG" >/dev/null || (echo "Failed while git subtree split for TAGS" && exit 1)
RETURNCODE=$?

echo " - subtree split for '${TAG}' [DONE]"
if [ $RETURNCODE -eq 0 ]
then
git push -q --force ${REMOTE_NAME} ${LOCAL_TAG}:refs/tags/${TAG} || (echo "Failed pushing tags to remote repo" && exit 1)
fi
done
done
echo " - syncing branch '${BRANCH}'"

git checkout master >/dev/null 2>&1 || (echo "Failed while git checkout master" && exit 1)
git branch -D "$LOCAL_BRANCH" >/dev/null 2>&1
git branch -D "${LOCAL_BRANCH}-checkout" >/dev/null 2>&1
git checkout -b "${LOCAL_BRANCH}-checkout" "origin/${BRANCH}" >/dev/null 2>&1 || (echo "Failed while git checkout" && exit 1)
git subtree split -q --prefix="$FROM_DIRECTORY" --branch="$LOCAL_BRANCH" "origin/${BRANCH}" >/dev/null || (echo "Failed while git subtree split for ${BRANCH}" && exit 1)
RETURNCODE=$?

if [ $RETURNCODE -eq 0 ]
then
git push -q --force $REMOTE_NAME ${LOCAL_BRANCH}:${BRANCH} || (echo "Failed pushing branchs to remote repo" && exit 1)
fi
fi

# split for tag
if [ -n "$TAG" ]
then
if ! git show-ref --quiet --verify -- "refs/tags/${TAG}"
then
echo " - skipping tag '${TAG}' (does not exist)"
continue
fi
LOCAL_TAG="${REMOTE_NAME}-tag-${TAG}"

if git branch | grep "${LOCAL_TAG}$" >/dev/null
then
echo " - skipping tag '${TAG}' (already synced)"
continue
fi

echo " - syncing tag '${TAG}'"
echo " - deleting '${LOCAL_TAG}'"
git branch -D "$LOCAL_TAG" >/dev/null 2>&1

echo " - subtree split for '${TAG}'"
git subtree split -q --prefix="$FROM_DIRECTORY" --branch="$LOCAL_TAG" "$TAG" >/dev/null || (echo "Failed while git subtree split for TAGS" && exit 1)
RETURNCODE=$?

echo " - subtree split for '${TAG}' [DONE]"
if [ $RETURNCODE -eq 0 ]
then
git push -q --force ${REMOTE_NAME} ${LOCAL_TAG}:refs/tags/${TAG} || (echo "Failed pushing tags to remote repo" && exit 1)
fi
fi
}

subsplit_main "$@"
Loading

0 comments on commit 3b166a3

Please sign in to comment.