Skip to content
Merged
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
232 changes: 232 additions & 0 deletions .github/scripts/ci-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
#!/bin/bash
# Horde CI Bootstrap Script (Unified - works in both GitHub Actions and local mode)
# Generated by: horde-components 1.0.0-alpha39
# Template version: 1.0.0
# Generated: 2026-03-12 12:03:58 UTC
#
# DO NOT EDIT - Regenerate with: horde-components ci init --force
#
# This script auto-detects its environment and adapts accordingly:
# - GitHub Actions: Downloads phar, installs sudo helper, runs in /tmp
# - Local development: Uses local checkout, runs in ~/horde-ci-*

set -e
set -o pipefail

# ============================================================================
# Stage 1: Mode Detection and Configuration
# ============================================================================

if [ -n "$GITHUB_ACTIONS" ]; then
CI_MODE="github"
WORK_DIR="${WORK_DIR:-/tmp/horde-ci}"
COMPONENT_PATH="${GITHUB_WORKSPACE}"
COMPONENT_NAME="Routes"
else
CI_MODE="local"
COMPONENT_NAME="${COMPONENT_NAME:-Routes}"
COMPONENT_PATH="${COMPONENT_PATH:-$(pwd)}"
WORK_DIR="${WORK_DIR:-$HOME/horde-ci-$COMPONENT_NAME}"
LOCAL_COMPONENTS_PATH="${LOCAL_COMPONENTS_PATH:-$HOME/git/horde-components}"
fi

# ============================================================================
# Stage 2: Logging Setup
# ============================================================================

# Colors (enabled for local TTY, disabled for GitHub Actions)
if [ "$CI_MODE" = "local" ] && [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
NC=''
fi

# Logging functions (adapt to GitHub Actions annotations or local output)
log_info() {
if [ "$CI_MODE" = "github" ]; then
echo "::notice::$*"
else
echo -e "${GREEN}[INFO]${NC} $*"
fi
}

log_warn() {
if [ "$CI_MODE" = "github" ]; then
echo "::warning::$*"
else
echo -e "${YELLOW}[WARN]${NC} $*"
fi
}

log_error() {
if [ "$CI_MODE" = "github" ]; then
echo "::error::$*"
else
echo -e "${RED}[ERROR]${NC} $*"
fi >&2
}

# ============================================================================
# Stage 3: Environment Validation
# ============================================================================

log_info "Horde CI Bootstrap ($CI_MODE mode)"
log_info "Component: $COMPONENT_NAME"
log_info "Component path: $COMPONENT_PATH"
log_info "Work directory: $WORK_DIR"

if [ "$CI_MODE" = "github" ]; then
# GitHub Actions environment validation
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
else
# Local mode environment validation
if [ ! -x "$LOCAL_COMPONENTS_PATH/bin/horde-components" ]; then
log_error "horde-components not found at $LOCAL_COMPONENTS_PATH/bin/horde-components"
log_error "Set LOCAL_COMPONENTS_PATH environment variable to your horde-components checkout"
log_error "Example: export LOCAL_COMPONENTS_PATH=~/git/horde-components"
exit 1
fi

if [ ! -d "$COMPONENT_PATH" ]; then
log_error "Component directory not found: $COMPONENT_PATH"
exit 1
fi
fi

# ============================================================================
# Stage 4: PHP Validation
# ============================================================================

if ! command -v php &> /dev/null; then
if [ "$CI_MODE" = "github" ]; then
log_error "PHP not found. ubuntu-24.04 runner should have PHP preinstalled."
else
log_error "PHP not found. Please install PHP 8.2 or higher."
fi
exit 1
fi

PHP_VERSION=$(php -r 'echo PHP_VERSION;')
if [ "$CI_MODE" = "github" ]; then
log_info "Using runner's PHP version: $PHP_VERSION"
else
log_info "Using PHP version: $PHP_VERSION"
fi

# ============================================================================
# Stage 5: Acquire horde-components
# ============================================================================

mkdir -p "$WORK_DIR/setup"

if [ "$CI_MODE" = "github" ]; then
# GitHub mode: Download phar
COMPONENTS_PHAR="$WORK_DIR/setup/horde-components.phar"
COMPONENTS_PHAR_URL="${COMPONENTS_PHAR_URL:-https://github.com/horde/components/releases/latest/download/horde-components.phar}"

if [ -f "$COMPONENTS_PHAR" ]; then
log_info "Using cached horde-components.phar"
else
log_info "Downloading horde-components from $COMPONENTS_PHAR_URL"

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

# Validate 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 ready"
COMPONENTS_BIN="php $COMPONENTS_PHAR"
else
# Local mode: Use local checkout
COMPONENTS_BIN="php $LOCAL_COMPONENTS_PATH/bin/horde-components"
log_info "Using local horde-components: $LOCAL_COMPONENTS_PATH"

# Show version
$COMPONENTS_BIN --version 2>/dev/null || log_warn "Could not determine horde-components version"
fi

# ============================================================================
# Stage 6: Install Helper Scripts
# ============================================================================

if [ "$CI_MODE" = "github" ]; then
# GitHub Actions: Install sudo helper for PHP version switching
log_info "Installing sudo helper script"

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

if [ -f "$SUDO_HELPER" ]; then
sudo install -m 755 "$SUDO_HELPER" /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
fi

# Note: Local mode doesn't need sudo helper (uses system PHP or phpbrew/phpenv directly)

# ============================================================================
# Stage 7: Run CI Setup
# ============================================================================

log_info "Running CI setup..."

$COMPONENTS_BIN ci setup \
--ci-mode="$CI_MODE" \
--work-dir="$WORK_DIR" \
--component="$COMPONENT_PATH"

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

# ============================================================================
# Stage 8: Run CI Tests
# ============================================================================

log_info "Running CI tests..."

$COMPONENTS_BIN ci run \
--work-dir="$WORK_DIR"

EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
log_info "CI tests complete"
else
log_error "CI tests failed with exit code $EXIT_CODE"
exit $EXIT_CODE
fi
90 changes: 43 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
# 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-alpha39
# Template version: 1.0.0
# Generated: 2026-03-12 12:03:58 UTC
#
# DO NOT EDIT - Regenerate with: horde-components ci init
#
# This workflow uses the runner's preinstalled PHP 8.3 for bootstrap.
# horde-components will install additional PHP versions as needed.

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:

# 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-22.04']
php-versions: ['8.2', '8.3', '8.4']
ci:
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@v4

- 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: phpunit, composer:v2, phpstan
- name: Setup Github Token as composer credential
run: composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: |
composer config minimum-stability dev
COMPOSER_ROOT_VERSION=dev-FRAMEWORK_6_0 composer install --no-interaction
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: run phpunit
run: phpunit
- name: run phpstan
run: phpstan analyze src/ lib/ --level 1
- name: Checkout code
uses: actions/checkout@v4

- name: Cache horde-components.phar
uses: actions/cache@v4
with:
path: /tmp/horde-ci/setup
key: components-phar-${{ hashFiles('.github/scripts/ci-bootstrap.sh') }}

- 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') }}

- name: Run CI
run: bash .github/scripts/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: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: ci-results-${{ github.run_number }}
path: |
/tmp/horde-ci/lanes/*/Routes/build/*.json
retention-days: 30
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ run-tests.log
/phpstan.neon
# PHPStan cache directory
/.phpstan.cache/
/.phpunit.cache/
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"horde/exception": "^3 || dev-FRAMEWORK_6_0",
"horde/util": "^3 || dev-FRAMEWORK_6_0",
"horde/support": "^3 || dev-FRAMEWORK_6_0",
"horde/http": "^3 || dev-FRAMEWORK_6_0",
"psr/http-message": "^2"
},
"require-dev": {
Expand Down Expand Up @@ -55,5 +56,7 @@
"branch-alias": {
"dev-FRAMEWORK_6_0": "3.x-dev"
}
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Loading
Loading