From f0d62490f24947c503ca3cbea57007fad06483fa Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Thu, 18 Jun 2026 19:27:49 +0700 Subject: [PATCH] Phase 6c: CI/CD, Velopack release pipeline, version-flow fix, build/update docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Workflows (.github/workflows/): - build.yml: Windows restore + dotnet format --verify + Release build (0-warning gate) + tests, on PR/push to main. - codeql.yml: project-specific CodeQL C# (Windows, builds CommandForge.slnx). The shared reusable codeql-csharp.yml runs on Linux and expects a .sln, so it cannot build this WPF/.slnx app. - release.yml: on tag v*, install vpk, download the previous release for the delta base (continue-on-error on first release), publish self-contained + vpk pack, publish the GitHub Release (vpk upload github), attach SHA-256 checksums.txt, and optionally submit to VirusTotal (gated on VT_API_KEY). - announce-release.yml + notify-ci-failure.yml: thin callers of the reusable Discord workflows in poli0981/.github (secrets: inherit). - dependabot.yml: weekly nuget + github-actions updates. Fix: scripts/pack.ps1 now passes -p:Version/-p:InformationalVersion to dotnet publish, so the in-app "App version" matches the release tag instead of defaulting to 1.0.0. Docs (English, public): BUILD.md, RELEASING.md, UPDATES.md — including the Velopack update mechanism (first vs subsequent release and how deltas are produced) and the required repo secrets. No source changes; 0-warning Release build, 104 tests pass; actionlint clean. Co-Authored-By: Claude Opus 4.8 --- .github/dependabot.yml | 17 +++++ .github/workflows/announce-release.yml | 23 ++++++ .github/workflows/build.yml | 34 +++++++++ .github/workflows/codeql.yml | 45 ++++++++++++ .github/workflows/notify-ci-failure.yml | 14 ++++ .github/workflows/release.yml | 93 +++++++++++++++++++++++++ BUILD.md | 59 ++++++++++++++++ RELEASING.md | 50 +++++++++++++ UPDATES.md | 47 +++++++++++++ scripts/pack.ps1 | 6 +- 10 files changed, 387 insertions(+), 1 deletion(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/announce-release.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/notify-ci-failure.yml create mode 100644 .github/workflows/release.yml create mode 100644 BUILD.md create mode 100644 RELEASING.md create mode 100644 UPDATES.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7d3495d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +version: 2 +updates: + - package-ecosystem: nuget + directory: "/" + schedule: + interval: weekly + open-pull-requests-limit: 5 + commit-message: + prefix: "deps" + + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: weekly + open-pull-requests-limit: 5 + commit-message: + prefix: "ci" diff --git a/.github/workflows/announce-release.yml b/.github/workflows/announce-release.yml new file mode 100644 index 0000000..e46c1c9 --- /dev/null +++ b/.github/workflows/announce-release.yml @@ -0,0 +1,23 @@ +name: Announce Release + +# Posts a release announcement to Discord (reuses the shared workflow in poli0981/.github). +# Requires repo/org secret DISCORD_RELEASES_WEBHOOK (or DISCORD_REPO_WEBHOOK); optional +# DISCORD_PING_ROLE_ID. No-op effect if those secrets are unset (the job will error — set them +# or disable this workflow). + +on: + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: Release tag to announce (e.g. v0.3.0) + required: true + type: string + +jobs: + announce: + uses: poli0981/.github/.github/workflows/announce-release.yml@main + with: + tag_override: ${{ github.event.inputs.tag || '' }} + secrets: inherit diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8615e6e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build + +on: + push: + branches: [main] + pull_request: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + # WPF (net10.0-windows) only builds on Windows. + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.0.x' + + - name: Restore + run: dotnet restore CommandForge.slnx + + - name: Verify formatting + run: dotnet format CommandForge.slnx --verify-no-changes --no-restore + + - name: Build (Release, warnings = errors) + run: dotnet build CommandForge.slnx -c Release --no-restore + + - name: Test + run: dotnet test CommandForge.slnx -c Release --no-build diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..b1acb97 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,45 @@ +name: CodeQL + +# Project-specific CodeQL (not the shared reusable codeql-csharp.yml): this is a WPF +# (net10.0-windows) app that only builds on Windows and uses a .slnx solution, whereas the +# reusable workflow runs on ubuntu and looks for a .sln. + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '37 14 * * 1' # Mondays 14:37 UTC + workflow_dispatch: + +permissions: + actions: read + contents: read + security-events: write + +jobs: + analyze: + name: Analyze (csharp) + runs-on: windows-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.0.x' + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: csharp + queries: security-extended + + - name: Build + run: dotnet build CommandForge.slnx -c Release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:csharp" diff --git a/.github/workflows/notify-ci-failure.yml b/.github/workflows/notify-ci-failure.yml new file mode 100644 index 0000000..370ee51 --- /dev/null +++ b/.github/workflows/notify-ci-failure.yml @@ -0,0 +1,14 @@ +name: Notify CI Failure + +# Posts a Discord alert when the Build workflow fails on main (reuses the shared workflow in +# poli0981/.github). Requires repo/org secret DISCORD_CI_WEBHOOK. + +on: + workflow_run: + workflows: ["Build"] + types: [completed] + +jobs: + notify: + uses: poli0981/.github/.github/workflows/notify-ci-failure.yml@main + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c5eec4e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,93 @@ +name: Release + +# Triggered by pushing a SemVer tag (vX.Y.Z). Builds a self-contained, Velopack-packaged +# release and publishes it to GitHub Releases with SHA-256 checksums and (optionally) a +# VirusTotal scan. No code signing yet (see SECURITY.md). + +on: + push: + tags: ['v*'] + workflow_dispatch: + inputs: + version: + description: 'Version without the leading v (e.g. 0.3.0)' + required: true + type: string + +permissions: + contents: write + +jobs: + release: + runs-on: windows-latest + env: + REPO_URL: https://github.com/poli0981/CommandForge + VT_API_KEY: ${{ secrets.VT_API_KEY }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.0.x' + + - name: Resolve version and tag + id: ver + shell: pwsh + run: | + if ('${{ github.event_name }}' -eq 'workflow_dispatch') { + $version = '${{ github.event.inputs.version }}' + $tag = "v$version" + } else { + $tag = '${{ github.ref_name }}' + $version = $tag -replace '^v', '' + } + "version=$version" >> $env:GITHUB_OUTPUT + "tag=$tag" >> $env:GITHUB_OUTPUT + Write-Host "Releasing $version (tag $tag)" + + - name: Install Velopack CLI (vpk) + shell: pwsh + run: | + dotnet tool install -g vpk + "$env:USERPROFILE\.dotnet\tools" >> $env:GITHUB_PATH + + - name: Download previous release (delta base) + continue-on-error: true # first release has nothing to download + run: vpk download github --repoUrl $env:REPO_URL --token ${{ secrets.GITHUB_TOKEN }} + shell: pwsh + + - name: Publish + pack (Velopack) + run: ./scripts/pack.ps1 -Version ${{ steps.ver.outputs.version }} + shell: pwsh + + - name: Publish GitHub Release (Velopack) + run: > + vpk upload github + --repoUrl $env:REPO_URL + --token ${{ secrets.GITHUB_TOKEN }} + --publish + --releaseName "CommandForge ${{ steps.ver.outputs.version }}" + --tag ${{ steps.ver.outputs.tag }} + shell: pwsh + + - name: SHA-256 checksums + shell: pwsh + run: | + $rel = Join-Path (Get-Location) 'Releases' + Get-ChildItem $rel -File -Exclude 'checksums.txt' | + Get-FileHash -Algorithm SHA256 | + ForEach-Object { '{0} {1}' -f $_.Hash.ToLower(), (Split-Path $_.Path -Leaf) } | + Out-File (Join-Path $rel 'checksums.txt') -Encoding ascii + gh release upload ${{ steps.ver.outputs.tag }} (Join-Path $rel 'checksums.txt') --clobber + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: VirusTotal scan (optional) + if: env.VT_API_KEY != '' + uses: crazy-max/ghaction-virustotal@v4 + with: + vt_api_key: ${{ env.VT_API_KEY }} + update_release_body: true + files: | + Releases/*-Setup.exe + Releases/*-full.nupkg diff --git a/BUILD.md b/BUILD.md new file mode 100644 index 0000000..85468e8 --- /dev/null +++ b/BUILD.md @@ -0,0 +1,59 @@ +# Building CommandForge + +## Requirements + +- Windows 10 (22H2) or Windows 11 +- **.NET 10 SDK** (`dotnet --version` → `10.0.x`) +- For packaging: the **Velopack CLI** — `dotnet tool install -g vpk` +- Admin rights are only needed to **test** elevated commands, not to build. + +The solution file is **`CommandForge.slnx`** (the XML solution format). + +## Build, run, test + +```bash +dotnet restore CommandForge.slnx +dotnet build CommandForge.slnx -c Release # must be 0 warnings (warnings are errors) +dotnet run --project src/CommandForge.Wpf +dotnet test CommandForge.slnx +``` + +## Code style + +```bash +dotnet format CommandForge.slnx # apply formatting +dotnet format CommandForge.slnx --verify-no-changes # CI gate +``` + +The build enforces analyzers as errors (`TreatWarningsAsErrors`, `EnforceCodeStyleInBuild`), +including unused-using/unused-member rules. + +## Publish (self-contained) + package + +```bash +# One-step helper (publish + vpk pack): +pwsh ./scripts/pack.ps1 -Version 0.3.0 +``` + +`pack.ps1` runs a self-contained `win-x64` publish (stamping the assembly version so the in-app +version matches the release) and then `vpk pack`. It writes these artifacts to `Releases/`: + +- `CommandForge-win-Setup.exe` — the installer +- `CommandForge--full.nupkg` — full package +- `CommandForge--delta.nupkg` — delta package (only when a previous full is present) +- `releases.win.json` / `RELEASES` — the update manifest read by the app + +The `CommandForge.Elevator` helper is published into the same folder automatically (see the +`PublishElevatorOnPublish` target in `src/CommandForge.Wpf/CommandForge.Wpf.csproj`). + +> No code signing yet — see [SECURITY.md](.github/SECURITY.md). Don't add a signing step until +> Azure Trusted Signing (or SignPath Foundation for OSS) is set up. + +## CI + +- **`build.yml`** — restore + `dotnet format --verify-no-changes` + Release build + tests on every + PR/push to `main` (Windows). +- **`codeql.yml`** — CodeQL C# analysis (Windows, builds `CommandForge.slnx`). +- **`release.yml`** — see [RELEASING.md](RELEASING.md). + +See [UPDATES.md](UPDATES.md) for how auto-update works. diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..15394e2 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,50 @@ +# Releasing CommandForge + +Releases are automated by [`release.yml`](.github/workflows/release.yml), triggered by pushing a +SemVer tag. + +## Steps + +1. Update `docs/Changelog.md` (internal) and make sure `main` is green. +2. Choose a SemVer version `X.Y.Z`. +3. Tag and push: + ```bash + git tag v0.3.0 + git push origin v0.3.0 + ``` +4. The **Release** workflow runs on `windows-latest` and: + - resolves the version from the tag (`vX.Y.Z` → `X.Y.Z`), + - installs `vpk`, + - **downloads the previous release** (`vpk download github`) so a delta can be computed + (skipped/ignored on the very first release), + - publishes self-contained and packages with Velopack (`scripts/pack.ps1`, which stamps the + assembly version), + - **publishes the GitHub Release** with all `Releases/` assets (`vpk upload github --publish`), + - generates **`checksums.txt`** (SHA-256) and attaches it, + - if `VT_API_KEY` is set, submits `Setup.exe` + `*-full.nupkg` to **VirusTotal** and appends the + scan links to the release notes. +5. Edit the GitHub Release notes if needed (changelog highlights). The SHA-256 + VirusTotal info is + already attached. + +You can also run the workflow manually (**Actions → Release → Run workflow**) with a `version` +input; it tags `vX.Y.Z` via the upload step. + +## Required repository secrets + +| Secret | Used for | Required | +|---|---|---| +| `GITHUB_TOKEN` | Create the release & upload assets | automatic | +| `VT_API_KEY` | VirusTotal scan + links | optional (step skipped if unset) | +| `DISCORD_RELEASES_WEBHOOK` (or `DISCORD_REPO_WEBHOOK`) | Release announcement to Discord | optional | +| `DISCORD_PING_ROLE_ID` | Role ping on stable releases | optional | +| `DISCORD_CI_WEBHOOK` | Build-failure alerts to Discord | optional | + +> `poli0981` is a user account (not an org), so secrets are set **per repository** +> (Settings → Secrets and variables → Actions). + +## Code signing + +Not done yet. Releases ship unsigned; users may see a SmartScreen "unknown publisher" warning. +Mitigations: SHA-256 + VirusTotal (above), no obfuscation, public source. When Azure Trusted +Signing (or SignPath Foundation) is configured, add a signing step after `dotnet publish` and +before `vpk pack`, and update [SECURITY.md](.github/SECURITY.md). diff --git a/UPDATES.md b/UPDATES.md new file mode 100644 index 0000000..ae07178 --- /dev/null +++ b/UPDATES.md @@ -0,0 +1,47 @@ +# How updates work (Velopack) + +CommandForge installs and updates itself with [Velopack](https://velopack.io/). Updates are +**per-user** and need **no UAC**. + +## For users + +1. Download `CommandForge-win-Setup.exe` from the + [latest release](https://github.com/poli0981/CommandForge/releases) and run it. It installs + per-user under `%LocalAppData%\CommandForge`. +2. After that, the app checks GitHub Releases for newer versions (on startup if enabled, or via + **Help → Check for updates** / `F5`) and updates itself. When a newer version exists it downloads + the update (a small **delta** when possible) and applies it on restart. + +The only network connection involved is to GitHub (see [PRIVACY.md](PRIVACY.md)). Update errors are +mapped to clear messages: offline, not found (404), rate limited (403/429), and server error (5xx). + +## How it works under the hood + +- The app calls `VelopackApp.Build().Run()` at startup to handle install/update/uninstall hooks. +- It checks for updates via `UpdateManager(new GithubSource("https://github.com/poli0981/CommandForge", null, prerelease: false))`. +- Auto-update only works for an **installed** build (not a dev/portable run); the app detects this + and hides update prompts otherwise. + +## Release artifacts and the delta mechanism + +Each release (see [RELEASING.md](RELEASING.md)) uploads the contents of `Releases/`: + +| Asset | Purpose | +|---|---| +| `CommandForge-win-Setup.exe` | First-time installer | +| `CommandForge--full.nupkg` | Full package (fallback / first install of a version) | +| `CommandForge--delta.nupkg` | Delta from the previous version (small download) | +| `releases.win.json` / `RELEASES` | Update manifest the client reads | +| `checksums.txt` | SHA-256 of the assets (manual verification) | + +**First release (e.g. `v0.3.0`):** there is no previous version, so only a **full** package + +`Setup.exe` + manifest are produced and uploaded. + +**Subsequent releases (e.g. `v0.3.1`):** Velopack needs the **previous** `-full.nupkg` present +while packing to compute the delta. The release workflow does this automatically by running +`vpk download github` before `vpk pack`, so each release after the first produces **both** a +`-full.nupkg` and a `-delta.nupkg`. Clients already on `0.3.0` download only the small +`-delta.nupkg`; the full package remains the fallback. + +> If you ever build a release **locally**, run `vpk download github --repoUrl ` first so the +> prior full package is available for the delta — otherwise only a full package is produced. diff --git a/scripts/pack.ps1 b/scripts/pack.ps1 index b638126..18826d7 100644 --- a/scripts/pack.ps1 +++ b/scripts/pack.ps1 @@ -32,9 +32,13 @@ $publishDir = Join-Path $repoRoot "publish/$Runtime" $wpfProject = Join-Path $repoRoot 'src/CommandForge.Wpf' Write-Host "Publishing CommandForge $Version ($Runtime, $Configuration)..." -ForegroundColor Cyan +# Stamp the assembly version so the in-app "App version" (Settings -> About, Report Bug) matches +# the released package version; otherwise it stays at the 1.0.0 default regardless of the tag. dotnet publish $wpfProject ` -c $Configuration -r $Runtime --self-contained true ` - -p:PublishSingleFile=false -o $publishDir + -p:PublishSingleFile=false ` + -p:Version=$Version -p:InformationalVersion=$Version ` + -o $publishDir # vpk is the Velopack CLI: dotnet tool install -g vpk if (-not (Get-Command vpk -ErrorAction SilentlyContinue)) {