From b70f49cbef4296dbc06cff4f044a04fdc4205b53 Mon Sep 17 00:00:00 2001 From: apale7 <1092377056@qq.com> Date: Mon, 20 Apr 2026 01:44:27 +0800 Subject: [PATCH] chore(release): automate changelog and assets --- .github/workflows/release-assets.yml | 138 ++++++++++++++++++++++++++ .github/workflows/release-please.yml | 22 ++++ .github/workflows/release-precheck.md | 15 +++ .release-please-manifest.json | 3 + release-please-config.json | 9 ++ 5 files changed, 187 insertions(+) create mode 100644 .github/workflows/release-assets.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .github/workflows/release-precheck.md create mode 100644 .release-please-manifest.json create mode 100644 release-please-config.json diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml new file mode 100644 index 0000000..2ac8ef4 --- /dev/null +++ b/.github/workflows/release-assets.yml @@ -0,0 +1,138 @@ +name: release-assets + +on: + release: + types: + - published + +permissions: + contents: write + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - name: windows + runs-on: windows-latest + artifact_name: ocswitch-desktop-windows-amd64 + package: release/ocswitch-desktop-windows-amd64.zip + output: build/bin/ocswitch-desktop.exe + - name: macos + runs-on: macos-13 + artifact_name: ocswitch-desktop-darwin-amd64 + package: release/ocswitch-desktop-darwin-amd64.zip + output: build/bin/ocswitch-desktop.app + - name: linux + runs-on: ubuntu-22.04 + artifact_name: ocswitch-desktop-linux-amd64 + package: release/ocswitch-desktop-linux-amd64.zip + output: build/bin/ocswitch-desktop + + runs-on: ${{ matrix.runs-on }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install frontend deps + working-directory: frontend + run: npm install + + - name: Install Wails CLI + run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.12.0 + + - name: Install Linux deps + if: runner.os == 'Linux' + run: sudo apt-get update && sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev build-essential pkg-config + + - name: Verify Wails output name + shell: bash + env: + EXPECTED_OUTPUT: ${{ matrix.output }} + run: | + python - <<'PY' + import os + import pathlib + + expected = pathlib.Path(os.environ["EXPECTED_OUTPUT"]) + print(f"expected output: {expected.as_posix()}") + PY + + - name: Build desktop app + run: wails build -tags desktop_wails + + - name: Package artifact + shell: bash + env: + SOURCE_PATH: ${{ matrix.output }} + DEST_PATH: ${{ matrix.package }} + run: | + mkdir -p release + python - <<'PY' + import hashlib + import os + import pathlib + import zipfile + + source = pathlib.Path(os.environ["SOURCE_PATH"]) + dest = pathlib.Path(os.environ["DEST_PATH"]) + dest.parent.mkdir(parents=True, exist_ok=True) + + with zipfile.ZipFile(dest, "w", compression=zipfile.ZIP_DEFLATED) as zf: + if source.is_dir(): + for path in source.rglob("*"): + if path.is_file(): + zf.write(path, arcname=f"{source.name}/{path.relative_to(source).as_posix()}") + else: + zf.write(source, arcname=source.name) + + digest = hashlib.sha256(dest.read_bytes()).hexdigest() + dest.with_suffix(dest.suffix + ".sha256").write_text(f"{digest} {dest.name}\n", encoding="ascii") + PY + + - name: List packaged files + shell: bash + run: | + python - <<'PY' + import pathlib + + for path in sorted(pathlib.Path("release").glob("**/*")): + if path.is_file(): + print(path.as_posix()) + PY + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.artifact_name }} + path: | + ${{ matrix.package }} + ${{ matrix.package }}.sha256 + + publish: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: release-assets + merge-multiple: true + + - name: Publish GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: release-assets/** diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..0ada13e --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,22 @@ +name: release-please + +on: + push: + branches: + - master + +permissions: + contents: write + pull-requests: write + +jobs: + release-please: + runs-on: ubuntu-latest + + steps: + - name: Release Please + uses: googleapis/release-please-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + config-file: release-please-config.json + manifest-file: .release-please-manifest.json diff --git a/.github/workflows/release-precheck.md b/.github/workflows/release-precheck.md new file mode 100644 index 0000000..8c22a81 --- /dev/null +++ b/.github/workflows/release-precheck.md @@ -0,0 +1,15 @@ +# Release Workflow Precheck + +1. Confirm release-please is enabled on `master`. +2. Confirm conventional commits are used for release notes grouping. +3. Confirm `release-please-config.json` targets the repo root and `CHANGELOG.md`. +4. Confirm Wails output name matches `wails.json`: + - `build/bin/ocswitch-desktop.exe` on Windows + - `build/bin/ocswitch-desktop.app` on macOS + - `build/bin/ocswitch-desktop` on Linux +5. Confirm Linux runner has the GTK/WebKit packages needed by Wails. +6. Confirm `npm install` is sufficient for frontend build in CI. +7. Confirm release assets are uploaded only after the GitHub Release is published. +8. Confirm each asset has a matching `.sha256` file. +9. Confirm tag format is `v*`. +10. Confirm the generated release contains the three platform archives. diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..e18ee07 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.0" +} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..d417228 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "packages": { + ".": { + "release-type": "go", + "changelog-path": "CHANGELOG.md" + } + } +}