Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/actions/ci-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ci-env
description: Load CI env
runs:
using: composite
steps:
-
name: Composer cache
uses: actions/cache@v2
with:
path: vendor
key: composer-${{ hashFiles('composer.json') }}
restore-keys: composer-${{ hashFiles('composer.json') }}
-
shell: bash
run: bin/ci/env
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI
on: [push]
jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: bin/ci/phpcs

phpstan:
runs-on: ubuntu-latest
strategy:
matrix:
php: [--php=8.1, --php=8.2]
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/ci-env
- run: bin/ci/phpstan ${{ matrix.php }}

phpdd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/ci-env
- run: bin/ci/phpdd

composer-require-checker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/ci-env
- run: bin/ci/composer-require-checker

composer-validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: bin/ci/composer-validate

shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: bin/ci/shellcheck

unused-scanner:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: bin/ci/unused-scanner
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/.idea/
/var/
/vendor/
9 changes: 9 additions & 0 deletions bin/ci/composer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

php8.1 /usr/local/bin/composer "${@}"
9 changes: 9 additions & 0 deletions bin/ci/composer-require-checker
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

composer-require-checker --ansi "${@}"
9 changes: 9 additions & 0 deletions bin/ci/composer-validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

composer validate --ansi --strict
10 changes: 10 additions & 0 deletions bin/ci/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh

DOCKER_IMAGE_NAME="${CI_DOCKER_IMAGE_NAME}" \
DOCKER_FILE_PATH="${ROOT_PATH}"/docker/ci/Dockerfile \
source "${ROOT_PATH}"/bin/docker-build.inc.bash
9 changes: 9 additions & 0 deletions bin/ci/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

"${ROOT_PATH}"/bin/composer install
22 changes: 22 additions & 0 deletions bin/ci/phpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

if [ ! -d "${ROOT_PATH}"/var/ci/phpcs ]; then
mkdir -p "${ROOT_PATH}"/var/ci/phpcs
fi

phpcs \
-p \
--warning-severity=0 \
--ignore=/vendor/,/var/,*Enum.php \
--bootstrap=config/ci/phpcs.php \
--standard="${COMPOSER_HOME}"/vendor/steevanb/php-code-sniffs/src/Steevanb/ruleset.xml \
--report=steevanb\\PhpCodeSniffs\\Reports\\Steevanb \
--cache="${ROOT_PATH}"/var/ci/phpcs/cache \
. \
"${@}"
9 changes: 9 additions & 0 deletions bin/ci/phpdd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

phpdd --ansi --exclude=vendor,var "${@}" .
39 changes: 39 additions & 0 deletions bin/ci/phpstan
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"

source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

PHP_VERSION=
PHPSTAN_PARAMETERS=
CLEAR_CACHE=false
for arg in "${@}"; do
if [ "${arg:0:6}" == "--php=" ]; then
PHP_VERSION="${arg:6}"
elif [ "${arg}" == "--clear-cache" ]; then
CLEAR_CACHE=true
else
PHPSTAN_PARAMETERS="${PHPSTAN_PARAMETERS} ${arg}"
fi
done

if [ "${CLEAR_CACHE}" == true ] && [ -d "${ROOT_PATH}"/var/ci/phpstan ]; then
echo "Clear cache"
rm -rf "${ROOT_PATH}"/var/ci/phpstan
fi

if [ "${PHP_VERSION}" == "" ]; then
php8.2 "${ROOT_PATH}"/bin/ci/phpstan.php ${PHPSTAN_PARAMETERS}
else
echo "PHP ${PHP_VERSION}"

"php${PHP_VERSION}" \
"${PHPSTAN_BIN_PATH}" \
analyse \
--ansi \
--configuration config/ci/phpstan.php-"${PHP_VERSION}".neon \
${PHPSTAN_PARAMETERS}
fi
36 changes: 36 additions & 0 deletions bin/ci/phpstan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Steevanb\ParallelProcess\{
Console\Application\ParallelProcessesApplication,
Process\Process,
Process\ProcessInterfaceCollection
};
use Steevanb\PhpCollection\ScalarCollection\StringCollection;
use Symfony\Component\Console\Input\ArgvInput;

require $_SERVER['COMPOSER_HOME'] . '/vendor/autoload.php';
require dirname(__DIR__, 2) . '/vendor/autoload.php';

function createPhpstanProcesses(): ProcessInterfaceCollection
{
$phpVersions = new StringCollection(['8.1', '8.2']);

$return = new ProcessInterfaceCollection();
foreach ($phpVersions->toArray() as $loopPhpVersion) {
$return->add(createPhpstanProcess($loopPhpVersion));
}

return $return;
}

