CakePHP 5.4 app for live polls: create via email without login, manage via secret admin link, join via code. Includes slide types (choice, wordcloud, open, scale, content), presenter mode, CSV export, captcha, throttling, tests and Gitea CI/deploy workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
6.1 KiB
YAML
147 lines
6.1 KiB
YAML
# CI + Deployment (Gitea Actions, GitHub Actions compatible).
|
||
#
|
||
# - test: runs on every push to any branch. Its commit status is what the branch
|
||
# protection of main requires, so a PR can only be merged once the tests are green.
|
||
# - deploy: runs only on push to main (i.e. after a merge), only if the tests are green and
|
||
# ONLY if the repository variable DEPLOY_ENABLED is "true" (deactivated by default).
|
||
#
|
||
# Target: DirectAdmin hosting, app checked out directly into the domain's public_html
|
||
# (the root .htaccess/index.php forward every request to webroot/).
|
||
# The server pulls the code itself over HTTPS with the job's short-lived token, so no
|
||
# deploy key and no stored credentials are needed on the server.
|
||
#
|
||
# Repository variables (Settings → Actions → Variables):
|
||
# DEPLOY_ENABLED "true" to enable deployment (anything else = disabled)
|
||
# SSH_HOST e.g. plenario.gnilebein.de
|
||
# SSH_PORT optional, default 22
|
||
# SSH_USER e.g. gnilebein.de
|
||
# SSH_FINGERPRINT optional but recommended: SHA256 host key fingerprint (ssh-keygen -lf)
|
||
# DEPLOY_PATH e.g. /home/gnilebein.de/domains/plenario.gnilebein.de/public_html
|
||
# PHP_BIN optional, PHP CLI binary (default: auto-detect, must be >= 8.4)
|
||
# COMPOSER_BIN optional, composer command (default: auto-detect, else composer.phar
|
||
# is installed once to ~/.local/bin)
|
||
# Repository secrets:
|
||
# SSH_KEY private deploy key (preferred), or
|
||
# SSH_PASSWORD password (fallback)
|
||
#
|
||
# One-time setup on the server: create config/.env (DEBUG=false, APP_FULL_BASE_URL,
|
||
# SECURITY_SALT, mail settings – see config/.env.example). The deploy aborts without it.
|
||
name: CI / Deploy
|
||
|
||
on:
|
||
push:
|
||
branches: ['**']
|
||
|
||
jobs:
|
||
test:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Setup PHP
|
||
uses: shivammathur/setup-php@v2
|
||
with:
|
||
php-version: '8.5'
|
||
extensions: mbstring, intl, pdo_sqlite, sqlite3
|
||
coverage: none
|
||
|
||
- name: Install dependencies
|
||
run: composer install --no-interaction --prefer-dist --no-progress
|
||
|
||
- name: Run tests
|
||
run: vendor/bin/phpunit
|
||
|
||
- name: Coding standard
|
||
run: vendor/bin/phpcs --warning-severity=0
|
||
|
||
deploy:
|
||
needs: test
|
||
# Deactivated until the repository variable DEPLOY_ENABLED is "true".
|
||
if: vars.DEPLOY_ENABLED == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||
runs-on: ubuntu-latest
|
||
concurrency:
|
||
group: deploy-production
|
||
cancel-in-progress: false
|
||
steps:
|
||
- name: Deploy via SSH
|
||
uses: appleboy/ssh-action@v1.0.3
|
||
with:
|
||
host: ${{ vars.SSH_HOST }}
|
||
port: ${{ vars.SSH_PORT || 22 }}
|
||
username: ${{ vars.SSH_USER }}
|
||
key: ${{ secrets.SSH_KEY }}
|
||
password: ${{ secrets.SSH_PASSWORD }}
|
||
fingerprint: ${{ vars.SSH_FINGERPRINT }}
|
||
script_stop: true
|
||
script: |
|
||
set -eu
|
||
DEPLOY_PATH="${{ vars.DEPLOY_PATH }}"
|
||
PHP="${{ vars.PHP_BIN }}"
|
||
COMPOSER="${{ vars.COMPOSER_BIN }}"
|
||
REPO_URL="${{ github.server_url }}/${{ github.repository }}.git"
|
||
GIT_AUTH="Authorization: Basic $(printf 'oauth2:%s' '${{ github.token }}' | base64 | tr -d '\n')"
|
||
|
||
if [ -z "$DEPLOY_PATH" ] || [ ! -d "$DEPLOY_PATH" ]; then
|
||
echo "DEPLOY_PATH is not set or does not exist: '$DEPLOY_PATH'" >&2
|
||
exit 1
|
||
fi
|
||
cd "$DEPLOY_PATH"
|
||
|
||
# --- PHP ---------------------------------------------------------------
|
||
if [ -z "$PHP" ]; then
|
||
for candidate in /usr/local/php85/bin/php /usr/local/php84/bin/php /usr/local/bin/php php; do
|
||
if command -v "$candidate" >/dev/null 2>&1 \
|
||
&& "$candidate" -r 'exit(PHP_VERSION_ID >= 80400 ? 0 : 1);'; then
|
||
PHP="$candidate"
|
||
break
|
||
fi
|
||
done
|
||
fi
|
||
if [ -z "$PHP" ]; then
|
||
echo "No PHP >= 8.4 found – set the repository variable PHP_BIN." >&2
|
||
exit 1
|
||
fi
|
||
echo "Using PHP: $PHP ($("$PHP" -r 'echo PHP_VERSION;'))"
|
||
|
||
# --- Composer (installed once, verified against the official checksum) --
|
||
if [ -z "$COMPOSER" ]; then
|
||
if command -v composer >/dev/null 2>&1; then
|
||
COMPOSER="$PHP $(command -v composer)"
|
||
else
|
||
PHAR="$HOME/.local/bin/composer.phar"
|
||
if [ ! -f "$PHAR" ]; then
|
||
mkdir -p "$HOME/.local/bin"
|
||
EXPECTED="$(curl -fsSL https://composer.github.io/installer.sig)"
|
||
curl -fsSL https://getcomposer.org/installer -o /tmp/composer-setup.php
|
||
ACTUAL="$("$PHP" -r "echo hash_file('sha384', '/tmp/composer-setup.php');")"
|
||
if [ "$EXPECTED" != "$ACTUAL" ]; then
|
||
rm -f /tmp/composer-setup.php
|
||
echo "Composer installer checksum mismatch" >&2
|
||
exit 1
|
||
fi
|
||
"$PHP" /tmp/composer-setup.php --quiet --install-dir="$HOME/.local/bin" --filename=composer.phar
|
||
rm -f /tmp/composer-setup.php
|
||
fi
|
||
COMPOSER="$PHP $PHAR"
|
||
fi
|
||
fi
|
||
|
||
# --- Code: first run initialises the checkout, later runs update it -----
|
||
if [ ! -d .git ]; then
|
||
git init -q
|
||
git remote add origin "$REPO_URL"
|
||
fi
|
||
git remote set-url origin "$REPO_URL"
|
||
git -c "http.extraHeader=$GIT_AUTH" fetch --quiet origin '+refs/heads/main:refs/remotes/origin/main'
|
||
git reset --hard origin/main
|
||
echo "Deployed commit: $(git rev-parse --short HEAD)"
|
||
|
||
if [ ! -f config/.env ]; then
|
||
echo "config/.env is missing – create it once on the server (see config/.env.example)." >&2
|
||
exit 1
|
||
fi
|
||
|
||
$COMPOSER install --no-dev --optimize-autoloader --no-interaction --no-progress
|
||
"$PHP" bin/cake.php migrations migrate
|
||
"$PHP" bin/cake.php cache clear_all
|