Verified Commit c588f566 authored by Jibran Ijaz's avatar Jibran Ijaz
Browse files

Issue #2283919 by jibran: Added GitLab CI YML.

parent 4c0b2a0f
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -51,14 +51,14 @@ jobs:
        SIMPLETEST_DB: mysql://drupal:drupal@127.0.0.1/local
        BROWSERTEST_OUTPUT_FILE: /data/app/sites/simpletest/browser_output.html
        BROWSERTEST_OUTPUT_DIRECTORY: /data/app/sites/simpletest/browser_output
        MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", null, "http:\/\/127.0.0.1:4444\/wd\/hub"]'
        MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"chromeOptions": { "args": [ "--disable-gpu", "--headless" ] } }, "http://127.0.0.1:4444/wd/hub" ]'
    - image: mariadb
      environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: local
        MYSQL_USER: drupal
        MYSQL_PASSWORD: drupal
    - image: selenium/standalone-chrome:latest
    - image: selenium/standalone-chrome:3.141.59-oxygen
    working_directory: /data/app
    steps:
    - setup_remote_docker:
@@ -86,6 +86,10 @@ jobs:
        steps:
          - run: composer require 'drupal/hal-hal:^1.0'

    - run:
        name: Show all installed composer packages.
        command: composer show

    - checkout:
        path: modules/${MODULE_NAME}

@@ -136,7 +140,7 @@ jobs:
    - run:
        name: Run unit tests
        command: |
          ./vendor/bin/phpunit --configuration ./core/phpunit.xml.dist --log-junit ../build/logs/phpunit/phpunit.xml --exclude-group functional_javascript modules/${MODULE_NAME}
          ./vendor/bin/phpunit --configuration ./core/phpunit.xml.dist --log-junit ../build/logs/phpunit/phpunit.xml modules/${MODULE_NAME}
#          ./vendor/bin/phpunit --verbose  --configuration ./core/phpunit.xml.dist --log-junit ../build/logs/phpunit/phpunit.xml modules/${MODULE_NAME}
#          ./vendor/bin/phpunit --debug --verbose  --configuration ./core/phpunit.xml.dist --log-junit ../build/logs/phpunit/phpunit.xml modules/${MODULE_NAME}

+164 −0
Original line number Diff line number Diff line
default:
  image: skpr/php-cli:${PHP_VERSION}-v2-latest
  services:
    - name: mysql:${MYSQL_VERSION}
      alias: mysql

stages:
  - pre
  - build
  - lint
  - test

variables:
  # Configure mysql environment variables (https://hub.docker.com/_/mysql/)
  MYSQL_ROOT_PASSWORD: drupal
  MYSQL_DATABASE: drupal
  MYSQL_USER: drupal
  MYSQL_PASSWORD: drupal
  SIMPLETEST_DB: mysql://drupal:drupal@mysql/drupal
  SIMPLETEST_BASE_URL: http://localhost:8080
  BROWSERTEST_OUTPUT_DIRECTORY: app/sites/default/files
  BROWSERTEST_OUTPUT_FILE: test-output.html
  MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"chromeOptions": { "args": [ "--disable-gpu", "--headless" ] } }, "http://chrome:4444/wd/hub" ]'

