fixing github actions steps and configuration #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: COmanage Registry setup + PHPUnit (multi-PHP, multi-DB) | |
| on: | |
| workflow_dispatch: | |
| push: | |
| pull_request: | |
| jobs: | |
| setup-and-test: | |
| runs-on: | |
| - codebuild-comanage-pipeline-${{ github.run_id }}-${{ github.run_attempt }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php: ["8.3"] | |
| db: | |
| - engine: postgres | |
| image: postgres:16-alpine | |
| port: 5432 | |
| health_cmd: 'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"' | |
| - engine: mysql | |
| image: mysql:8.0 | |
| port: 3306 | |
| health_cmd: 'mysqladmin ping -h 127.0.0.1 -uroot -p"$MYSQL_ROOT_PASSWORD" --silent' | |
| - engine: mariadb | |
| image: mariadb:11 | |
| port: 3306 | |
| health_cmd: 'mariadb-admin ping -h 127.0.0.1 -uroot -p"$MARIADB_ROOT_PASSWORD" --silent' | |
| # Exactly ONE service container per matrix run (the image changes) | |
| services: | |
| db: | |
| image: ${{ matrix.db.image }} | |
| env: | |
| # Postgres vars (used only by postgres image) | |
| POSTGRES_DB: registry_test | |
| POSTGRES_USER: test_user | |
| POSTGRES_PASSWORD: test_password | |
| # MySQL vars (used only by mysql image; mariadb image ignores these) | |
| MYSQL_DATABASE: registry_test | |
| MYSQL_USER: test_user | |
| MYSQL_PASSWORD: test_password | |
| MYSQL_ROOT_PASSWORD: root_password | |
| # MariaDB vars (used only by mariadb image) | |
| MARIADB_DATABASE: registry_test | |
| MARIADB_USER: test_user | |
| MARIADB_PASSWORD: test_password | |
| MARIADB_ROOT_PASSWORD: root_password | |
| options: >- | |
| --health-cmd "${{ matrix.db.health_cmd }}" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 20 | |
| env: | |
| COMANAGE_REGISTRY_DIR: /srv/comanage-registry | |
| # Matrix DB selection for this run | |
| DB_ENGINE: ${{ matrix.db.engine }} | |
| # DB service connection info (because you publish ports) | |
| # COMANAGE_REGISTRY_DATABASE_HOST: db | |
| # COMANAGE_REGISTRY_DATABASE_PORT: ${{ matrix.db.port }} | |
| # Values used by your PHPUnit setup test | |
| COMANAGE_REGISTRY_ADMIN_GIVEN_NAME: Admin | |
| COMANAGE_REGISTRY_ADMIN_FAMILY_NAME: User | |
| COMANAGE_REGISTRY_ADMIN_USERNAME: admin | |
| COMANAGE_REGISTRY_SECURITY_SALT: phpunit-security-salt | |
| # Values used by tests/bootstrap.php to create containers (host/port are set dynamically after start) | |
| COMANAGE_REGISTRY_DATABASE: registry_test | |
| COMANAGE_REGISTRY_DATABASE_USER: test_user | |
| COMANAGE_REGISTRY_DATABASE_USER_PASSWORD: test_password | |
| COMANAGE_REGISTRY_DATABASE_PERSISTENT: "false" | |
| steps: | |
| - name: Show OS info | |
| shell: bash | |
| run: | | |
| cat /etc/os-release | |
| uname -a | |
| - name: Upgrade OS version | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| sudo apt-get update | |
| sudo apt-get upgrade -y | |
| - name: Checkout (only for workflow files) | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| git clone \ | |
| --depth=1 \ | |
| --branch "${GITHUB_REF_NAME}" \ | |
| "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \ | |
| "${COMANAGE_REGISTRY_DIR}" | |
| - name: Install PHP ${{ matrix.php }} and extensions | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| sudo apt-get install -y --no-install-recommends \ | |
| software-properties-common ca-certificates gnupg | |
| sudo add-apt-repository -y ppa:ondrej/php | |
| sudo apt-get update | |
| PHP_VER="${{ matrix.php }}" | |
| sudo apt-get install -y --no-install-recommends \ | |
| php${PHP_VER}-cli \ | |
| php${PHP_VER}-mbstring \ | |
| php${PHP_VER}-intl \ | |
| php${PHP_VER}-ldap \ | |
| php${PHP_VER}-xml \ | |
| php${PHP_VER}-zip \ | |
| php${PHP_VER}-pdo \ | |
| php${PHP_VER}-mysql \ | |
| php${PHP_VER}-pgsql \ | |
| php${PHP_VER}-gd \ | |
| php${PHP_VER}-xsl \ | |
| php${PHP_VER}-memcached \ | |
| php${PHP_VER}-curl | |
| # Force the correct version via update-alternatives | |
| sudo update-alternatives --set php /usr/bin/php${PHP_VER} | |
| # Also override via /usr/local/bin which is earlier in PATH | |
| sudo ln -sf /usr/bin/php${PHP_VER} /usr/local/bin/php | |
| # Persist for subsequent steps | |
| echo "PHP_VER=${PHP_VER}" >> "$GITHUB_ENV" | |
| # Prepend /usr/local/bin to PATH for all subsequent steps | |
| echo "/usr/local/bin" >> "$GITHUB_PATH" | |
| - name: Install OS packages needed for setup | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| sudo apt-get update | |
| sudo apt-get install -y --no-install-recommends \ | |
| wget curl tar ca-certificates \ | |
| git unzip \ | |
| libicu-dev \ | |
| libldap2-dev \ | |
| libxml2 \ | |
| zlib1g \ | |
| libsodium23 \ | |
| libpng-dev \ | |
| libjpeg-dev \ | |
| libfreetype6-dev \ | |
| libxslt1.1 \ | |
| libmemcached11 \ | |
| tree | |
| - name: Show versions | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| php -v | |
| composer --version | |
| docker --version | |
| docker version | |
| echo "DOCKER_API_VERSION=${DOCKER_API_VERSION-}" | |
| echo "${DOCKER_HOST-}" | |
| docker context show | |
| - name: Wait for DB to be ready | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| case "${DB_ENGINE}" in | |
| postgres) | |
| docker exec "${{ job.services.db.id }}" sh -lc 'for i in $(seq 1 60); do pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" && exit 0; sleep 1; done; exit 1' | |
| ;; | |
| mysql) | |
| docker exec "${{ job.services.db.id }}" sh -lc 'for i in $(seq 1 60); do mysqladmin ping -h 127.0.0.1 -uroot -p"$MYSQL_ROOT_PASSWORD" --silent && exit 0; sleep 1; done; exit 1' | |
| ;; | |
| mariadb) | |
| docker exec "${{ job.services.db.id }}" sh -lc 'for i in $(seq 1 60); do mariadb-admin ping -h 127.0.0.1 -uroot -p"$MARIADB_ROOT_PASSWORD" --silent && exit 0; sleep 1; done; exit 1' | |
| ;; | |
| *) | |
| echo "Unknown DB_ENGINE=${DB_ENGINE}" | |
| exit 1 | |
| ;; | |
| esac | |
| - name: Export DB host/port (service container IP) | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| DB_HOST="$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' '${{ job.services.db.id }}')" | |
| echo "Resolved DB_HOST=${DB_HOST}" | |
| case "${DB_ENGINE}" in | |
| postgres) DB_PORT=5432 ;; | |
| mysql|mariadb) DB_PORT=3306 ;; | |
| *) echo "Unknown DB_ENGINE=${DB_ENGINE}"; exit 1 ;; | |
| esac | |
| echo "COMANAGE_REGISTRY_DATABASE_HOST=${DB_HOST}" >> "$GITHUB_ENV" | |
| echo "COMANAGE_REGISTRY_DATABASE_PORT=${DB_PORT}" >> "$GITHUB_ENV"` | |
| - name: Smoke test DB TCP port | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| php -r ' | |
| $h=getenv("COMANAGE_REGISTRY_DATABASE_HOST"); $p=(int)getenv("COMANAGE_REGISTRY_DATABASE_PORT"); | |
| $fp=@fsockopen($h,$p,$errno,$errstr,5); | |
| if(!$fp){fwrite(STDERR,"TCP connect failed: $errno $errstr\n"); exit(1);} | |
| fclose($fp); | |
| echo "TCP connect OK to $h:$p\n"; | |
| ' | |
| - name: Create local/config/database.php placeholder | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| cd "${COMANAGE_REGISTRY_DIR}"/local/config | |
| sudo touch database.php | |
| sudo chown www-data:www-data database.php | |
| sudo tee "database.php" > /dev/null <<'EOF' | |
| <?php | |
| // Placeholder: actual connection is configured dynamically by tests/bootstrap.php via Testcontainers | |
| return []; | |
| EOF | |
| - name: Show working directory | |
| shell: bash | |
| run: | | |
| tree -L 3 "${COMANAGE_REGISTRY_DIR}" | |
| - name: Debug DB connectivity | |
| shell: bash | |
| run: | | |
| set -euxo pipefail | |
| echo "Host=$COMANAGE_REGISTRY_DATABASE_HOST Port=$COMANAGE_REGISTRY_DATABASE_PORT Engine=$DB_ENGINE" | |
| getent hosts "$COMANAGE_REGISTRY_DATABASE_HOST" || true | |
| - name: Run PHPUnit (DB_ENGINE=${{ matrix.db_engine }}) | |
| shell: bash | |
| working-directory: /srv/comanage-registry/app | |
| run: | | |
| set -euxo pipefail | |
| cd "${COMANAGE_REGISTRY_DIR}"/app | |
| DB_ENGINE="${DB_ENGINE}" vendor/bin/phpunit --testsuite app |