Merge pull request #8 from Dasemu/fix/branch-version-policy

Install PR branch and version policy on development
This commit is contained in:
dasemu authored and GitHub committed 2026-10-13 11:59:46 +02:00
commit bdb91c3d7a
7 files changed
+176 -3

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
name: PR branch and version policy
on:
pull_request_target:
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
branches: [main, development]
permissions:
contents: read
issues: read
jobs:
policy:
name: Branch and version policy
runs-on: ubuntu-latest
steps:
# Run only the trusted base policy. Never execute code from the PR head.
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
persist-credentials: false
- name: Test the trusted policy
run: python3 -m unittest discover -s scripts/tests -v
- name: Check explicit owner approval for a major bump
id: approval
uses: actions/github-script@v7
with:
script: |
const label = 'major-version-approved';
const pr = context.payload.pull_request;
let approved = false;
if (pr.labels.some(item => item.name === label)) {
const events = await github.paginate(github.rest.issues.listEvents, {
...context.repo, issue_number: pr.number, per_page: 100
});
const latest = events.filter(event =>
['labeled', 'unlabeled'].includes(event.event) && event.label?.name === label
).at(-1);
approved = latest?.event === 'labeled' &&
latest.actor?.login === context.repo.owner;
}
core.setOutput('approved', String(approved));
- name: Fetch PR snapshots and validate versions
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
HEAD_BRANCH: ${{ github.event.pull_request.head.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
MAJOR_APPROVED: ${{ steps.approval.outputs.approved }}
run: |
set -euo pipefail
# Public read-only fetch; checkout credentials are not persisted.
git fetch --no-tags origin "$BASE_SHA" "refs/pull/$PR_NUMBER/head"
args=()
if [[ "$MAJOR_APPROVED" == true ]]; then args+=(--major-approved); fi
python3 scripts/check_version_policy.py \
--base-ref "$BASE_SHA" --head-ref "$HEAD_SHA" \
--base-branch "$BASE_BRANCH" --head-branch "$HEAD_BRANCH" "${args[@]}"
+11
View File
@@ -0,0 +1,11 @@
# Repository contribution policy
- Branch new features as `feat/*` and open their PRs against `development`.
- Branch ordinary fixes as `fix/*` and open their PRs against `development`.
- Branch urgent production fixes as `hotfix/*` and open their PRs against `main`.
- Each `feat/*` or `fix/*` PR into `development`, and each `hotfix/*` PR into `main`, increments only the third versionName component: `x.y.(z+1)` relative to its destination.
- A promotion PR from `development` into `main` increments only the second component: `x.(y+1).z`. Do not reset the third component.
- Change the first component only when the repository owner explicitly requests it. Follow the owner-applied approval label procedure in `docs/ANDROID_RELEASES.md`.
- Increase the committed Android versionCode with every PR. Keep versionName changes in the PR for review, alongside the corresponding README version.
- Read `docs/ANDROID_RELEASES.md` for the workflow and run the version policy tests when changing it.
- Do not merge PRs on the owner's behalf unless explicitly asked; the owner reviews and merges them.
+1 -1
View File
@@ -6,7 +6,7 @@ NavFrame is an experimental Android navigation app that renders its own 480×240
The owner has confirmed static and synthetic NavFrame frames on a Xiaomi 11 Lite 5G NE running Android 14 and a 2026 Yamaha MT-07, and the bundled Asturias map working offline on the phone. On 2026-10-12, the owner reported that the latest version displayed the map on the TFT for about 20 minutes, then showed `Mapa no disponible` in La Corredoria (Oviedo) for the rest of the trip while the phone map continued working. An offline map was installed. The exact installed build, diagnostic code and background state were not recorded; the cause is under investigation. This establishes a successful map display followed by a persistent failure, not sustained TFT reliability.
The current checkout is version 0.13.4. The 0.13 series adds voice/routing language selection for Spanish, English, German, French, and Italian, plus a system-language option; unsupported system locales resolve to English. Speech still depends on the Android TextToSpeech engine and its installed voice data. The app includes offline map and place data for Asturias, plus installable regional packages. Worldwide regions can be discovered and built on demand through the [regional package workflow](docs/GLOBAL_OFFLINE.md); this is not complete worldwide coverage. Installed packages currently provide map and local place/camera data. Offline route calculation, global camera completeness, and complete worldwide font coverage are not provided.
The current checkout is version 0.13.5. The 0.13 series adds voice/routing language selection for Spanish, English, German, French, and Italian, plus a system-language option; unsupported system locales resolve to English. Speech still depends on the Android TextToSpeech engine and its installed voice data. The app includes offline map and place data for Asturias, plus installable regional packages. Worldwide regions can be discovered and built on demand through the [regional package workflow](docs/GLOBAL_OFFLINE.md); this is not complete worldwide coverage. Installed packages currently provide map and local place/camera data. Offline route calculation, global camera completeness, and complete worldwide font coverage are not provided.
Route calculation and address search use configurable online services. Spoken output uses the selected language when Android provides voice data; voice availability and offline behavior depend on the device's TextToSpeech engine. Physical validation of route guidance, voice playback, camera alerts, sustained TFT map rendering, and a 30-minute screen-off session remains pending unless a newer test report says otherwise.
+2 -2
View File
@@ -15,8 +15,8 @@ android {
applicationId = "dev.navframe.app"
minSdk = 26
targetSdk = 35
versionName = "0.13.4"
versionCode = 20
versionName = "0.13.5"
versionCode = 21
}
if (hasReleaseSigning) {
signingConfigs.create("production") {
+19
View File
@@ -2,6 +2,25 @@
The Android workflow verifies the debug build, unit tests and lint for pull requests and pushes to `main` or `development`. A manual Actions run is also available. Pull requests never receive production signing secrets or publish releases.
## Pull request routing and version policy
Commit the version change in the PR itself. `PR branch and version policy` checks the proposed `app/build.gradle.kts` against the destination branch snapshot:
| PR source | Destination | Required versionName |
| --- | --- | --- |
| `feat/*` | `development` | `x.y.(z+1)` |
| `fix/*` | `development` | `x.y.(z+1)` |
| `hotfix/*` | `main` | `x.y.(z+1)` |
| `development` | `main` | `x.(y+1).z` |
Features and ordinary fixes must go through `development`; urgent production fixes use `hotfix/*` into `main`. Other source/destination combinations fail. Components not being incremented are preserved: promotion from `0.13.8` requires `0.14.8`, not `0.14.0`. Every PR also increases the committed Android `versionCode`; the production build override remains independent.
The major component only changes on the owner's explicit request. For that exceptional PR, the repository owner must personally apply the `major-version-approved` label; the workflow verifies the most recent label event actor. The expected version then becomes `(x+1).y.z`, while branch routing still applies. Remove the label when the exception is no longer authorized.
The policy uses `pull_request_target` with read-only permissions and executes only the base branch's trusted script. It reads PR version declarations with `git show` without building or executing PR code, and never uses production secrets. The existing Android checks continue using the ordinary `pull_request` event. Enable **Branch and version policy** as a required status check in branch protection/rulesets for both destinations to prevent merging a failed policy check. Install this policy on both branches before relying on it for development PRs. If another PR changes the destination version, update the branch/version and rerun the check before merging.
CI validates the committed bump rather than pushing version commits with privileged tokens. This keeps the exact app version reviewable in the PR and works for fork contributions as well.
## Branch outputs
| Event | Output after checks pass |
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Validate PR routing and committed Android versions without executing PR code."""
import argparse
import re
import subprocess
def version_at(ref):
content = subprocess.check_output(
['git', 'show', f'{ref}:app/build.gradle.kts'], text=True
)
names = re.findall(r'^\s*versionName\s*=\s*"(\d+)\.(\d+)\.(\d+)"\s*$', content, re.M)
codes = re.findall(r'^\s*versionCode\s*=\s*(\d+)\s*$', content, re.M)
if len(names) != 1 or len(codes) != 1:
raise ValueError('Expected one literal x.y.z versionName and one versionCode')
return tuple(map(int, names[0])), int(codes[0])
def validate(base_branch, head_branch, old, new, old_code, new_code, major_approved=False):
if base_branch == 'main' and head_branch == 'development':
expected = (old[0], old[1] + 1, old[2])
elif base_branch == 'main' and head_branch.startswith('hotfix/'):
expected = (old[0], old[1], old[2] + 1)
elif base_branch == 'development' and head_branch.startswith(('feat/', 'fix/')):
expected = (old[0], old[1], old[2] + 1)
else:
raise ValueError('PRs must be feat/* or fix/* -> development, hotfix/* -> main, or development -> main')
if major_approved:
expected = (old[0] + 1, old[1], old[2])
if new != expected:
raise ValueError(f'Expected version {".".join(map(str, expected))}, found {".".join(map(str, new))}')
if new_code <= old_code or not 1 <= new_code <= 2_100_000_000:
raise ValueError('Committed versionCode must increase and remain within Android limits')
def main():
parser = argparse.ArgumentParser(description=__doc__)
for name in ('base-ref', 'head-ref', 'base-branch', 'head-branch'):
parser.add_argument(f'--{name}', required=True)
parser.add_argument('--major-approved', action='store_true')
args = parser.parse_args()
old, old_code = version_at(args.base_ref)
new, new_code = version_at(args.head_ref)
try:
validate(args.base_branch, args.head_branch, old, new, old_code, new_code, args.major_approved)
except ValueError as error:
raise SystemExit(str(error)) from error
print(f'Version policy passed: {old} -> {new}, versionCode {old_code} -> {new_code}')
if __name__ == '__main__':
main()
+35
View File
@@ -0,0 +1,35 @@
import unittest
from scripts.check_version_policy import validate
class VersionPolicyTest(unittest.TestCase):
def test_allowed_transitions(self):
for base, head, new in [('main', 'development', (0, 14, 4)),
('main', 'hotfix/map', (0, 13, 5)),
('development', 'feat/routes', (0, 13, 5)),
('development', 'fix/map', (0, 13, 5))]:
with self.subTest(base=base, head=head):
validate(base, head, (0, 13, 4), new, 20, 21)
def test_reject_invalid_routes_and_versions(self):
for base, head, new, code in [('main', 'feat/routes', (0, 13, 5), 21),
('main', 'fix/map', (0, 13, 5), 21),
('development', 'hotfix/map', (0, 13, 5), 21),
('main', 'other', (0, 13, 5), 21),
('other', 'fix/map', (0, 13, 5), 21),
('main', 'development', (0, 14, 0), 21),
('main', 'hotfix/map', (1, 13, 4), 21),
('development', 'feat/routes', (0, 13, 4), 21),
('main', 'hotfix/map', (0, 13, 5), 20)]:
with self.subTest(base=base, head=head, new=new, code=code):
with self.assertRaises(ValueError):
validate(base, head, (0, 13, 4), new, 20, code)
def test_explicit_major_approval(self):
validate('main', 'hotfix/major', (0, 13, 4), (1, 13, 4), 20, 21, True)
with self.assertRaises(ValueError):
validate('main', 'feat/major', (0, 13, 4), (1, 13, 4), 20, 21, True)
if __name__ == '__main__':
unittest.main()