Skip to content
102 changes: 53 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run.
# Generated by: horde-components 1.0.0-alpha30
# Template version: 1.0.0
# Generated: 2026-03-03 18:48:30 UTC
#
# DO NOT EDIT - Regenerate with: horde-components ci init

on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches:
- master
- maintaina-composerfixed
- FRAMEWORK_6_0
branches: [ FRAMEWORK_6_0 ]
pull_request:
branches:
- master
- maintaina-composerfixed
- FRAMEWORK_6_0


# Allows you to run this workflow manually from the Actions tab
branches: [ FRAMEWORK_6_0 ]
workflow_dispatch:
inputs:
php_versions:
description: 'PHP versions to test (comma-separated, e.g., 8.2,8.4)'
required: false
default: 'all'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-20.04']
php-versions: ['7.4', '8.0', 'latest']
phpunit-versions: ['latest', '9.5']
test:
runs-on: ubuntu-24.04

steps:
- name: Setup github ssh key
run: mkdir -p ~/.ssh/ && ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: bcmath, ctype, curl, dom, gd, gettext, iconv, imagick, json, ldap, mbstring, mysql, opcache, openssl, pcntl, pdo, posix, redis, soap, sockets, sqlite, tokenizer, xmlwriter
ini-values: post_max_size=512M, max_execution_time=360
coverage: xdebug
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}, composer:v2
- name: Setup Github Token as composer credential
run: composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
- name: Install horde/test dependency and other dependencies
run: |
COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer config minimum-stability dev
COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer install
COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer require --dev horde/test dev-FRAMEWORK_6_0
- name: Redo install due to many fails
run: |
COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer install
COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer require --dev horde/test dev-FRAMEWORK_6_0
- name: run phpunit
run: phpunit --bootstrap test/bootstrap.php
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP 8.4 (for bootstrap)
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: json, mbstring, curl
coverage: none

- name: Cache QC tools (PHPUnit, PHPStan, PHP-CS-Fixer)
uses: actions/cache@v4
with:
path: /tmp/horde-ci/tools
key: ci-tools-${{ hashFiles('.horde.yml') }}
restore-keys: |
ci-tools-

- name: CI Setup
run: bash bin/ci-bootstrap.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPONENTS_PHAR_URL: ${{ vars.COMPONENTS_PHAR_URL || 'https://github.com/horde/components/releases/latest/download/horde-components.phar' }}

- name: CI Run
run: |
php /tmp/horde-ci/bin/horde-components.phar ci run \
--work-dir=/tmp/horde-ci

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: ci-results-${{ github.run_number }}
path: |
/tmp/horde-ci/lanes/*/build/*.json
retention-days: 30
137 changes: 137 additions & 0 deletions bin/ci-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash
# Horde CI Bootstrap Script (GitHub Actions)
# Generated by: horde-components 1.0.0-alpha30
# Template version: 1.0.0
# Generated: 2026-03-03 18:48:30 UTC
#
# DO NOT EDIT - Regenerate with: horde-components ci init

set -e
set -o pipefail

# Configuration
BOOTSTRAP_PHP_VERSION="8.4"
COMPONENTS_PHAR_URL="${COMPONENTS_PHAR_URL:-https://github.com/horde/components/releases/latest/download/horde-components.phar}"
COMPONENT_NAME="Http"
WORK_DIR="/tmp/horde-ci"

# Colors for output (disabled in CI)
RED=''
GREEN=''
YELLOW=''
NC=''

# Logging functions
log_info() {
if [ -n "$GITHUB_ACTIONS" ]; then
echo "::notice::$*"
else
echo "[INFO] $*"
fi
}

log_warn() {
if [ -n "$GITHUB_ACTIONS" ]; then
echo "::warning::$*"
else
echo "[WARN] $*"
fi
}

log_error() {
if [ -n "$GITHUB_ACTIONS" ]; then
echo "::error::$*"
else
echo "[ERROR] $*"
fi >&2
}

# Stage 1: Validate environment
log_info "Horde CI Bootstrap - Stage 1 (GitHub Actions mode)"
log_info "Component: $COMPONENT_NAME"
log_info "Bootstrap PHP: $BOOTSTRAP_PHP_VERSION"

# Check we're in GitHub Actions
if [ -z "$GITHUB_ACTIONS" ]; then
log_error "This script is for GitHub Actions. Use bootstrap-local.sh for local development."
exit 1
fi

# Validate required environment variables
if [ -z "$GITHUB_REPOSITORY" ]; then
log_error "GITHUB_REPOSITORY not set"
exit 1
fi

if [ -z "$GITHUB_REF" ]; then
log_error "GITHUB_REF not set"
exit 1
fi

if [ -z "$GITHUB_TOKEN" ]; then
log_error "GITHUB_TOKEN not set"
exit 1
fi

# Stage 2: Verify PHP
if ! command -v php &> /dev/null; then
log_error "PHP not found. Ensure setup-php action runs before this script."
exit 1
fi

PHP_VERSION=$(php -r 'echo PHP_VERSION;')
log_info "PHP version: $PHP_VERSION"

if [ "${PHP_VERSION:0:3}" != "$BOOTSTRAP_PHP_VERSION" ]; then
log_warn "Expected PHP $BOOTSTRAP_PHP_VERSION, got $PHP_VERSION (proceeding anyway)"
fi

# Stage 3: Download horde-components.phar
log_info "Downloading horde-components from $COMPONENTS_PHAR_URL"

mkdir -p "$WORK_DIR/bin"
COMPONENTS_PHAR="$WORK_DIR/bin/horde-components.phar"

if ! curl -sS -L -o "$COMPONENTS_PHAR" "$COMPONENTS_PHAR_URL"; then
log_error "Failed to download horde-components.phar"
exit 1
fi

# Validate it's a valid phar
if ! php "$COMPONENTS_PHAR" help &> /dev/null; then
log_error "Downloaded phar is not valid or not executable"
exit 1
fi

log_info "horde-components.phar downloaded successfully"

# Stage 4: Install sudo helper script
log_info "Installing sudo helper script"

# Extract and install the helper script from PHAR
php "$COMPONENTS_PHAR" -r "copy('phar://' . '$COMPONENTS_PHAR' . '/data/ci/sudo-helper.sh', '$WORK_DIR/sudo-helper.sh');" 2>/dev/null || \
log_warn "Could not extract sudo helper from PHAR (older version?)"

if [ -f "$WORK_DIR/sudo-helper.sh" ]; then
sudo install -m 755 "$WORK_DIR/sudo-helper.sh" /usr/local/bin/horde-ci-sudo-helper
log_info "Sudo helper installed successfully"
else
log_warn "Sudo helper not found, will try to proceed without it"
fi

# Stage 5: Handoff to PHP (horde-components ci setup)
log_info "Bootstrap complete. Handing off to horde-components ci setup"

php "$COMPONENTS_PHAR" ci setup \
--ci-mode=github \
--work-dir="$WORK_DIR" \
--component="$COMPONENT_NAME"

EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
log_info "CI setup complete. Workspace: $WORK_DIR"
else
log_error "CI setup failed with exit code $EXIT_CODE"
exit $EXIT_CODE
fi