Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ means a chain: run the steps in order, or one step calls the next. `Test+` marks
| Name in Actions | File | When it runs | What it changes |
|---|---|---|---|
| App+Play: 1. send candidate to Play Console | `app-play-1-candidate.yml` | Manual, from `main` | Sends the Play AAB to Google review, tags `vX.Y.Z-rc.N`, archives the AAB to R2 |
| App+Play: 2. publish release | `app-play-2-release.yml` | Manual, after Google approves the candidate | Final AAB to the Play beta track, final tag, GitHub Release, website APKs on R2, OTA `update.json` |
| App+Play: 2. publish release | `app-play-2-release.yml` | Manual, after Google approves the candidate | Final AAB to the Play beta track, final tag, GitHub Release, website APKs on R2, OTA `update.json`; then calls `app-fdroid-repo.yml` |
| App: publish F-Droid repo | `app-fdroid-repo.yml` | Called by App+Play step 2; manual (staging by default) | F-Droid repo on R2: `fdroid/` (live) or `fdroid-staging/` |
| App: Firebase distribution | `app-firebase.yml` | Each push to `main` or to a branch with a ticket key | Tester build on Firebase |
| Bins: 1. build static (PRoot) | `bins-1-build.yml` | Weekly (Sunday) and manual | New `binaries-*` release; then calls step 2 |
| Bins: 2. archive + retention | `bins-2-archive.yml` | Called by step 1, or manual (dry run option) | Archives binaries to R2, prunes old releases |
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/app-fdroid-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "App: publish F-Droid repo"

# K2GO-421: the self-hosted F-Droid repository on R2 (k2go-apk-repo, prefix fdroid/).
# Design: controller/docs/ADR-K2GO-421-self-hosted-fdroid-repo.md. Tool: tools/fdroid-repo/.
#
# - Called by "App+Play: 2. publish release" after the release APKs are on R2 (staging false).
# - Manual: publish a release that is on R2 already. Staging (default) writes fdroid-staging/,
# a separate repo with its own URL, so the live repo does not change.
# The repo index is signed with the app signing key (the same secrets as the APK).

on:
workflow_call:
inputs:
tag:
type: string
required: true
staging:
type: boolean
default: false
workflow_dispatch:
inputs:
tag:
description: "Release tag whose fdroid APK is on R2, for example v1.2.0"
required: true
staging:
description: "Publish to fdroid-staging/ instead of the live fdroid/"
type: boolean
default: true

permissions:
contents: read

jobs:
publish:
name: Publish the F-Droid repository
runs-on: ubuntu-latest
# Two runs at once would race on the same index.
concurrency:
group: fdroid-repo
cancel-in-progress: false
env:
TAG: ${{ inputs.tag }}
PREFIX: ${{ inputs.staging && 'fdroid-staging' || 'fdroid' }}
BASE_URL: https://k2go-download.appdevforall.org
BUCKET_NAME: k2go-apk-repo
steps:
- name: Checkout Code
uses: actions/checkout@v5

- name: Require a release tag
run: |
if ! printf '%s' "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::'$TAG' is not a release tag (vX.Y.Z). Release candidates do not go to the F-Droid repo."
exit 1
fi

- name: Unit tests (fdroid-repo)
working-directory: tools/fdroid-repo
run: python3 -m unittest -v test_fdroid_repo

- name: Decode Keystore
env:
ENCODED_STRING: ${{ secrets.KEYSTORE_BASE64 }}
run: echo "$ENCODED_STRING" | base64 -d > "$RUNNER_TEMP/keystore.jks"

