Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
GitLab CI (version >= 9) configuration for testing and TER uploading TYPO3 extensions
cache:
key: "$CI_COMMIT_REF_NAME/$CI_JOB_STAGE"
paths:
- .composer/
before_script:
# Install git on machine
- apk add git --update
stages:
- test
- mirror
- upload
.test: &testing
stage: test
image: php:$DOCKER_TAG
only:
- branches
before_script:
# Where to locate the DocRoot (needed for Unit Tests)
- export TYPO3_PATH_WEB="$PWD/.Build/Web"
- export COMPOSER_CACHE_DIR=.composer
# Install composer
- curl -OLs https://composer.github.io/installer.sig
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- php composer-setup.php --no-ansi --install-dir=/usr/bin --filename=composer
- php -r "unlink('composer-setup.php'); unlink('installer.sig');"
# Get the given TYPO3 core
- composer require typo3/cms="${TYPO3_VERSION}" --update-with-dependencies
# Get the TYPO3 testing framework (thx to Nicole and Helmut for that)
- composer require nimut/testing-framework
# Get the latest PHP_CodeSniffer
- composer require squizlabs/php_codesniffer
script:
# Run Unit Tests
- .Build/bin/phpunit -c Configuration/.Build/Tests/UnitTests.xml
# Run PHP_CodeSniffer (warning_severity is needed due usage of hooks which are not psr2 compliant)
- .Build/bin/phpcs --standard=PSR2 --config-set warning_severity 8 Classes Configuration/TCA Tests/Unit
# Tests in PHP 5.6 and TYPO3 6.2
test:php56:typo3_62:
<<: *testing
variables:
DOCKER_TAG: 5.6-alpine
TYPO3_VERSION: ^6.2
# Build in PHP 5.6 and TYPO3 7.6
test:php56:typo3_7:
<<: *testing
variables:
DOCKER_TAG: 5.6-alpine
TYPO3_VERSION: ^7.6
# Build in PHP 7.0 and TYPO3 7.6
test:php70:typo3_7:
<<: *testing
variables:
DOCKER_TAG: 7.0-alpine
TYPO3_VERSION: ^7.6
# Build in PHP 7.1 and TYPO3 7.6
test:php71:typo3_7:
<<: *testing
variables:
DOCKER_TAG: 7.1-alpine
TYPO3_VERSION: ^7.6
# Build in PHP 7.0 and TYPO3 8 (latest stable release)
test:php70:typo3_8:
<<: *testing
variables:
DOCKER_TAG: 7.0-alpine
TYPO3_VERSION: ^8
# Build in PHP 7.1 and TYPO3 8 (latest stable release)
test:php71:typo3_8:
<<: *testing
variables:
DOCKER_TAG: 7.1-alpine
TYPO3_VERSION: ^8
# Build in PHP 7.0 and TYPO3 (current master)
test:php70:typo3_master:
<<: *testing
variables:
DOCKER_TAG: 7.0-alpine
TYPO3_VERSION: dev-master
# Build in PHP 7.1 and TYPO3 (current master)
test:php71:typo3_master:
<<: *testing
variables:
DOCKER_TAG: 7.1-alpine
TYPO3_VERSION: dev-master
mirror-to-github:
stage: mirror
image: indiehosters/git
only:
- master
script:
- git remote add github https://$GITHUB_USERNAME:$GITHUB_TOKEN@github.com/$GITHUB_USERNAME/$GITHUB_REMOTE_REPO_NAME.git
- git push github master
- git push github master --tags
# TER Upload when tagging in master branch
# The variables T3O_USERNAME and T3O_PASSWORD should be set in GitLab
ter-upload:
image: php:7-alpine
stage: upload
only:
- tags
before_script:
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- export COMPOSER_CACHE_DIR=.composer
script:
- composer install
# Get the package for uploading to TER (thx to Claus)
- composer require namelesscoder/typo3-repository-client
- export TYPO3_PATH_WEB="$PWD/.Build/Web"
# Upload to TER if a Git tag was set (and username/password is set in the global variables)
- >
if [ -n "$CI_COMMIT_TAG" ] && [ -n "$T3O_USERNAME" ] && [ -n "$T3O_PASSWORD" ]; then
echo -e "Preparing upload of release ${CI_COMMIT_TAG} to TER\n"
# Cleanup before we upload
git reset --hard HEAD && git clean -fx
# Upload
TAG_MESSAGE=`git tag -n10 -l $CI_COMMIT_TAG | sed 's/^[0-9.]*[ ]*//g'`
echo "Uploading release ${CI_COMMIT_TAG} to TER"
.Build/bin/upload . "$T3O_USERNAME" "$T3O_PASSWORD" "$TAG_MESSAGE"
fi;
{
"name": "vendorname/extensionname",
"type": "typo3-cms-extension",
"description": "Description of my extension",
"homepage": "https://typo3.org",
"license": [
"GPL-2.0+"
],
"keywords": [
"TYPO3",
"extension"
],
"authors": [
{
"name": "Thomas Löffler",
"email": "loeffler@spooner-web.de",
"homepage": "https://spooner-web.de",
"role": "Developer"
}
],
"require": {
"typo3/cms": "^6.2 || ^7 || ^8"
},
"autoload": {
"psr-4": {
"VendorName\\ExtensionName\\": "Classes/"
}
},
"config": {
"vendor-dir": ".Build/vendor/",
"bin-dir": ".Build/bin/"
},
"extra": {
"typo3/cms": {
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": ".Build/Web"
}
}
}
concurrent = 5
[[runners]]
name = "GitLab Runner"
url = "https://my.gitlab.com/ci"
token = "xxx"
envorionment = ["COMPOSER_CACHE_DIR=/cache"]
executor = "docker"
[runners.docker]
tls_verify = false
image = "webdevops/php"
privileged = false
disable_cache = false
volumes = ["/var/cache:/cache:rw"]
cache_dir = "/cache"
[runners.cache]
Insecure = false
<phpunit
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="../../../.Build/vendor/nimut/testing-framework/src/TestingFramework/Bootstrap/UnitTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
>
<testsuites>
<testsuite name="Base tests">
<directory>../../../Tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>

t3easy commented Jan 31, 2017

One Idea:
Use a cache key for all tests to share the composer cache across all dependent jobs
e.g.:

cache:
  key: "$CI_BUILD_STAGE"
  paths:
  - .composer/

Use variables instead of script/export because they are merged from global to job e.g.:

variables:
  COMPOSER_CACHE_DIR: ".composer"
  COMPOSER_ALLOW_SUPERUSER: "1"
  TYPO3_VERSION: ^7.6
  TYPO3_PATH_WEB: "$CI_PROJECT_DIR/.Build/Web"

test:php7.1:typo3_85:
  variables:
    TYPO3_VERSION: ^8.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment