Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$config = (new PhpCsFixer\Config())
->setRules([
'@PER-CS' => true,
'@PHP8x3Migration' => true,
'@PHP8x2Migration' => true,
'php_unit_test_class_requires_covers' => true,
'nullable_type_declaration_for_default_null_value' => true,
'Horde/remove_php_version_comment' => true,
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
"horde/phpconfigfile": "^0.0.1-alpha4 || dev-FRAMEWORK_6_0"
},
"require-dev": {
"horde/test": "^3 || dev-FRAMEWORK_6_0",
"phpunit/phpunit": "^12 || ^11 || ^10 || ^9"
"horde/test": "^3 || dev-FRAMEWORK_6_0"
},
"suggest": {
"horde/test": "^3 || dev-FRAMEWORK_6_0",
Expand Down Expand Up @@ -75,7 +74,8 @@
"config": {
"allow-plugins": {
"horde/horde-installer-plugin": true
}
},
"platform-check": false
},
"extra": {
"branch-alias": {
Expand Down
145 changes: 145 additions & 0 deletions data/ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Horde Components CI Templates

This directory contains templates for generating CI configuration files for Horde components.

## Template Files

### `bootstrap-github.sh.template`
Bootstrap script for GitHub Actions. Sets up environment and downloads horde-components.phar.

### `bootstrap-local.sh.template`
Bootstrap script for local development. Uses local horde-components installation.

### `workflow.yml.template`
GitHub Actions workflow configuration for running CI on pull requests and pushes.

## Template Variables

Templates use `{{VARIABLE_NAME}}` syntax for placeholders. These are replaced during generation:

### User-Provided Variables

- `{{COMPONENT_NAME}}` - Component name (e.g., "Db", "Http")
- `{{COMPONENTS_PHAR_URL}}` - URL to download horde-components.phar
- `{{WORK_DIR}}` - Working directory for CI (e.g., "/tmp/horde-ci")
- `{{PHP_VERSION}}` - Bootstrap PHP version (e.g., "8.4")
- `{{LOCAL_COMPONENTS_PATH}}` - Local path to horde-components (local mode only)
- `{{LOCAL_COMPONENT_PATH}}` - Local path to component (local mode only)

### Automatic Variables

These are added automatically by the template renderer:

- `{{TEMPLATE_VERSION}}` - Template version (e.g., "1.0.0")
- `{{GENERATED_DATE}}` - Generation timestamp
- `{{COMPONENTS_VERSION}}` - horde-components version

## Usage

### Generate CI files for a component

```bash
cd ~/git/horde/Http
horde-components ci init
```

This creates:
- `bin/ci-bootstrap.sh` - Bootstrap script
- `.github/workflows/ci.yml` - GitHub Actions workflow

### Generate for local mode

```bash
cd ~/git/horde/Http
horde-components ci init --mode=local
```

### Check if templates are outdated

```bash
cd ~/git/horde/Http
horde-components ci check
```

### Regenerate with latest templates

```bash
cd ~/git/horde/Http
horde-components ci init --force
```

## Template Versioning

Generated files include a version comment:

```bash
# Template version: 1.0.0
```

This allows detection of outdated generated files. When templates are updated, the version is incremented following semantic versioning:

- **Major version** (X.0.0): Breaking changes to generated files
- **Minor version** (1.X.0): New features, backwards compatible
- **Patch version** (1.0.X): Bug fixes

## Current Version

**Template Version:** 1.0.0

**Changelog:**
- 1.0.0 (2026-03-03): Initial template release

## Customization

Components can customize generated files after generation. However:

- Mark customized sections with comments
- Run `ci init --force` will overwrite customizations
- Consider submitting improvements back to templates

Example:

```bash
#!/bin/bash
# ... (generated code)

# CUSTOMIZATION START - Component-specific environment
export SPECIAL_VAR="value"
# CUSTOMIZATION END

# ... (generated code continues)
```

## Testing Templates

Templates can be tested without generating files:

```bash
# Dry run - show what would be generated
horde-components ci init --dry-run
```

## Adding New Templates

1. Create new `.template` file in this directory
2. Use `{{VARIABLE}}` syntax for placeholders
3. Add variables to `template-variables.md`
4. Update this README
5. Add rendering logic to `InitCommand` if needed

## Template Format

Templates are plain text files with variable substitution. Keep them:

- Simple and readable
- Well-commented
- Executable (for shell scripts)
- Valid syntax (for YAML/JSON)

## Support

For issues with templates or CI setup:

1. Check generated file versions (`ci check`)
2. Try regenerating (`ci init --force`)
3. Report issues: https://github.com/horde/components/issues
124 changes: 124 additions & 0 deletions data/ci/bootstrap-github.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash
# Horde CI Bootstrap Script (GitHub Actions)
# Generated by: horde-components {{COMPONENTS_VERSION}}
# Template version: {{TEMPLATE_VERSION}}
# Generated: {{GENERATED_DATE}}
#
# DO NOT EDIT - Regenerate with: horde-components ci init

set -e
set -o pipefail

# Configuration
BOOTSTRAP_PHP_VERSION="{{PHP_VERSION}}"
COMPONENTS_PHAR_URL="{{COMPONENTS_PHAR_URL}}"
COMPONENT_NAME="{{COMPONENT_NAME}}"
WORK_DIR="{{WORK_DIR}}"

# 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" --version &> /dev/null; then
log_error "Downloaded phar is not valid or not executable"
exit 1
fi

log_info "horde-components.phar downloaded successfully"
php "$COMPONENTS_PHAR" --version

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

php "$COMPONENTS_PHAR" ci setup \
--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
92 changes: 92 additions & 0 deletions data/ci/bootstrap-local.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
# Horde CI Bootstrap Script (Local Development)
# Generated by: horde-components {{COMPONENTS_VERSION}}
# Template version: {{TEMPLATE_VERSION}}
# Generated: {{GENERATED_DATE}}
#
# DO NOT EDIT - Regenerate with: horde-components ci init

set -e
set -o pipefail

# Configuration
COMPONENT_NAME="{{COMPONENT_NAME}}"
WORK_DIR="{{WORK_DIR}}"
LOCAL_COMPONENTS_PATH="{{LOCAL_COMPONENTS_PATH}}"
LOCAL_COMPONENT_PATH="{{LOCAL_COMPONENT_PATH}}"

# Colors for output
if [ -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
log_info() {
echo -e "${GREEN}[INFO]${NC} $*"
}

log_warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}

log_error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
}

# Stage 1: Validate environment
log_info "Horde CI Bootstrap - Stage 1 (Local mode)"
log_info "Component: $COMPONENT_NAME"

# Validate required paths
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 to your horde-components checkout"
exit 1
fi

if [ ! -d "$LOCAL_COMPONENT_PATH" ]; then
log_error "Component directory not found: $LOCAL_COMPONENT_PATH"
log_error "Set LOCAL_COMPONENT_PATH to your component checkout"
exit 1
fi

# Stage 2: Verify we have PHP
if ! command -v php &> /dev/null; then
log_error "PHP not found. Please install PHP 8.2 or higher."
exit 1
fi

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

# Stage 3: Use local horde-components
COMPONENTS_BIN="$LOCAL_COMPONENTS_PATH/bin/horde-components"
log_info "Using local horde-components: $COMPONENTS_BIN"

php "$COMPONENTS_BIN" --version

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

php "$COMPONENTS_BIN" ci setup \
--mode=local \
--work-dir="$WORK_DIR" \
--component="$COMPONENT_NAME" \
--local-path="$LOCAL_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
Loading
Loading