build app:
  stage: build
  cache:
    key: ${CI_COMMIT_REF_SLUG}-composer
    paths:
      - app/vendor/
  script:
    - cp -r ${CI_PROJECT_DIR} /tmp/${CI_PROJECT_NAME}
    - git clone --depth 1 --branch ${DRUPAL_CORE_CONSTRAINT}.x https://git.drupal.org/project/drupal.git app
    - mv /tmp/${CI_PROJECT_NAME} app/modules/
    - cd app
    - git log -1 --oneline
    - composer install --prefer-dist --no-progress
    - composer require --dev "phpstan/phpstan-deprecation-rules:^1.0"
    - composer show
    - cp modules/${CI_PROJECT_NAME}/.drupalci/* .
    - mkdir -p ${BROWSERTEST_OUTPUT_DIRECTORY}
  artifacts:
    expire_in: 1 hour
    paths:
      - app/composer.lock
      - app/

phpcs:
  stage: lint
  needs: ["build app"]
  script:
    - cd app
    - touch phpcs-report.xml
    - vendor/bin/phpcs
      --standard=vendor/drupal/coder/coder_sniffer/Drupal
      --extensions=php,module,inc,install,test,profile,theme,css,info
      --ignore=*.md
      --report=junit
      --report-file=phpcs-report.xml
      modules/${CI_PROJECT_NAME}
  dependencies:
    - build app
  artifacts:
    when: always
    reports:
      junit: app/phpcs-report.xml

phpstan:
  stage: lint
  needs: ["build app"]
  script:
    - cd app
    - cp modules/${CI_PROJECT_NAME}/phpstan.neon .
    - touch phpstan-report.xml
    - vendor/bin/phpstan analyze
      --memory-limit=-1
      --no-progress
      --error-format=junit
      modules/${CI_PROJECT_NAME}
      > phpstan-report.xml
    - cat phpstan-report.xml
  dependencies:
    - build app
  artifacts:
    when: always
    reports:
      junit: app/phpstan-report.xml

#test unit:
#  needs: ["build app"]
#  stage: test
#  before_script:
#    - cd app
#    - touch phpunit-report-unit.xml
#  script:
#    - vendor/bin/phpunit --configuration ./core/phpunit.xml.dist --log-junit phpunit-report-unit.xml modules/${CI_PROJECT_NAME}/tests/src/Unit/
#  dependencies:
#    - build app
#  artifacts:
#    when: always
#    reports:
#      junit: app/phpunit-report-unit.xml

test kernel:
  needs: ["build app"]
  stage: test
  before_script:
    - cd app
    - touch phpunit-report-kernel.xml
    - ./wait-for-it.sh -s -t 180 mysql:3306 -- echo "MySQL is Ready"
  script:
    - vendor/bin/phpunit --configuration ./core/phpunit.xml.dist --log-junit phpunit-report-kernel.xml modules/${CI_PROJECT_NAME}/tests/src/Kernel/
  dependencies:
    - build app
  artifacts:
    when: always
    reports:
      junit: app/phpunit-report-kernel.xml

test functional:
  needs: ["build app"]
  stage: test
  before_script:
    - cd app
    - touch phpunit-report-functional.xml
    - php -S 0.0.0.0:8080 .ht.router.php >> http.log 2>&1 &
    - ./wait-for-it.sh -s -t 180 mysql:3306 -- echo "MySQL is Ready"
  script:
    - vendor/bin/phpunit --configuration ./core/phpunit.xml.dist --log-junit phpunit-report-functional.xml modules/${CI_PROJECT_NAME}/tests/src/Functional/
  dependencies:
    - build app
  artifacts:
    when: always
    reports:
      junit: app/phpunit-report-functional.xml
    paths:
      - app/http.log
      - app/sites/simpletest/browser_output/

test functional javascript:
  needs: ["build app"]
  stage: test
  image: skpr/php-cli:${PHP_VERSION}-v2-latest
  services:
    - name: mysql:${MYSQL_VERSION}
      alias: mysql
    - name: selenium/standalone-chrome:latest
      alias: chrome
  before_script:
    - cd app
    - touch phpunit-report-functional-javascript.xml
    - php -S 0.0.0.0:8080 .ht.router.php >> http.log 2>&1 &
    - ./wait-for-it.sh -s -t 180 mysql:3306 -- echo "MySQL is Ready"
  script:
    - vendor/bin/phpunit --configuration ./core/phpunit.xml.dist --log-junit phpunit-report-functional-javascript.xml modules/${CI_PROJECT_NAME}/tests/src/FunctionalJavascript/
  dependencies:
    - build app
  artifacts:
    when: always
    reports:
      junit: app/phpunit-report-functional-javascript.xml
    paths:
      - app/http.log
      - app/sites/simpletest/browser_output/
+182 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available

WAITFORIT_cmdname=${0##*/}

echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
    cat << USAGE >&2
Usage:
    $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
    -h HOST | --host=HOST       Host or IP under test
    -p PORT | --port=PORT       TCP port under test
                                Alternatively, you specify the host and port as host:port
    -s | --strict               Only execute subcommand if the test succeeds
    -q | --quiet                Don't output any status messages
    -t TIMEOUT | --timeout=TIMEOUT
                                Timeout in seconds, zero for no timeout
    -- COMMAND ARGS             Execute command with args after the test finishes
USAGE
    exit 1
}

