feat: add project scaffolding workflow and initialization guide

This commit is contained in:
2026-03-02 17:27:59 +00:00
parent 6189129ca5
commit d69a1f464f
2 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
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)

42
HOWTO_INITIALIZE.md Normal file
View File

@@ -0,0 +1,42 @@
# `HOWTO_INITIALIZE.md`
This repository is a **Dynamic Template**. Instead of manually deleting files or renaming folders, use the integrated **Gitea Actions** to scaffold your specific environment.
## 🚀 Getting Started
Follow these steps to initialize your project structure, documentation, and licensing:
1. **Navigate to Actions:** Click on the **Actions** tab at the top of this repository.
2. **Select Workflow:** On the left sidebar, select **"Project Scaffolding (Advanced)"**.
3. **Run Workflow:** Click the **"Run workflow"** dropdown menu on the right.
### ⚙️ Configuration Options
| Input | Description |
| --- | --- |
| **Confirm Overwrite** | **Mandatory.** You must check this box to allow the script to modify the repository. |
| **Dry Run** | **Default: Enabled.** Runs the script in simulation mode. Check the logs to see what *would* happen without making changes. |
| **Project Language** | Select your stack (Python, Node, C++, etc.) to fetch the appropriate `.gitignore` and boilerplate. |
---
## 🛡️ Safety Features
### The Safety Switch
To prevent accidental data loss on existing projects, the automation will **fail immediately** unless the `confirm_overwrite` checkbox is active. This ensures that a "misclick" in the UI doesn't wipe your `README.md`.
### Dry Run Mode
It is highly recommended to run the workflow with **Dry Run** enabled first.
* **In Dry Run:** The action logs will display `[DRY RUN] Would execute: mkdir -p src`.
* **In Production:** Once you are satisfied with the simulated output, uncheck **Dry Run** and run the workflow again to commit the files to `main`.
---
## 📂 Standardized Structure
Once initialized, your repository will inherit a hierarchy based on the structure you chose from. If you are unsure about your choice, use the Dry Run mode.
---