#!/usr/bin/env bash # enable-auto-deploy.sh — flip the workflow_dispatch-only gate on # .forgejo/workflows/deploy.yml back to push:main + tag:v*. Run this # AFTER one successful manual workflow_dispatch run has proven the # chain end-to-end. set -Eeuo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" . "$SCRIPT_DIR/lib.sh" trap_errors REPO_ROOT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel) || die "not in a git repo" DEPLOY_YML="$REPO_ROOT/.forgejo/workflows/deploy.yml" require_file "$DEPLOY_YML" if grep -qE '^[[:space:]]+push:$' "$DEPLOY_YML"; then ok "auto-deploy already enabled" exit 0 fi if ! grep -qE '^[[:space:]]+# push:' "$DEPLOY_YML"; then die "deploy.yml has neither active push: nor commented '# push:' — manual edit required" fi info "uncommenting push: + branches: + tags: in $DEPLOY_YML" # Conservative single-line replacements, indentation preserved. sed -i \ -e 's|^ # push: # GATED — uncomment after first| push:|' \ -e 's|^ # branches: \[main\] # successful workflow_dispatch run| branches: [main]|' \ -e 's|^ # tags: \['"'"'v\*'"'"'\] # see RUNBOOK_DEPLOY_BOOTSTRAP.md| tags: ['"'"'v*'"'"']|' \ "$DEPLOY_YML" # Verify. if ! grep -qE '^[[:space:]]+push:$' "$DEPLOY_YML"; then die "sed didn't apply — open $DEPLOY_YML and uncomment by hand" fi ok "edited $DEPLOY_YML" info "diff:" git -C "$REPO_ROOT" --no-pager diff -- "$DEPLOY_YML" >&2 cat >&2 <