Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/scripts/fork-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
# Decides whether a sync PR (branch sync/vX, opened by the dojo's keeper agent) can be merged without
# a person, and if so merges it and starts the release. Clean means:
# - the CI passed on the PR's latest commit;
# - the upstream tag merges into main without conflicts (git merge-tree);
# - what the agent changed on top of that clean merge stays inside ALLOWED_FILES, or inside
# LINE_RULES files on lines matching their regex (versions, translation entries).
# Anything else gets the needs-review label and a comment, and waits for the owner.
# Configured by the calling workflow: UPSTREAM, ALLOWED_FILES, LINE_RULES, VERSION_FILE,
# VERSION_PATTERN, RELEASE_WORKFLOW, RELEASE_INPUTS, plus BRANCH, HEAD_SHA, CONCLUSION.
set -euo pipefail

tag=${BRANCH#sync/}
pr=$(gh pr list --head "$BRANCH" --state open --json number,headRefOid,labels \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lookup selects the first open PR with this branch name, but the checks below validate origin/$BRANCH rather than that PR's actual head. A fork PR named sync/v… can therefore be merged with its arbitrary changes while the script checks a different, trusted branch; the privileged workflow then starts a release.

Technical details
# Bind sync validation to the PR being merged

## Affected sites
- `.github/scripts/fork-sync.sh:14-20` — selects a PR by branch name and records its head SHA without verifying its head repository or base.
- `.github/scripts/fork-sync.sh:42-74` — validates `origin/$BRANCH` and compares its changes to the allowlist, not the selected PR's head.
- `.github/scripts/fork-sync.sh:76` — merges the selected PR with the privileged token.
- `.github/workflows/fork-sync.yml:12-16, 24` — grants write permissions and invokes this path for branch names matching `sync/v`.
- `.github/scripts/fork-sync.sh:80-84` — dispatches the release with `publish=true` after merge.

## Required outcome
- Ensure the exact PR head repository, SHA, base branch, and tree checked by the allowlist are the same head that is merged; do not auto-merge an untrusted fork PR based only on a colliding branch name.

--jq '.[0] | select(.) | "\(.number) \(.headRefOid) \([.labels[].name] | join(","))"')
if [[ -z $pr ]]; then
echo "No open PR for $BRANCH."
exit 0
fi
read -r num head labels <<<"$pr"
if [[ ,$labels, == *,needs-review,* ]]; then
echo "PR #$num is waiting for a review: nothing to do."
exit 0
fi
if [[ $head != "$HEAD_SHA" ]]; then
echo "The CI ran on $HEAD_SHA, the PR is at $head: the next CI run decides."
exit 0
fi
if [[ $CONCLUSION != success ]]; then
echo "CI $CONCLUSION on PR #$num: the agent or the owner fixes it, the next green run decides."
exit 0
fi

review() {
gh label create needs-review --color D93F0B --description "Sync PR that needs a person" 2>/dev/null || true
gh pr edit "$num" --add-label needs-review
gh pr comment "$num" --body "Fork sync: not merged automatically. $1"
echo "$1"
exit 0
}

git fetch -q origin main "$BRANCH"
git fetch -q --no-tags "https://github.com/$UPSTREAM.git" "refs/tags/$tag:refs/tags/$tag"
head_ref=origin/$BRANCH

git merge-base --is-ancestor "$tag" "$head_ref" || review "The branch does not contain upstream \`$tag\`."
if ! git merge-base --is-ancestor origin/main "$head_ref"; then
gh pr comment "$num" --body "Fork sync: \`main\` moved after this branch was created. Merge \`main\` into it; the next green CI decides."
exit 0
fi
if ! out=$(git merge-tree --write-tree origin/main "$tag"); then
review "Upstream \`$tag\` conflicts with \`main\`: the agent resolved code by hand."
fi
clean=$(head -1 <<<"$out")

declare -A rules=()
while IFS= read -r line; do
[[ -n $line ]] || continue
rules[${line%% :: *}]=${line#* :: }
done <<<"$LINE_RULES"

while IFS= read -r file; do
[[ -n $file ]] || continue
if grep -qxF -- "$file" <<<"$ALLOWED_FILES"; then
continue
fi
if [[ -n ${rules[$file]:-} ]]; then
other=$(git diff -U0 "$clean" "$head_ref" -- "$file" | grep -E '^[+-]' | grep -Ev '^(\+\+\+|---) ' | cut -c2- |
grep -Evx -- "${rules[$file]}" || true)
[[ -z $other ]] || review "\`$file\` changes lines other than the allowed ones:"$'\n\n```\n'"$other"$'\n```'
continue
fi
review "\`$file\` is not among the files the agent may change on its own."
done < <(git diff --name-only "$clean" "$head_ref")

gh pr merge "$num" --merge --match-head-commit "$HEAD_SHA"
git fetch -q origin main
version=$(git show "origin/main:$VERSION_FILE" | perl -ne 'if (/$ENV{VERSION_PATTERN}/) { print $1; exit }')
[[ -n $version ]] || { echo "Version not found in $VERSION_FILE" >&2; exit 1; }
args=()
while IFS= read -r input; do
[[ -n $input ]] && args+=(-f "${input//\{version\}/$version}")
done <<<"$RELEASE_INPUTS"
gh workflow run "$RELEASE_WORKFLOW" --ref main "${args[@]}"
echo "Merged PR #$num and started the $version release."
56 changes: 56 additions & 0 deletions .github/workflows/fork-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Fork sync

# This repo is a fork of lippdev/consolemode (see FORK.md). The dojo's keeper agent opens a PR from
# sync/vX when upstream publishes vX. When the CI of that PR finishes, this decides with fixed rules,
# no AI: a clean sync is merged and released (Release workflow, "publish" ticked); anything else
# gets the needs-review label and waits for the owner. The rules live in .github/scripts/fork-sync.sh.
on:
workflow_run:
workflows: [CI]
types: [completed]

permissions:
contents: write
pull-requests: write
# Starts the Release workflow.
actions: write

concurrency:
group: fork-sync
cancel-in-progress: false

jobs:
merge:
if: github.event.workflow_run.event == 'pull_request' && startsWith(github.event.workflow_run.head_branch, 'sync/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0

- name: Merge and release a clean sync
env:
GH_TOKEN: ${{ github.token }}
BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
CONCLUSION: ${{ github.event.workflow_run.conclusion }}
UPSTREAM: lippdev/consolemode
# What the agent may change on top of the clean merge: the Italian catalog and docs, and the
# changelogs the release reads its notes from.
ALLOWED_FILES: |
src/ConsoleMode/Resources/Strings.it-IT.json
README.it-IT.md
CHANGELOG.md
CHANGELOG.en-US.md
# file :: regex every changed line of that file must match (whole line).
LINE_RULES: |
src/ConsoleMode/ConsoleMode.csproj :: \s*<(Version|AssemblyVersion|FileVersion|InformationalVersion)>[0-9.]+</\1>\s*
VERSION_FILE: src/ConsoleMode/ConsoleMode.csproj
VERSION_PATTERN: <Version>([^<]+)</Version>
RELEASE_WORKFLOW: release.yml
RELEASE_INPUTS: |
version={version}
publish=true
run: .github/scripts/fork-sync.sh
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ jobs:
""
"---"
""
"🇧🇷 Notas em português: [CHANGELOG.md](https://github.com/lippdev/consolemode/blob/$tag/CHANGELOG.md)"
"🇧🇷 Notas em português: [CHANGELOG.md](https://github.com/1r0n51uv/consolemode/blob/$tag/CHANGELOG.md)"
)
if ($summaries.Count -gt 0) { $releaseNotes += @("") + $summaries }
$releaseNotes = $releaseNotes -join "`n"
Expand Down
5 changes: 2 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ Xbox mode, and restores the desk setup afterwards.
## Conventions

- **Every user-facing string** goes in every catalog in `src/ConsoleMode/Resources/`
(`Strings.pt-BR.json`, `en-US`, `es-ES`, `de-DE`, `fr-FR`, `ru-RU`), translated.
(`Strings.pt-BR.json`, `en-US`, `it-IT`), translated.
The localization tests fail when keys or `{0}` placeholders don't match, or when a sentence
is left in English.
- **Changelog**: add user-visible changes under `## [Unreleased]` in both
`CHANGELOG.md` (Portuguese) and `CHANGELOG.en-US.md`, ending the item with the PR number.
- **Docs come in pairs**: `README.md` / `README.pt-BR.md`, `docs/GUIDE.md` / `docs/GUIDE.pt-BR.md`.
The `README.<code>.md` and `docs/GUIDE.<code>.md` translations (es-ES, de-DE, fr-FR, ru-RU) are leaner
(no version numbers, "What's new" or roadmap): update them too when you change a section they carry.
`README.it-IT.md` is leaner (no version numbers, "What's new" or roadmap): update it too when you change a section it carries.
Adding a language: follow `docs/TRANSLATING.md`.
- **Commits and PR titles**: Conventional Commits in English (`fix: …`, `feat: …`, `docs: …`),
one topic per PR. `AppLog` messages are written in Portuguese, like the existing ones.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
English (US) release notes, mirroring CHANGELOG.md (Brazilian Portuguese). Before publishing a version, add a `## [VERSION]` section to **both** files: the workflow publishes the section matching the tag from each one and fails if either is missing.

## [Unreleased]
### Changes
- Lean edition: removed TV control (Google TV / Android TV), the FPS limit and counter (RTSS), per-game profiles, the local control API and `consolemode://` links, DDC/CI panel power-off, and the Spanish, German, French and Russian languages.

## [1.7.2]
### What's new
- Italian language: the app and the installer are now available in Italian.

## [1.7.1]
### What's new
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Notas em português do Brasil; a versão em inglês (Estados Unidos) fica em `CHANGELOG.en-US.md`. Antes de publicar uma versão, adicione uma seção `## [VERSÃO]` com o changelog daquela versão **nos dois arquivos**. O workflow publica as duas seções correspondentes à tag na mesma release e falha se faltar alguma.

## [Unreleased]
### Mudanças
- Edição enxuta: removidos o controle da TV (Google TV / Android TV), o limite e o contador de FPS (RTSS), os perfis por jogo, a API de controle local e os links `consolemode://`, o desligar por DDC/CI e os idiomas espanhol, alemão, francês e russo.

## [1.7.2]
### Novidades
- Idioma italiano: o app e o instalador agora estão disponíveis em italiano.

## [1.7.1]
### Novidades
Expand Down
42 changes: 42 additions & 0 deletions FORK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Fork notes

This is a fork of [lippdev/consolemode](https://github.com/lippdev/consolemode). The dojo's
`keeper` agent (see `1r0n51uv/ron1n-dojo`, FLOW-013) reads this file every time upstream publishes a
release, merges it here and opens a PR from `sync/vX`. Keep it current: it is what the agent knows
about what we changed.

## Lean edition (branch `alt/lean`)

This branch deliberately diverges from upstream and is **not** part of the keeper's sync flow. It removes
TV control, RTSS (FPS limit and counter), per-game profiles, the local control API, `consolemode://` links,
DDC/CI power-off and the es/de/fr/ru catalogs, and is meant to be redesigned further. Merging upstream into it
will conflict heavily; do it by hand, not with the keeper.

## What we changed

- **Italian**: `src/ConsoleMode/Resources/Strings.it-IT.json` (a catalog with every key of
`Strings.en-US.json`), its wiring (`ConsoleMode.csproj`, `Tests.csproj`, `LocalizationService.cs`,
`LocalizationTests.cs`, `build/ConsoleMode.iss`), `README.it-IT.md`, the language line of the other
READMEs, `docs/TESTING.md` and `docs/TRANSLATING.md`.
- **Updates and links point at the fork**: `UpdateService.Repository`, the changelog link in
`release.yml`, the installer URLs in `build/ConsoleMode.iss`. Never take upstream's value here.
- **Fork automation**: `.github/workflows/fork-sync.yml`, `.github/scripts/fork-sync.sh`, this file.
`winget.yml`/`release.yml`'s winget job stay off (no `WINGET_TOKEN`).

## Rules for a sync

1. Branch `sync/v<upstream version>` from `main`, then merge the upstream **tag** (`git merge v<X>`),
never a squash: the history must keep upstream's commits.
2. On a conflict, keep upstream's code and re-apply our changes above on top.
3. Every key upstream added to `Strings.en-US.json` goes into `Strings.it-IT.json`, translated
(the localization tests fail on a missing key, a wrong `{0}` or an untranslated sentence). Run
`dotnet test tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj` (in a `mcr.microsoft.com/dotnet/sdk:8.0`
container when `dotnet` is missing).
4. **Version**: the fork's version is the higher of upstream's and ours; if ours is higher or equal,
ours +1 patch. Set it in `src/ConsoleMode/ConsoleMode.csproj`: `Version`, `AssemblyVersion`,
`FileVersion` and `InformationalVersion`.
5. **Changelog**: a `## [<version>]` section in **both** `CHANGELOG.md` (Portuguese) and
`CHANGELOG.en-US.md`; the release fails without them. Keep upstream's sections, add ours on top.
6. Anything beyond the Italian catalog, `README.it-IT.md`, the changelogs and the version lines
makes the PR "not clean": it waits for the owner (`needs-review`).
7. Never push to `main`, never merge: `fork-sync.yml` decides, with fixed rules, after the CI is green.
67 changes: 0 additions & 67 deletions README.de-DE.md

This file was deleted.

Loading