#!/usr/bin/env bash # enable-auto-deploy.sh — re-enable Forgejo Actions deploy workflow. # # Two scenarios : # A. .forgejo/workflows.disabled/ exists (current state on this branch) # → rename back to .forgejo/workflows/, then ensure deploy.yml's # push: trigger is uncommented. # B. .forgejo/workflows/deploy.yml exists with push: commented out # → just uncomment. # # Run AFTER one successful 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" WF_DIR="$REPO_ROOT/.forgejo/workflows" WF_DISABLED="$REPO_ROOT/.forgejo/workflows.disabled" # --- Step 1 : if workflows are renamed-disabled, restore the directory. ------- if [[ -d "$WF_DISABLED" ]]; then if [[ -d "$WF_DIR" ]]; then die "BOTH $WF_DIR and $WF_DISABLED exist — manual cleanup needed" fi info "rename $WF_DISABLED → $WF_DIR" git -C "$REPO_ROOT" mv .forgejo/workflows.disabled .forgejo/workflows ok "directory restored" fi DEPLOY_YML="$WF_DIR/deploy.yml" require_file "$DEPLOY_YML" # --- Step 2 : if push: trigger is commented, uncomment it. -------------------- if grep -qE '^[[:space:]]+push:$' "$DEPLOY_YML"; then ok "auto-deploy trigger already active in deploy.yml" else 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" 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" if ! grep -qE '^[[:space:]]+push:$' "$DEPLOY_YML"; then die "sed didn't apply — open $DEPLOY_YML and uncomment by hand" fi ok "trigger uncommented" fi # --- Step 3 : prompt to commit + push. ---------------------------------------- info "diff:" git -C "$REPO_ROOT" --no-pager diff -- "$WF_DIR" >&2 || true cat >&2 <