From 789c7b3750fe6f8feb6d0e8c78445bba41fb3fa0 Mon Sep 17 00:00:00 2001 From: engelgardt Date: Sat, 16 May 2026 12:28:10 +0300 Subject: [PATCH] refactor: move source into src/ src/netswitch.ps1 (single file, ~150 lines). CI updated to build from this path. Added CONTRIBUTING.md describing layout, build, and release flow. No user-visible behaviour change. --- .github/workflows/release.yml | 2 +- CONTRIBUTING.md | 62 ++++++++++++++++++++++++++++++ netswitch.ps1 => src/netswitch.ps1 | 0 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 CONTRIBUTING.md rename netswitch.ps1 => src/netswitch.ps1 (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a025165..df7fcd1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: run: | Import-Module ps2exe $ver = '${{ steps.ver.outputs.version }}' - Invoke-ps2exe -inputFile netswitch.ps1 -outputFile netswitch.exe ` + Invoke-ps2exe -inputFile src/netswitch.ps1 -outputFile netswitch.exe ` -title "netswitch" -description "NIC IP/DHCP toggle - made by engelgardt" ` -company "engelgardt" -version "$ver.0" ` -requireAdmin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..2a06c3e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,62 @@ +# Contributing + +> Project layout, build, and release flow. **If you only want to use the tool — read [README](README.md) instead.** + +## Repo layout + +``` +netswitch/ +├── .github/ +│ ├── workflows/release.yml ← CI: tag-driven build + GitHub Release +│ └── ISSUE_TEMPLATE/ ← bug / feature / security routing +├── src/ +│ └── netswitch.ps1 ← the whole tool (~150 lines) +├── CHANGELOG.md ← Keep a Changelog format, newest first +├── CONTRIBUTING.md ← this file +├── LICENSE / README.md / SECURITY.md +└── .gitignore +``` + +## Run from source (no exe) + +``` +powershell -ExecutionPolicy Bypass -File src/netswitch.ps1 +``` + +The script self-elevates through UAC if you launched it without admin. + +## Build the portable .exe locally + +``` +Install-Module ps2exe -Scope CurrentUser +Invoke-ps2exe -inputFile src/netswitch.ps1 -outputFile netswitch.exe ` + -title "netswitch" -description "NIC IP/DHCP toggle - made by engelgardt" ` + -company "engelgardt" -version "1.0.0.0" ` + -requireAdmin +``` + +## Cut a release + +1. Update `src/netswitch.ps1` — bump `$NetswitchVersion` to `X.Y.Z`. +2. Update `CHANGELOG.md` — move items from `[Unreleased]` into a new `[X.Y.Z]` section with today's date. +3. Commit: `git commit -am "vX.Y.Z: …"`. +4. Tag: `git tag vX.Y.Z`. +5. Push: `git push && git push --tags`. + +GitHub Actions picks up the tag, builds the exe via ps2exe, writes the SHA-256, and creates the GitHub Release with the zip attached. + +## Where features go + +The whole tool is a single PowerShell file with these sections (in order): + +1. `$NetswitchVersion` / `$GithubRepo` — top of file. +2. **Self-elevate** block — UAC if non-admin. +3. **Banner** — Write-Host title. +4. **`Test-NetswitchUpdate`** — GitHub /releases/latest poll. +5. **Adapter filter + picker** — `$skipDescriptionPattern`, `$skipMediaTypes`, `Get-NetAdapter | Where-Object {...}`. +6. **Mode prompt** — Static / DHCP. +7. **Static branch** — `netsh interface ipv4 set address ... static ...`. +8. **DHCP branch** — `netsh interface ipv4 set address ... source=dhcp`. +9. **Current config display** — `Get-NetIPAddress | Format-Table`. + +If a section grows past ~50 lines, factor it into `src/lib/.ps1` and dot-source it from the main file. diff --git a/netswitch.ps1 b/src/netswitch.ps1 similarity index 100% rename from netswitch.ps1 rename to src/netswitch.ps1