ci(gitea): shared composite actions + pipeline generator for Gitea Actions
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AqpXh3hQMMaC74pTjFq4it Gitea 1.25 cannot run reusable workflows (workflow_call), so the logic of deploy-app.yml, smoke.yml and ci.yml moves into composite actions under .gitea/actions/, and each repo gets a thin pipeline rendered by tools/gitea-pipeline/render.py from repos.json. .github/workflows is left untouched (Gitea ignores it once .gitea/workflows exists).
This commit is contained in:
100
.gitea/actions/deploy/action.yml
Normal file
100
.gitea/actions/deploy/action.yml
Normal file
@@ -0,0 +1,100 @@
|
||||
name: Deploy to Hostinger
|
||||
description: >-
|
||||
rsync one plugin/theme to staging or production on Hostinger. Gitea port of the
|
||||
GitHub reusable deploy-app.yml (Gitea 1.25 has no workflow_call): same rsync
|
||||
excludes, retry-on-throttle (Hostinger rate-limits runner IPs), best-effort
|
||||
plugin-inventory guard and health check. New: records the deployed commit in
|
||||
~/.peptide-deploys/<stage>/<target> (outside public_html) for deploy-health.
|
||||
|
||||
inputs:
|
||||
stage:
|
||||
description: "staging | production"
|
||||
required: true
|
||||
target_path:
|
||||
description: "wp-content subpath, e.g. wp-content/plugins/prautoblogger"
|
||||
required: true
|
||||
ssh_private_key:
|
||||
required: true
|
||||
ssh_host:
|
||||
required: true
|
||||
ssh_port:
|
||||
required: true
|
||||
ssh_username:
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: rsync to ${{ inputs.stage }} (retry-on-throttle + inventory guard)
|
||||
shell: bash
|
||||
env:
|
||||
STAGE: ${{ inputs.stage }}
|
||||
TARGET_PATH: ${{ inputs.target_path }}
|
||||
SSH_PRIVATE_KEY: ${{ inputs.ssh_private_key }}
|
||||
SSH_HOST: ${{ inputs.ssh_host }}
|
||||
SSH_PORT: ${{ inputs.ssh_port }}
|
||||
SSH_USERNAME: ${{ inputs.ssh_username }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
case "$STAGE" in staging|production) ;; *) echo "::error::stage must be staging or production"; exit 1 ;; esac
|
||||
case "$TARGET_PATH" in
|
||||
*..*) echo "::error::'..' not allowed in target_path"; exit 1 ;;
|
||||
wp-content/plugins/?*|wp-content/themes/?*|wp-content/mu-plugins/?*) ;;
|
||||
*) echo "::error::refusing target_path '$TARGET_PATH'"; exit 1 ;;
|
||||
esac
|
||||
WORK=$(mktemp -d); trap 'rm -rf "$WORK"' EXIT
|
||||
printf '%s\n' "$SSH_PRIVATE_KEY" > "$WORK/key"; chmod 600 "$WORK/key"
|
||||
ssh-keyscan -p "$SSH_PORT" "$SSH_HOST" > "$WORK/known_hosts" 2>/dev/null || true
|
||||
SSHOPT="-i $WORK/key -p $SSH_PORT -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=$WORK/known_hosts -o ConnectTimeout=30 -o BatchMode=yes"
|
||||
R="$SSH_USERNAME@$SSH_HOST"
|
||||
BASE="/home/$SSH_USERNAME/domains/peptiderepo.com/public_html"
|
||||
if [ "$STAGE" = staging ]; then DEST="$BASE/staging/$TARGET_PATH"; else DEST="$BASE/$TARGET_PATH"; fi
|
||||
|
||||
PRE=0
|
||||
if [ "$STAGE" = production ]; then
|
||||
PRE=$(ssh -n $SSHOPT "$R" "wp --path=$BASE plugin list --status=active --field=name 2>/dev/null | wc -l" 2>/dev/null || echo 0)
|
||||
echo "Pre-deploy active plugins (best-effort): $PRE"
|
||||
fi
|
||||
|
||||
n=0
|
||||
until [ "$n" -ge 4 ]; do
|
||||
rsync -avz --delete \
|
||||
--exclude '.git' --exclude '.github' --exclude '.gitea' --exclude 'tests' --exclude 'node_modules' \
|
||||
--exclude 'vendor' --exclude 'composer.json' --exclude 'composer.lock' \
|
||||
--exclude 'phpunit.xml' --exclude 'phpunit.xml.dist' --exclude 'phpcs.xml.dist' \
|
||||
--exclude '.phpcs.xml.dist' --exclude 'ARCHITECTURE.md' --exclude 'CONVENTIONS.md' \
|
||||
--exclude 'CHANGELOG.md' --exclude 'qa-reviews' \
|
||||
-e "ssh $SSHOPT" \
|
||||
./ "$R:$DEST/" && break
|
||||
n=$((n+1)); echo "$STAGE rsync failed (attempt $n/4) - Hostinger may be throttling runner IPs; retrying in 25s..."; sleep 25
|
||||
done
|
||||
[ "$n" -lt 4 ] || { echo "::error::$STAGE rsync failed after 4 attempts"; exit 1; }
|
||||
|
||||
if [ "$STAGE" = production ]; then
|
||||
# Same remote command as the GitHub pipeline (the litespeed purge there runs
|
||||
# relative to $HOME, i.e. is effectively a no-op; kept as-is, see port notes).
|
||||
POST=$(ssh -n $SSHOPT "$R" "wp --path=$BASE plugin list --status=active --field=name 2>/dev/null | wc -l; find wp-content/litespeed/ -type f -delete 2>/dev/null; touch .lscache_purge 2>/dev/null || true" 2>/dev/null | head -1 || echo 0)
|
||||
echo "Post-deploy active plugins (best-effort): $POST"
|
||||
if [ "${PRE:-0}" -gt 0 ] && [ "${POST:-0}" -gt 0 ] && [ "${POST:-0}" -lt "${PRE:-0}" ]; then
|
||||
echo "::error::active plugin count dropped ${PRE} -> ${POST} after deploy"; exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
SLUG=$(printf '%s' "$TARGET_PATH" | tr '/' '_')
|
||||
ssh -n $SSHOPT "$R" "mkdir -p ~/.peptide-deploys/$STAGE && printf '%s %s %s\n' '$GITHUB_SHA' '$GITHUB_REPOSITORY' \"\$(date -u +%FT%TZ)\" > ~/.peptide-deploys/$STAGE/$SLUG" \
|
||||
|| echo "::warning::could not record deployed commit for deploy-health"
|
||||
echo "Deployed ${GITHUB_SHA:0:7} to $STAGE:$TARGET_PATH"
|
||||
|
||||
- name: Health check (${{ inputs.stage }})
|
||||
shell: bash
|
||||
env:
|
||||
STAGE: ${{ inputs.stage }}
|
||||
run: |
|
||||
sleep 5
|
||||
if [ "$STAGE" = staging ]; then
|
||||
echo "Staging responded: HTTP $(curl -s -o /dev/null -w '%{http_code}' https://staging.peptiderepo.com/ || echo 000)"
|
||||
exit 0
|
||||
fi
|
||||
S=$(curl -s -o /dev/null -w '%{http_code}' https://peptiderepo.com)
|
||||
if [ "$S" != "200" ] && [ "$S" != "403" ]; then echo "::error::site returned HTTP $S"; exit 1; fi
|
||||
echo "Production healthy (HTTP $S)"
|
||||
Reference in New Issue
Block a user