wait_for()
{
    if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
        echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
    else
        echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
    fi
    WAITFORIT_start_ts=$(date +%s)
    while :
    do
        if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
            nc -z $WAITFORIT_HOST $WAITFORIT_PORT
            WAITFORIT_result=$?
        else
            (echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
            WAITFORIT_result=$?
        fi
        if [[ $WAITFORIT_result -eq 0 ]]; then
            WAITFORIT_end_ts=$(date +%s)
            echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
            break
        fi
        sleep 1
    done
    return $WAITFORIT_result
}

wait_for_wrapper()
{
    # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
    if [[ $WAITFORIT_QUIET -eq 1 ]]; then
        timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
    else
        timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
    fi
    WAITFORIT_PID=$!
    trap "kill -INT -$WAITFORIT_PID" INT
    wait $WAITFORIT_PID
    WAITFORIT_RESULT=$?
    if [[ $WAITFORIT_RESULT -ne 0 ]]; then
        echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
    fi
    return $WAITFORIT_RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
    case "$1" in
        *:* )
        WAITFORIT_hostport=(${1//:/ })
        WAITFORIT_HOST=${WAITFORIT_hostport[0]}
        WAITFORIT_PORT=${WAITFORIT_hostport[1]}
        shift 1
        ;;
        --child)
        WAITFORIT_CHILD=1
        shift 1
        ;;
        -q | --quiet)
        WAITFORIT_QUIET=1
        shift 1
        ;;
        -s | --strict)
        WAITFORIT_STRICT=1
        shift 1
        ;;
        -h)
        WAITFORIT_HOST="$2"
        if [[ $WAITFORIT_HOST == "" ]]; then break; fi
        shift 2
        ;;
        --host=*)
        WAITFORIT_HOST="${1#*=}"
        shift 1
        ;;
        -p)
        WAITFORIT_PORT="$2"
        if [[ $WAITFORIT_PORT == "" ]]; then break; fi
        shift 2
        ;;
        --port=*)
        WAITFORIT_PORT="${1#*=}"
        shift 1
        ;;
        -t)
        WAITFORIT_TIMEOUT="$2"
        if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
        shift 2
        ;;
        --timeout=*)
        WAITFORIT_TIMEOUT="${1#*=}"
        shift 1
        ;;
        --)
        shift
        WAITFORIT_CLI=("$@")
        break
        ;;
        --help)
        usage
        ;;
        *)
        echoerr "Unknown argument: $1"
        usage
        ;;
    esac
done

if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
    echoerr "Error: you need to provide a host and port to test."
    usage
fi

WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}

# Check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)

WAITFORIT_BUSYTIMEFLAG=""
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
    WAITFORIT_ISBUSY=1
    # Check if busybox timeout uses -t flag
    # (recent Alpine versions don't support -t anymore)
    if timeout &>/dev/stdout | grep -q -e '-t '; then
        WAITFORIT_BUSYTIMEFLAG="-t"
    fi
else
    WAITFORIT_ISBUSY=0
fi

if [[ $WAITFORIT_CHILD -gt 0 ]]; then
    wait_for
    WAITFORIT_RESULT=$?
    exit $WAITFORIT_RESULT
else
    if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
        wait_for_wrapper
        WAITFORIT_RESULT=$?
    else
        wait_for
        WAITFORIT_RESULT=$?
    fi
fi

if [[ $WAITFORIT_CLI != "" ]]; then
    if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
        echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
        exit $WAITFORIT_RESULT
    fi
    exec "${WAITFORIT_CLI[@]}"
else
    exit $WAITFORIT_RESULT
fi

.gitlab-ci.yml

0 → 100644
+17 −0
Original line number Diff line number Diff line
include:
  # https://docs.gitlab.com/ee/ci/yaml/index.html#includetemplate
  - template: 'Workflows/Branch-Pipelines.gitlab-ci.yml'

deploystacks:
  trigger:
    include: .drupalci/.gitlab-single-pipeline.yml
    strategy: depend
  parallel:
    matrix:
      - DRUPAL_CORE_CONSTRAINT: ["9.4", "9.5"]
        PHP_VERSION: ["8.0", "8.1"]
        MYSQL_VERSION: ["8"]
      # Drupal 10 requires PHP 8.1
      - DRUPAL_CORE_CONSTRAINT: ["10.0", "10.1"]
        PHP_VERSION: ["8.1"]
        MYSQL_VERSION: ["8"]
+1 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="dynamic_entity_reference">
  <description>Default PHP CodeSniffer configuration for Dynamic Entity Reference.</description>
  <config name="installed_paths" value="../../drupal/coder/coder_sniffer/Drupal,../../drupal/coder/coder_sniffer/DrupalPractice,../../slevomat/coding-standard" />
  <file>.</file>
  <arg name="extensions" value="inc,install,module,php,profile,test,theme,yml"/>

Loading