Skip to content

Commit

Permalink
Merge pull request #64 from kdambekalns/task/branch-handling-changes
Browse files Browse the repository at this point in the history
TASK: Some code (style) tweaks
  • Loading branch information
robertlemke committed Aug 25, 2022
2 parents 683c88e + b3a133c commit afe39cb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 86 deletions.
29 changes: 7 additions & 22 deletions ComposerManifestMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
exit(1);
}

/**
* @param array $joinedManifest
* @param array $manifestData
* @param string $sectionKey
* @return array
*/
function mergeArraySection($joinedManifest, $manifestData, $sectionKey)
function mergeArraySection(array $joinedManifest, array $manifestData, string $sectionKey): array
{
if (isset($manifestData[$sectionKey])) {
if ($sectionKey !== 'require') {
Expand All @@ -30,14 +24,7 @@ function mergeArraySection($joinedManifest, $manifestData, $sectionKey)
return $joinedManifest;
}

/**
* @param array $joinedManifest
* @param array $manifestData
* @param string $sectionKey
* @param string $packageName
* @return array
*/
function mergeAutoloadSection($joinedManifest, $manifestData, $sectionKey, $packageName)
function mergeAutoloadSection(array $joinedManifest, array $manifestData, string $sectionKey, string $packageName): array
{
if (isset($manifestData[$sectionKey])) {
if (!isset($joinedManifest[$sectionKey])) {
Expand All @@ -48,7 +35,7 @@ function mergeAutoloadSection($joinedManifest, $manifestData, $sectionKey, $pack
if (!is_array($folders)) {
$folders = [$folders];
}
$folders = array_map(function ($folder) use ($packageName) {
$folders = array_map(static function ($folder) use ($packageName) {
return implode('/', [$packageName, $folder]);
}, $folders);

Expand All @@ -66,15 +53,15 @@ function mergeAutoloadSection($joinedManifest, $manifestData, $sectionKey, $pack

$composerManifests = glob('*/composer.json');

$joinedManifest = json_decode(file_get_contents('.composer.json'), true);
$joinedManifest = json_decode(file_get_contents('.composer.json'), true, 512, JSON_THROW_ON_ERROR);
// As JSON doesn't allow for any comments this is added as manifest key.
$joinedManifest['extra']['neos']['warning'] = 'AUTOGENERATED FILE, ONLY MODIFY THE .composer.json IN THIS DIRECTORY AND RUN THE COMPOSER MANIFEST MERGER SCRIPT PROVIDED BY THE BUILD ESSENTIALS PACKAGE.';

$joinedRepositoryPackages = [];

foreach ($composerManifests as $manifestFilepath) {
$packageName = trim(dirname($manifestFilepath), '/');
$manifestData = json_decode(file_get_contents($manifestFilepath), true);
$manifestData = json_decode(file_get_contents($manifestFilepath), true, 512, JSON_THROW_ON_ERROR);

$joinedRepositoryPackages[] = $manifestData['name'];

Expand All @@ -98,7 +85,7 @@ function mergeAutoloadSection($joinedManifest, $manifestData, $sectionKey, $pack
}

if (isset($extras['neos']['installer-resource-folders']) && is_array($extras['neos']['installer-resource-folders'])) {
$extras['neos']['installer-resource-folders'] = array_map(function ($resourceFolder) use ($packageName) {
$extras['neos']['installer-resource-folders'] = array_map(static function ($resourceFolder) use ($packageName) {
return $packageName . '/' . $resourceFolder;
}, $extras['neos']['installer-resource-folders']);
}
Expand All @@ -117,10 +104,8 @@ function mergeAutoloadSection($joinedManifest, $manifestData, $sectionKey, $pack
$joinedManifest['replace'][$containedPackageName] = 'self.version';
}

$joinedComposerJson = json_encode($joinedManifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
$joinedComposerJson = json_encode($joinedManifest, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
file_put_contents('composer.json', $joinedComposerJson);

echo('Written the following merged ' . getcwd() . '/composer.json' . PHP_EOL . PHP_EOL);
echo $joinedComposerJson;

exit(0);
28 changes: 12 additions & 16 deletions FilterStabilityFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@
* simply specifying a stability flag for a package in the typo3
* vendor namespace.
*/
$manifest = json_decode(file_get_contents('composer.json'), TRUE);
$manifest = json_decode(file_get_contents('composer.json'), true, 512, JSON_THROW_ON_ERROR);

if (isset($manifest['require'])) {
foreach ($manifest['require'] as $key => $requirement) {
if (strpos($key, 'typo3/') === 0 && $requirement[0] === '@') {
unset($manifest['require'][$key]);
}
}
foreach ($manifest['require'] as $key => $requirement) {
if ($requirement[0] === '@' && strpos($key, 'typo3/') === 0) {
unset($manifest['require'][$key]);
}
}
}
if (isset($manifest['require-dev'])) {
foreach ($manifest['require-dev'] as $key => $requirement) {
if (strpos($key, 'typo3/') === 0 && $requirement[0] === '@') {
unset($manifest['require-dev'][$key]);
}
}
foreach ($manifest['require-dev'] as $key => $requirement) {
if ($requirement[0] === '@' && strpos($key, 'typo3/') === 0) {
unset($manifest['require-dev'][$key]);
}
}
}

if (version_compare(PHP_VERSION, '5.4.0', '<')) {
file_put_contents('composer.json', json_encode($manifest));
} else {
file_put_contents('composer.json', json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
file_put_contents('composer.json', json_encode($manifest, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
96 changes: 48 additions & 48 deletions ReleaseHelpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,68 @@

# arguments: VERSION, BRANCH, BUILD_URL, DIR (optional)
function tag_version {
local VERSION=$1
local BRANCH=$2
local BUILD_URL=$3
local DIR=$4
local VERSION=$1
local BRANCH=$2
local BUILD_URL=$3
local DIR=$4

if [ -z "${DIR}" ] ; then
git tag -f -a -m "TASK: Tag as version ${VERSION}" -m "See ${BUILD_URL}" ${VERSION}
else
git --git-dir "${DIR}/.git" tag -f -a -m "TASK: Tag as version ${VERSION}" -m "See ${BUILD_URL}" ${VERSION}
fi
if [ -z "${DIR}" ]; then
git tag -f -a -m "TASK: Tag as version ${VERSION}" -m "See ${BUILD_URL}" "${VERSION}"
else
git --git-dir "${DIR}/.git" tag -f -a -m "TASK: Tag as version ${VERSION}" -m "See ${BUILD_URL}" "${VERSION}"
fi
}

# arguments: TAG, DIR (optional)
function push_tag {
local TAG=$1
local DIR=$2
local TAG=$1
local DIR=$2

if [ -z "${DIR}" ] ; then
git push -f origin ${TAG}:refs/tags/${TAG}
else
git --git-dir "${DIR}/.git" push -f origin ${TAG}:refs/tags/${TAG}
fi
if [ -z "${DIR}" ]; then
git push -f origin "${TAG}:refs/tags/${TAG}"
else
git --git-dir "${DIR}/.git" push -f origin "${TAG}:refs/tags/${TAG}"
fi
}

# arguments: BRANCH, BUILD_URL, VERSION, DIR (optional)
function commit_manifest_update {
local BRANCH=$1
local BUILD_URL=$2
local VERSION=$3
local DIR=$4
local BRANCH=$1
local BUILD_URL=$2
local VERSION=$3
local DIR=$4

if [ -z "${DIR}" ] ; then
if [[ `git status --porcelain composer.json "*/composer.json"` ]] ; then
if [[ `git status --porcelain composer.json` ]] ; then
git add composer.json
fi
if [[ `git status --porcelain "*/composer.json"` ]] ; then
git add */composer.json
fi
git commit -m "TASK: Update composer manifest for ${VERSION}" -m "See ${BUILD_URL}"
fi
else
if [[ `git --git-dir "${DIR}/.git" --work-tree "${DIR}" status --porcelain composer.json "*/composer.json"` ]] ; then
if [[ `git --git-dir "${DIR}/.git" --work-tree "${DIR}" status --porcelain composer.json` ]] ; then
git --git-dir "${DIR}/.git" --work-tree "${DIR}" add composer.json
fi
if [[ `git --git-dir "${DIR}/.git" --work-tree "${DIR}" status --porcelain "*/composer.json"` ]] ; then
git --git-dir "${DIR}/.git" --work-tree "${DIR}" add "*/composer.json"
fi
git --git-dir "${DIR}/.git" --work-tree "${DIR}" commit -m "TASK: Update composer manifest for ${VERSION}" -m "See ${BUILD_URL}"
fi
fi
if [ -z "${DIR}" ]; then
if [[ $(git status --porcelain composer.json "*/composer.json") ]]; then
if [[ $(git status --porcelain composer.json) ]]; then
git add composer.json
fi
if [[ $(git status --porcelain "*/composer.json") ]]; then
git add ./*/composer.json
fi
git commit -m "TASK: Update composer manifest for ${VERSION}" -m "See ${BUILD_URL}"
fi
else
if [[ $(git --git-dir "${DIR}/.git" --work-tree "${DIR}" status --porcelain composer.json "*/composer.json") ]]; then
if [[ $(git --git-dir "${DIR}/.git" --work-tree "${DIR}" status --porcelain composer.json) ]]; then
git --git-dir "${DIR}/.git" --work-tree "${DIR}" add composer.json
fi
if [[ $(git --git-dir "${DIR}/.git" --work-tree "${DIR}" status --porcelain "*/composer.json") ]]; then
git --git-dir "${DIR}/.git" --work-tree "${DIR}" add "*/composer.json"
fi
git --git-dir "${DIR}/.git" --work-tree "${DIR}" commit -m "TASK: Update composer manifest for ${VERSION}" -m "See ${BUILD_URL}"
fi
fi
}

# arguments: BRANCH, DIR (optional)
function push_branch {
local BRANCH=$1
local DIR=$2
local BRANCH=$1
local DIR=$2

if [ -z "${DIR}" ] ; then
git push origin ${BRANCH}
else
git --git-dir "${DIR}/.git" push origin ${BRANCH}
fi
if [ -z "${DIR}" ]; then
git push origin "${BRANCH}"
else
git --git-dir "${DIR}/.git" push origin "${BRANCH}"
fi
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Neos Flow Build Toolchain Essentials",
"license": ["LGPL-3.0+"],
"require": {
"php": "^7.4",
"neos/composer-plugin": "^2.0.0",
"symfony/console": "^5.1",
"guzzlehttp/guzzle": "^6.0 || ^7.0"
Expand Down

0 comments on commit afe39cb

Please sign in to comment.