function createPhpstanProcess(string $phpVersion): Process
{
return (new Process([__DIR__ . '/phpstan', '--php=' . $phpVersion]))
->setName('phpstan --php=' . $phpVersion);
}

(new ParallelProcessesApplication())
->addProcesses(createPhpstanProcesses())
->run(new ArgvInput($argv));
35 changes: 35 additions & 0 deletions bin/ci/shellcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

filesToCheck=()
files=$(find "${ROOT_PATH}"/bin)
for file in ${files}; do
if [ -f "${file}" ] && [ "${file:(-4)}" != ".php" ]; then
filesToCheck+=("${file}")
fi
done

exitCode=0
for fileToCheck in "${filesToCheck[@]}"; do
set +e
# SC1091 (info): Not following: ./bin/dockerise.inc.bash was not specified as input (see shellcheck -x).
# SC2034 (warning): CI_DOCKER_IMAGE_NAME appears unused. Verify use (or export if used externally).
# SC2086 (info): Double quote to prevent globbing and word splitting.
# SC2155 (warning): Declare and assign separately to avoid masking return values.
# SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.
shellcheck --color=always --exclude SC1091,SC2034,SC2086,SC2155,SC2181 "${fileToCheck}"
if [ ${?} != 0 ]; then
exitCode=1
fi
set -e
done

if [ "${exitCode}" == 0 ]; then
echo -e "\e[42m All files contains valid syntax. \e[0m"
fi
exit ${exitCode}
9 changes: 9 additions & 0 deletions bin/ci/unused-scanner
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

unused-scanner "${ROOT_PATH}"/config/ci/unused-scanner.php
9 changes: 9 additions & 0 deletions bin/ci/validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/../..")"
source "${ROOT_PATH}"/bin/common.inc.sh
source "${ROOT_PATH}"/bin/dockerise.inc.bash

php8.2 "${ROOT_PATH}"/bin/ci/validate.php "${@}"
22 changes: 22 additions & 0 deletions bin/ci/validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Steevanb\ParallelProcess\{
Console\Application\ParallelProcessesApplication,
Process\Process
};
use Symfony\Component\Console\Input\ArgvInput;

require $_SERVER['COMPOSER_HOME'] . '/vendor/autoload.php';
require dirname(__DIR__, 2) . '/vendor/autoload.php';

(new ParallelProcessesApplication())
->addProcess(new Process([__DIR__ . '/composer-require-checker']))
->addProcess(new Process([__DIR__ . '/composer-validate']))
->addProcess(new Process([__DIR__ . '/phpcs']))
->addProcess(new Process([__DIR__ . '/phpdd']))
->addProcess(new Process([__DIR__ . '/phpstan']))
->addProcess(new Process([__DIR__ . '/shellcheck']))
->addProcess(new Process([__DIR__ . '/unused-scanner']))
->run(new ArgvInput($argv));
5 changes: 5 additions & 0 deletions bin/common.inc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eu

readonly CI_DOCKER_IMAGE_NAME="steevanb/symfony-form-options-builder:ci"
10 changes: 10 additions & 0 deletions bin/composer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -eu

readonly ROOT_PATH="$(realpath "$(dirname "$(realpath "$0")")/..")"
source "${ROOT_PATH}"/bin/common.inc.sh
BIN_DIR=bin \
source "${ROOT_PATH}"/bin/dockerise.inc.bash

php8.1 /usr/local/bin/composer "${@}"
47 changes: 47 additions & 0 deletions bin/docker-build.inc.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -eu

function buildDockerImage() {
local dockerImageName="${1}"
local dockerFilePath="${2}"

if [ "${refresh}" == true ]; then
local refreshArguments="--no-cache --pull"
else
local refreshArguments=
fi

DOCKER_BUILDKIT=1 \
docker \
build \
--file "${dockerFilePath}" \
--tag="${dockerImageName}" \
--build-arg DOCKER_UID="$(id -u)" \
--build-arg DOCKER_GID="$(id -g)" \
${refreshArguments} \
"${ROOT_PATH}"
}

function pushDockerImage() {
local dockerImageName="${1}"

echo "Push Docker image ${dockerImageName}."
docker push "${dockerImageName}"
}

refresh=false
push=false
for param in "${@}"; do
if [ "${param}" == "--refresh" ]; then
refresh=true
elif [ "${param}" == "--push" ]; then
push=true
fi
done

buildDockerImage "${DOCKER_IMAGE_NAME}" "${DOCKER_FILE_PATH}"

if [ "${push}" == true ]; then
pushDockerImage "${DOCKER_IMAGE_NAME}"
fi
Loading