Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
306 changes: 306 additions & 0 deletions .github/copilot-instructions.md

Large diffs are not rendered by default.

167 changes: 98 additions & 69 deletions .github/workflows/build-switchgentool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Switch Config Generator Tool

on:
push:
branches: [ main, dev/nl/newDesignv1 ]
branches: [ main ]
tags: [ 'v*' ]
paths:
- 'src/**'
Expand All @@ -20,16 +20,50 @@ on:
- '.github/workflows/build-switchgentool.yml'
workflow_dispatch:

# ── Test job needs read; release job needs write (scoped per-job) ─────────
permissions:
contents: read
actions: read

# Cancel in-flight runs for the same branch/PR (tags always run to completion)
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}

jobs:
# ════════════════════════════════════════════════════════════════════════
# Job 1: Test — run full pytest suite
# ════════════════════════════════════════════════════════════════════════
test:
name: Test (pytest)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run tests
run: python -m pytest tests/ -v --tb=short

# ════════════════════════════════════════════════════════════════════════
# Job 2: Build — PyInstaller cross-platform executables
# ════════════════════════════════════════════════════════════════════════
build:
name: Build on ${{ matrix.os }}
needs: test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: true
matrix:
include:
- os: windows-latest
Expand All @@ -46,7 +80,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
cache: 'pip'

- name: Install build tools (Linux only)
Expand All @@ -55,22 +89,13 @@ jobs:
sudo apt-get update
sudo apt-get install -y upx

- name: Ensure requirements
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
if [ ! -f requirements.txt ]; then
echo "jinja2>=3.0.0" > requirements.txt
fi
pip install -r requirements.txt
pip install "pyinstaller==6.11.*"

- name: Quick source test (run as script)
shell: bash
run: |
python -c "import sys; print(sys.version)"
python src/main.py --help

- name: Build (Windows)
if: matrix.os == 'windows-latest'
shell: powershell
Expand All @@ -83,7 +108,7 @@ jobs:
--exclude-module matplotlib `
--exclude-module PIL `
--paths=src `
src/main.py
pyinstaller_entry.py
if (!(Test-Path "dist\\${{ matrix.exe_name }}")) { Write-Error "Build failed"; exit 1 }

- name: Build (Linux)
Expand All @@ -98,7 +123,7 @@ jobs:
--exclude-module matplotlib \
--exclude-module PIL \
--paths=src \
src/main.py
pyinstaller_entry.py
test -f "dist/${{ matrix.exe_name }}" || (echo "Build failed" && exit 1)
upx --best --lzma "dist/${{ matrix.exe_name }}" || true

Expand All @@ -107,19 +132,13 @@ jobs:
run: |
chmod +x "dist/${{ matrix.exe_name }}" || true
"dist/${{ matrix.exe_name }}" --help || (echo "Executable failed to run" && exit 1)
- name: Test BMC converter module inclusion

- name: Verify BMC converter module inclusion
shell: bash
run: |
python -c "
import sys
sys.path.insert(0, 'src')
try:
from convertors.convertors_bmc_switch_json import convert_bmc_switches
print('[OK] BMC converter module can be imported')
except ImportError as e:
print('[ERROR] BMC converter module import failed:', e)
sys.exit(1)
from src.convertors.convertors_bmc_switch_json import convert_bmc_switches
print('[OK] BMC converter module can be imported')
"

- name: Stage artifact
Expand All @@ -135,47 +154,57 @@ jobs:
name: ${{ matrix.asset_name }}
path: artifact_staging/

# release:
# name: Create Release
# needs: build
# runs-on: ubuntu-latest
# if: startsWith(github.ref, 'refs/tags/v')
# steps:
# - name: Checkout
# uses: actions/checkout@v4

# - name: Download artifacts
# uses: actions/download-artifact@v4
# with:
# path: ./artifacts

# - name: Show downloaded files
# run: ls -Rla ./artifacts

# - name: Create GitHub Release
# uses: softprops/action-gh-release@v2
# with:
# files: |
# ./artifacts/network-config-generator-windows-amd64/network_config_generator.exe
# ./artifacts/network-config-generator-linux-amd64/network_config_generator
# body: |
# ## Network Switch Config Generator ${{ github.ref_name }}

# ### Download
# 1) Grab the file for your OS
# 2) (Linux) Make it executable: `chmod +x network_config_generator`
# 3) Run: `./network_config_generator --help`

# ### Usage
# ```bash
# ./network_config_generator --input_json lab_input.json --output_folder output/
# ./network_config_generator --input_json standard_input.json --output_folder output/
# ./network_config_generator --input_json lab_input.json --convertor my.custom.convertor
# ```