- name: Publish
env:
AWS_ACCESS_KEY_ID: ${{ vars.CLOUDFLARE_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: auto
R2_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
KEYSTORE_FILE: ${{ runner.temp }}/keystore.jks
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
WORK: ${{ runner.temp }}/fdroid-work
run: bash tools/fdroid-repo/publish.sh

- name: Cleanup Keystore
if: always()
run: rm -rf "$RUNNER_TEMP/keystore.jks" "$RUNNER_TEMP/fdroid-work/keystore.jks"
14 changes: 13 additions & 1 deletion .github/workflows/app-play-2-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: "App+Play: 2. publish release"
# Run this from main after Google approved a candidate and main says versionName "vX.Y.Z" (the final
# commit: same code, only the version line changed). It sends the final AAB to the Play beta track
# (Open testing), and only when Play accepts the upload it tags the commit and runs the release build:
# GitHub Release, website APKs, R2 and the OTA update.json. An rc build is never released as final
# GitHub Release, website APKs, R2, the OTA update.json and the F-Droid repo (K2GO-421). An rc build is never released as final
# (check-release). Google gives its verdict by email and in Play Console (the API cannot read it).

on:
Expand Down Expand Up @@ -387,3 +387,15 @@ jobs:
- name: Cleanup Keystore
if: always()
run: rm -f keystore.jks

# K2GO-421: the self-hosted F-Droid repository, from the fdroid APK that the release job put on R2.
fdroid-repo:
name: F-Droid repository
needs: [tag, release]
permissions:
contents: read
uses: ./.github/workflows/app-fdroid-repo.yml
with:
tag: ${{ needs.tag.outputs.tag }}
staging: false
secrets: inherit
108 changes: 108 additions & 0 deletions controller/docs/ADR-K2GO-421-self-hosted-fdroid-repo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# ADR-K2GO-421 : Self-hosted F-Droid repository

- Status: Accepted (decisions of the maintainer, 2026-11-21)
- Date: 2026-09-24 (draft), 2026-11-21 (decisions and implementation)
- Ticket: K2GO-421 (relates to K2GO-399, "Acceptable to F-Droid?")
- Author: AppDevForAll

## Decision in one line

Publish a fdroidserver-generated F-Droid repository of the `fdroid` flavor on the Cloudflare R2
bucket `k2go-apk-repo` under the prefix `fdroid/`, signed with the app signing key, as an update
channel that we control while the official f-droid.org inclusion (K2GO-399) goes on in parallel.

## Context (facts, verified 2026-11-21)

- The release job of `app-play-2-release.yml` builds `standard` and `fdroid` and uploads both
APKs to the root of `k2go-apk-repo` (`K2Go-<tag>-release.apk`, `K2Go-<tag>-fdroid-release.apk`).
Public host: `https://k2go-download.appdevforall.org`.
- The `fdroid` flavor has no Firebase and no in-app OTA updater. Crash reports (GlitchTip) start
only after the user turns them on (`CrashReportConsent`, default off, K2GO-579).
- The `standard` APK and the `fdroid` APK have the same signer (apksigner, v1.2.0):
`3a11e9f345e8b4ef79ccb8c819ca0d5392dd8f3febe26abb089c5e2e022fefb5`. A website install and a
repository install can update each other. A Play install cannot: Google signs it with another key.
- An F-Droid repository is static files. The client reads `repo/entry.jar`, then the index that
entry.jar names with its SHA-256 (`index-v2.json`, or `index-v1.jar` for old clients), then
APKs and icons at fixed paths. It never asks for a directory listing. So R2 is sufficient.
- R2 has no directory listing and no implicit `index.html`. Only a person in a browser needs one.
A generated landing page closes that gap, the same as the add-ons gallery
(`appdevforall/plugin-examples`, `tools/addons`).
- Without the previous index, `fdroid update` sets the "added" date of every old version to the
date of the run (tested with fdroidserver 2.4.2).
- `static/` is not a public web root (box nginx, LAN only). It is not used here.

## Decisions

- D1. URL. Bucket `k2go-apk-repo`, prefix `fdroid/`:
repository `https://k2go-download.appdevforall.org/fdroid/repo`, landing page
`https://k2go-download.appdevforall.org/fdroid/index.html`. Manual test runs write
`fdroid-staging/`, a separate repository with its own URL.
The QR code of fdroidserver holds the repository address (`.../fdroid/repo?fingerprint=...`).
The F-Droid app reads it, but a phone camera opens it in a browser, and R2 has no object at that
key. So the landing page is also uploaded at the key `fdroid/repo` (no slash). R2 keys are flat:
that key and the `fdroid/repo/...` keys exist side by side, and the F-Droid app never asks for it.
The "Add to F-Droid" button and the QR code on the landing page use
`https://fdroid.link/#<repo address>?fingerprint=<fingerprint>`. The F-Droid app claims
`fdroid.link` as a verified App Link, so Android opens the app directly. Without the app, the
browser shows fdroid.link. The repo address is in the fragment: the browser does not send it to
fdroid.link. (The app claims `fdroidrepos://` for HTTPS repos, but no longer `fdroidrepo://` for
HTTP repos, so a scheme link fails in a local HTTP test.)
- D2. Flavor. The repository ships the `fdroid` flavor. The F-Droid client does the updates, and
this flavor has no in-app updater, so two updaters never compete. (The draft said `standard`.)
- D3. One key. The repository index is signed with the app signing key: the same keystore and the
same GitHub secrets (`KEYSTORE_BASE64`, `KEY_ALIAS`, `KEYSTORE_PASSWORD`, `KEY_PASSWORD`). The
repository fingerprint is then the fingerprint of the app certificate: one fingerprint to check.
- Consequence: a change of this key changes the repository fingerprint. Each user must then
remove the repository and add it again with the new fingerprint. The config change is one line.
- The run checks that the release APK is signed by the key that signs the index, so an APK
signed by another key is never published.
- D4. R2 holds the state. CI keeps nothing between runs. Each run pulls `fdroid/repo/` and
`fdroid/archive/` (indexes and APKs), adds the release APK, runs `fdroid update`, and uploads.
The localized images (`repo/<app id>/`) are not pulled: they come from `metadata/` on each run.
- D5. Upload order. APKs and images, then the indexes, then `entry.jar`, then the landing page.
Deletions come last. The same rule as `update.json` (ADFA-4984): a published file never names a
file that is not in R2 yet. Before the upload, the run also checks that each file that the new
index names is in the upload.
- D6. History. `archive_older: 3`: the three newest versions in `repo/`, older ones in `archive/`
(also published).
- D7. Cache. `Cache-Control: public, max-age=60` on indexes, `entry.jar` and pages;
one year, immutable, on APKs (the name carries the version) and hashed icons.
- D7b. Look. The landing page uses the look of the add-ons site (`addons.appdevforall.org`,
also static files on R2): the same `styles.css`, logo, header and footer, copied from
`appdevforall/plugin-examples` `site/` into `tools/fdroid-repo/site/`. As on the add-ons site,
the page links its CSS and SVG under `assets/` with a content hash in the name, because the zone
can keep these file types in a browser for hours. The app icon on the page is an SVG that each
run makes from the adaptive icon of the app (`res/drawable/ic_launcher_*.xml`), so the icon has
one source and stays sharp on a phone. The F-Droid index keeps the PNG icon.
- D8. Metadata. `tools/fdroid-repo/metadata/org.appdevforall.k2go.yml`: license
`GPL-3.0-or-later`, source `https://github.com/appdevforall/KnowledgeToGo`, no anti-feature (no analytics, crash reports are opt-in).
- D9. Workflow. `app-fdroid-repo.yml`: called by `app-play-2-release.yml` after the release job
(live `fdroid/`), and manual (`staging` on by default) for a tag whose APK is on R2.
Release candidates never go to the repository. `fdroid update` runs in `debian:trixie` with
fdroidserver from apt. One run at a time (concurrency group `fdroid-repo`).

## Before the first live publish

- Run the workflow by hand with `staging` on, add the staging repository in the F-Droid app on a
phone, install, and check the fingerprint.
- Cloudflare: the zone can keep `.jar` files in its cache longer than `Cache-Control` says (the
add-ons work found that the Browser Cache TTL of the zone wins for file types that Cloudflare
caches by default). Add a cache rule for `/fdroid/repo/entry.jar`, `/fdroid/repo/index*` and the
same paths under `/fdroid/archive/` that respects the origin headers. Check `cf-cache-status`
and `age` after the first publish.
- Optional: a URL rewrite so that `/fdroid/` serves `/fdroid/index.html`.

## Out of scope

- Official f-droid.org submission and reproducible builds (K2GO-399). Note: an f-droid.org source
build needs the prebuilt native binaries that Gradle fetches from a GitHub Release
(`syncNativeArtifacts`). That is a concern for the official path, not for this repository.
- Removal or change of the OTA updater of the `standard` flavor.

## References

- Tool and local test: `tools/fdroid-repo/README.md`.
- Workflows: `.github/workflows/app-fdroid-repo.yml`, `.github/workflows/app-play-2-release.yml`.
- Pattern for a static site on R2: `appdevforall/plugin-examples`, `tools/addons`,
`.github/workflows/publish-addons.yml`.
- F-Droid umbrella: K2GO-399.
56 changes: 56 additions & 0 deletions tools/fdroid-repo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# fdroid-repo: the self-hosted F-Droid repository (K2GO-421)

The F-Droid repository of Knowledge to Go is static files on Cloudflare R2:

| What | URL |
|---|---|
| Repository (add it in the F-Droid app) | `https://k2go-download.appdevforall.org/fdroid/repo` |
| Landing page (for a person in a browser) | `https://k2go-download.appdevforall.org/fdroid/index.html` |
| Staging copy (manual runs) | `https://k2go-download.appdevforall.org/fdroid-staging/...` |

Design: `controller/docs/ADR-K2GO-421-self-hosted-fdroid-repo.md`.
Workflow: `.github/workflows/app-fdroid-repo.yml`.

## Files

| File | Use |
|---|---|
| `publish.sh` | The publish run: pull from R2, `fdroid update`, verify, page, upload. |
| `fdroid_repo.py` | `config`, `qr`, `verify`, `page` and `plan` steps (Python stdlib; `qr` runs in the container with python3-qrcode). |
| `test_fdroid_repo.py` | Unit tests: `python -m unittest -v test_fdroid_repo` |
| `metadata/org.appdevforall.k2go.yml` | App text for the F-Droid client. The version, permissions and signer come from the APK. |
| `site/` | The landing page: `page.template.html`, and the look of the add-ons site (`styles.css` and `adfa-logo.svg` copied from `appdevforall/plugin-examples` `site/`; `fdroid.css` for this page only). |
| `r2_mock_server.py` | Local test: serves a folder the way R2 does (no listing, no implicit index). |

## Rules that the run keeps

- R2 holds the state. Each run pulls `fdroid/repo/` and `fdroid/archive/`. Without the old index,
`fdroid update` sets the "added" date of each old version to the date of the run.
- The repo index is signed with the app signing key (the same GitHub secrets as the APK).
So the repo fingerprint is the fingerprint of the app certificate.
- `verify` stops the run before the upload when the release APK is not in the index, when another
key signed it, or when the index names a file that is not there.
- Upload order: APKs and images, then the indexes, then `entry.jar`, then the landing page.
Deletions come last. A published file never names a file that is not in R2 yet.

## Local test

Needs Docker and Python 3. Use a test keystore and an APK signed with it: the release key stays
in CI.

```sh
# A local folder is the bucket. Put the APK at its root, as the release job puts it on R2.
mkdir -p /tmp/bucket && cp K2Go-v1.2.0-fdroid-release.apk /tmp/bucket/
export KEY_ALIAS=... KEYSTORE_PASSWORD=... KEY_PASSWORD=...
TAG=v1.2.0 PREFIX=fdroid BASE_URL=http://localhost:8080 KEYSTORE_FILE=test.jks \
LOCAL_BUCKET=/tmp/bucket bash tools/fdroid-repo/publish.sh
python tools/fdroid-repo/r2_mock_server.py --root /tmp/bucket --port 8080
# Open http://localhost:8080/fdroid/index.html
```

To test from a phone on the same Wi-Fi: set `BASE_URL=http://<LAN IP of the computer>:8080`
in the publish run (the index, the QR code and the "Add to F-Droid" link carry this address),
then start the server with `--bind 0.0.0.0`. The firewall of the computer must let the port in.

`FDROID_IMAGE` selects the Docker image for `fdroid update` (default `debian:trixie`, which installs
`fdroidserver` from apt on each run).
Loading
Loading