From 92e7dd5d00aceee55216d006222a2e60d6955593 Mon Sep 17 00:00:00 2001 From: Compot Developer Date: Sat, 17 Oct 2026 20:18:02 +0000 Subject: [PATCH] ci: a code change must come with a new version (#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .github/check-version.sh, the script of OpenIPC/vectis with camex's version macro and paths: a pull request that changes src/, android/, the Makefile, ci/ or scripts/ must raise CAMEX_VERSION (MAJOR.MINOR.PATCH without leading zeros, greater than the base) and add its new '## X.Y.Z — YYYY-MM-DD' section to CHANGELOG.md. Docs, tests, screenshots and .github/ need no new version. The "Version bump" job runs it on every pull request. READMEs: a "When to bump" section with the rule. --- .github/check-version.sh | 65 +++++++++++++++++++++++++++++++++++++ .github/workflows/build.yml | 19 +++++++++++ README.md | 16 +++++++++ README.ru.md | 16 +++++++++ README.zh-CN.md | 14 ++++++++ 5 files changed, 130 insertions(+) create mode 100755 .github/check-version.sh diff --git a/.github/check-version.sh b/.github/check-version.sh new file mode 100755 index 0000000..8e3e9bb --- /dev/null +++ b/.github/check-version.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# +# Copyright (c) OpenIPC https://openipc.org MIT License +# +# check-version.sh — fail a pull request that changes code or the build +# but not CAMEX_VERSION in src/version.h (#63). The new version must be +# MAJOR.MINOR.PATCH without leading zeros, greater than the base one, +# and have its section in CHANGELOG.md ("## — "). +# src/, android/, the Makefile, ci/ and scripts/ count as code or build; +# docs, tests, screenshots and the workflows in .github/ do not need a new +# version. Same script as OpenIPC/vectis, other paths and version macro. +# +# Usage: .github/check-version.sh [BASE] (default origin/master) +# + +set -eu + +base=${1:-origin/master} +code="src android Makefile ci scripts" + +ver() { sed -n 's/^#define CAMEX_VERSION *"\(.*\)"/\1/p'; } + +new=$(ver < src/version.h) +old=$(git show "$base:src/version.h" | ver) + +if ! echo "$new" | grep -Eq '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'; then + echo "::error::CAMEX_VERSION \"$new\" is not MAJOR.MINOR.PATCH" + exit 1 +fi + +# shellcheck disable=SC2086 # $code is a list of paths +changed=$(git diff --name-only "$base"...HEAD -- $code) + +if [ "$new" = "$old" ]; then + if [ -n "$changed" ]; then + echo "::error::code or build changed, CAMEX_VERSION is still $old:" \ + "bump PATCH (fix) or MINOR (feature) and add its CHANGELOG.md section" + echo "$changed" + exit 1 + fi + echo "version $new unchanged, no code or build changes" + exit 0 +fi + +top=$(printf '%s\n%s\n' "$old" "$new" | sort -V | tail -n 1) +if [ "$top" != "$new" ]; then + echo "::error::CAMEX_VERSION $new is not greater than $old" + exit 1 +fi + +# $new is digits and dots only (checked above): escape the dots, require a date. +re=$(printf '%s' "$new" | sed 's/\./\\./g') +if ! grep -Eq "^## $re — [0-9]{4}-[0-9]{2}-[0-9]{2}\$" CHANGELOG.md; then + echo "::error::CHANGELOG.md has no section \"## $new — YYYY-MM-DD\"" + exit 1 +fi + +# The section must come with this pull request, not be one the base +# branch already has (a version taken from there brings no notes). +if git show "$base:CHANGELOG.md" 2>/dev/null | grep -Eq "^## $re — "; then + echo "::error::the section \"## $new\" is already on $base: take a new version" + exit 1 +fi + +echo "version $old -> $new, CHANGELOG.md section found" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4016f37..db7146c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,6 +34,25 @@ env: # actions target Node 24 natively (checkout@v5, upload-artifact@v5, download-artifact@v5, gh-release@v3) jobs: + # ---------------------------------------------------------------- version + # Pull requests: a change to the code or the build comes with a new + # CAMEX_VERSION (MAJOR.MINOR.PATCH) and its CHANGELOG.md section (#63) + version: + name: Version bump + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Code changes come with a new version + env: + # through the environment, not pasted into the script + BASE: ${{ github.base_ref }} + run: .github/check-version.sh "origin/$BASE" + # ------------------------------------------------------------------ linux linux: name: Linux ${{ matrix.target }} (musl static) diff --git a/README.md b/README.md index 7a36f72..4b4ccc7 100644 --- a/README.md +++ b/README.md @@ -749,6 +749,22 @@ The Android `versionName` and `versionCode` follow it: `scripts/sync-android-ver (or `make apk`, which calls it) updates `android/app/build.gradle.kts` and `android/app/src/main/AndroidManifest.xml`. +### When to bump + +`CAMEX_VERSION` is `MAJOR.MINOR.PATCH`, numbers without leading zeros: + +- **PATCH** — fixes and small changes; **MINOR** — a new feature (option, config field, + protocol, platform); **MAJOR** — an incompatible change (arguments, config format, + protocol, default behaviour), only when the maintainer decides. +- A pull request that changes the code or the build (`src/`, `android/`, `Makefile`, + `ci/`, `scripts/`) bumps the version as its last commit before the merge and adds + its `## X.Y.Z — YYYY-MM-DD` section to `CHANGELOG.md`. Pull requests with only docs, + tests, screenshots or workflows in `.github/` do not. +- CI checks this on every pull request (`.github/check-version.sh`, job "Version + bump"): the new version must be well-formed, greater than the one on `master` and + have its new `CHANGELOG.md` section. Until the bump commit is pushed, the check is + red by design. + ### Release process There are no version tags and no versioned releases: one release, `latest`, is diff --git a/README.ru.md b/README.ru.md index fe33ce7..5f42a4c 100644 --- a/README.ru.md +++ b/README.ru.md @@ -755,6 +755,22 @@ sudo rmmod camex (или `make apk`, который его вызывает) обновляет `android/app/build.gradle.kts` и `android/app/src/main/AndroidManifest.xml`. +### Когда поднимать версию + +`CAMEX_VERSION` — `MAJOR.MINOR.PATCH`, числа без ведущих нулей: + +- **PATCH** — исправления и мелкие правки; **MINOR** — новая возможность (опция, поле + конфигурации, протокол, платформа); **MAJOR** — несовместимое изменение (аргументы, + формат конфигурации, протокол, поведение по умолчанию), только по решению мейнтейнера. +- Pull request, который меняет код или сборку (`src/`, `android/`, `Makefile`, `ci/`, + `scripts/`), последним коммитом перед мержем поднимает версию и добавляет в + `CHANGELOG.md` её раздел `## X.Y.Z — YYYY-MM-DD`. Pull request только с документацией, + тестами, скриншотами или workflow в `.github/` версию не поднимает. +- CI проверяет это в каждом pull request (`.github/check-version.sh`, job «Version + bump»): новая версия должна быть правильного вида, больше версии в `master` и иметь + новый раздел в `CHANGELOG.md`. Пока коммит с версией не запушен, проверка красная — + так и задумано. + ### Процесс релиза Тегов версий и релизов по версиям нет: один релиз, `latest`, CI заменяет после diff --git a/README.zh-CN.md b/README.zh-CN.md index 34aa265..f6082f4 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -726,6 +726,20 @@ Android 的 `versionName` 和 `versionCode` 随之变化:`scripts/sync-android (或调用它的 `make apk`)会更新 `android/app/build.gradle.kts` 和 `android/app/src/main/AndroidManifest.xml`。 +### 何时提升版本号 + +`CAMEX_VERSION` 为 `MAJOR.MINOR.PATCH`,各数字不带前导零: + +- **PATCH** —— 修复和小改动;**MINOR** —— 新功能(选项、配置字段、协议、平台); + **MAJOR** —— 不兼容的变更(参数、配置格式、协议、默认行为),仅由维护者决定。 +- 修改代码或构建(`src/`、`android/`、`Makefile`、`ci/`、`scripts/`)的 pull request, + 在合并前的最后一个提交中提升版本号,并在 `CHANGELOG.md` 中添加 + `## X.Y.Z — YYYY-MM-DD` 章节。只涉及文档、测试、截图或 `.github/` 中工作流的 + pull request 不提升版本号。 +- CI 会在每个 pull request 中检查这一点(`.github/check-version.sh`,job + “Version bump”):新版本号格式必须正确、大于 `master` 上的版本,并带有新的 + `CHANGELOG.md` 章节。在推送提升版本号的提交之前,该检查为红色,这是预期行为。 + ### 发布流程 没有版本标签,也没有按版本的发布:只有一个发布 `latest`,每次推送到 `master`