# ### Features
# - Auto-detects input format (lab vs standard)
# - Converts lab format to standard automatically
# - Generates network switch configurations
# - Custom convertors & multi-switch support
# - Cross-platform executables
# ════════════════════════════════════════════════════════════════════════
# Job 3: Release — create GitHub Release (tag pushes only)
# ════════════════════════════════════════════════════════════════════════
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')

# Require approval via GitHub Environment before publishing
environment: production

permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts

- name: Show downloaded files
run: ls -Rla ./artifacts

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
./artifacts/network-config-generator-windows-amd64/network_config_generator.exe
./artifacts/network-config-generator-linux-amd64/network_config_generator
body: |
## Network Switch Config Generator ${{ github.ref_name }}

### Download
1) Grab the file for your OS
2) (Linux) Make it executable: `chmod +x network_config_generator`
3) Run: `./network_config_generator --help`

### Usage
```bash
./network_config_generator --input_json lab_input.json --output_folder output/
./network_config_generator --input_json standard_input.json --output_folder output/
./network_config_generator --input_json lab_input.json --convertor my.custom.convertor
```

### Features
- Auto-detects input format (lab vs standard)
- Converts lab format to standard automatically
- Generates network switch configurations
- Custom convertors & multi-switch support
- Cross-platform executables
26 changes: 20 additions & 6 deletions .github/workflows/triage-submissions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
issues:
types: [opened, edited]

permissions:
issues: write

jobs:
validate-and-assign:
# Only run for config submissions
Expand Down Expand Up @@ -71,16 +74,23 @@ jobs:
const spamPatterns = [
/<script/i,
/javascript:/i,
/\$\{.*\}/, // Template injection
/\{\{.*\}\}/, // Template injection
/onclick=/i,
/onerror=/i,
];
// Template-like patterns (${} and {{}}) are legitimate in Dell OS10 / Jinja2 configs
const templatePatterns = [
/\$\{.*\}/,
/\{\{.*\}\}/,
];

const hasSpam = spamPatterns.some(p => p.test(body));
if (hasSpam) {
errors.push('❌ Submission contains suspicious patterns. Please remove any scripts or code injection attempts.');
}
const hasTemplatePatterns = templatePatterns.some(p => p.test(body));
if (hasTemplatePatterns) {
warnings.push('⚠️ Config contains template-like patterns (${ } or {{ }}). This is fine for Dell OS10 / Jinja2 configs.');
}

// ========================================
// CHECK 4: Required checkboxes completed
Expand All @@ -90,8 +100,8 @@ jobs:

console.log(`Checkboxes: ${checkedBoxes}/${totalBoxes} checked`);

if (checkedBoxes < 3) {
errors.push('❌ Please check all required checkboxes (sanitization, responsibility acknowledgment, contributing guide).');
if (checkedBoxes < 2) {
errors.push('❌ Please check the required checkboxes (password sanitization and CONTRIBUTING.md review).');
}

// ========================================
Expand Down Expand Up @@ -128,9 +138,11 @@ jobs:
- name: Handle valid submission - Assign to Copilot
if: fromJson(steps.validate.outputs.result).valid
uses: actions/github-script@v7
env:
VALIDATION_RESULT: ${{ steps.validate.outputs.result }}
with:
script: |
const result = JSON.parse('${{ steps.validate.outputs.result }}');
const result = JSON.parse(process.env.VALIDATION_RESULT);
const warnings = result.warnings || [];

console.log('✅ Submission validated, assigning to Copilot');
Expand Down Expand Up @@ -185,9 +197,11 @@ jobs:
- name: Handle invalid submission - Request fixes
if: "!fromJson(steps.validate.outputs.result).valid"
uses: actions/github-script@v7
env:
VALIDATION_RESULT: ${{ steps.validate.outputs.result }}
with:
script: |
const result = JSON.parse('${{ steps.validate.outputs.result }}');
const result = JSON.parse(process.env.VALIDATION_RESULT);
const errors = result.errors || [];
const warnings = result.warnings || [];

Expand Down
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# Binaries for programs and plugins
# Binaries
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test
_*
!**/__init__.py

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
1
# Dependency directories (remove the comment below to include it)
# Generated configs and outputs
**/generated_*.cfg
generated_outputs/

Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

Loading