126 lines
5.0 KiB
YAML
126 lines
5.0 KiB
YAML
name: Project Scaffolding (Universal Engine)
|
|
run-name: Scaffolding [${{ github.event.inputs.project_path }}] - Confirm: ${{ github.event.inputs.confirm_overwrite }}
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
project_name:
|
|
description: 'Display Name (used for README)'
|
|
required: true
|
|
default: 'My New Project'
|
|
project_path:
|
|
description: 'Relative path in central-boilerplates (e.g., software/python or mods/skyrim)'
|
|
required: true
|
|
default: 'software/python'
|
|
confirm_overwrite:
|
|
description: '⚠️ WARNING: Confirm initialization of this repository'
|
|
required: true
|
|
type: boolean
|
|
default: false
|
|
dry_run:
|
|
description: 'Simulate only (logs actions without moving files)'
|
|
required: true
|
|
type: boolean
|
|
default: true
|
|
remove_workflow:
|
|
description: 'Self-Destruct: Delete this setup script after successful run?'
|
|
required: true
|
|
type: boolean
|
|
default: true
|
|
|
|
jobs:
|
|
scaffold:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Template Repo
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Validate and Fetch
|
|
run: |
|
|
# 1. Variables
|
|
PATH_INPUT="${{ github.event.inputs.project_path }}"
|
|
NAME_INPUT="${{ github.event.inputs.project_name }}"
|
|
DRY="${{ github.event.inputs.dry_run }}"
|
|
|
|
# Replace with your actual Gitea URL and Username
|
|
CENTRAL_REPO="https://gitea.nathan-falvey.synology.me/Templates/scaffold-storage"
|
|
|
|
# 2. Safety Gate
|
|
if [ "${{ github.event.inputs.confirm_overwrite }}" != "true" ]; then
|
|
echo "::error::Safety Check Failed: You must check 'confirm_overwrite' to proceed."
|
|
exit 1
|
|
fi
|
|
|
|
# 3. Remote Path Verification
|
|
# If PATH_INPUT is empty or set to special values, we'll copy the whole repo.
|
|
if [ -z "$PATH_INPUT" ] || [ "$PATH_INPUT" = "." ] || [ "$PATH_INPUT" = "*" ] || [ "${PATH_INPUT,,}" = "all" ]; then
|
|
echo "Verifying source: $CENTRAL_REPO (entire repo)"
|
|
HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" "$CENTRAL_REPO")
|
|
else
|
|
echo "Verifying source: $CENTRAL_REPO/src/branch/main/$PATH_INPUT"
|
|
HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" "$CENTRAL_REPO/src/branch/main/$PATH_INPUT")
|
|
fi
|
|
|
|
if [ "$HTTP_STATUS" -ne 200 ]; then
|
|
echo "::error::BOILERPLATE NOT FOUND!"
|
|
echo "--------------------------------------------------------"
|
|
if [ -z "$PATH_INPUT" ] || [ "$PATH_INPUT" = "." ] || [ "$PATH_INPUT" = "*" ] || [ "${PATH_INPUT,,}" = "all" ]; then
|
|
echo "The central repo '$CENTRAL_REPO' could not be reached."
|
|
else
|
|
echo "The path '$PATH_INPUT' does not exist in the central repo."
|
|
fi
|
|
echo "HTTP Status: $HTTP_STATUS"
|
|
echo "Check your central-boilerplates repo and try again."
|
|
echo "--------------------------------------------------------"
|
|
exit 1
|
|
fi
|
|
|
|
# 4. Execution Logic
|
|
if [ "$DRY" == "true" ]; then
|
|
echo "[DRY RUN] Would clone $CENTRAL_REPO"
|
|
echo "[DRY RUN] Would copy files from /$PATH_INPUT to root"
|
|
echo "[DRY RUN] Would update README.md header to: $NAME_INPUT"
|
|
else
|
|
echo "Fetching boilerplate..."
|
|
git clone --depth 1 "$CENTRAL_REPO.git" temp_configs
|
|
|
|
# Remove any git metadata from the cloned template
|
|
rm -rf temp_configs/.git
|
|
|
|
# Decide whether to copy the whole repo or a specific subpath
|
|
if [ -z "$PATH_INPUT" ] || [ "$PATH_INPUT" = "." ] || [ "$PATH_INPUT" = "*" ] || [ "${PATH_INPUT,,}" = "all" ]; then
|
|
COPY_SRC="temp_configs"
|
|
else
|
|
COPY_SRC="temp_configs/$PATH_INPUT"
|
|
fi
|
|
|
|
if [ ! -d "$COPY_SRC" ]; then
|
|
echo "::error::SOURCE NOT FOUND: $COPY_SRC"
|
|
ls -la temp_configs || true
|
|
exit 1
|
|
fi
|
|
|
|
# Copy all files including hidden ones from the chosen source
|
|
cp -a "$COPY_SRC"/. .
|
|
|
|
# Update README with the provided project name
|
|
echo "# $NAME_INPUT" > README.md
|
|
|
|
# Cleanup
|
|
rm -rf temp_configs
|
|
fi
|
|
|
|
- name: Self-Destruct
|
|
if: ${{ github.event.inputs.remove_workflow == 'true' && github.event.inputs.dry_run == 'false' }}
|
|
run: |
|
|
echo "Self-destructing: Removing scaffold.yaml..."
|
|
rm .gitea/workflows/scaffold.yaml
|
|
|
|
- name: Commit and Push
|
|
if: ${{ github.event.inputs.dry_run == 'false' }}
|
|
run: |
|
|
git config --local user.email "actions@gitea.local"
|
|
git config --local user.name "Gitea Scaffolder"
|
|
git add .
|
|
# Only push if there are actual changes
|
|
git diff --quiet && git diff --staged --quiet || (git commit -m "chore: scaffold project from $PATH_INPUT" && git push origin main) |