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
6 changes: 4 additions & 2 deletions .github/ci-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ differ: "main push" venues are nightly venues, and post-merge evidence for
a commit is the next nightly run whose head contains it.

Deploys are not CI and keep their push trigger: `container-images` (image
publish) and `mcpx docs` (GitHub Pages). Jobs that only ran on `push`
publish), `mcpx docs` (GitHub Pages), and `pm-console android` (the app's
release, on pushes that touch the app; owner's instruction of 2026-11-22
that the app is built and released by Actions without a person). Jobs that only ran on `push`
were widened to `schedule` where the nightly run must do the same work:
the id arm64 world-snapshot job, the mcpx `basic: test` job, the mcpx and
mcpx-conformance `ON_MAIN` recording, and the Go module tidy commit. To
Expand Down Expand Up @@ -98,7 +100,7 @@ never a state that persists by default.
| Workflow | Automatic venue | Manual |
| ------------------------- | --------------------- | ------ |
| workflow-lint | none | yes |
| pm-console-android | none | yes |
| pm-console-android | main push, path gated | yes |
| proxy-port-fallbacks | none | yes |
| fleet-search-parity-guard | none | yes |
| fleet-rust-tests | nightly schedule | yes |
Expand Down
78 changes: 52 additions & 26 deletions .github/workflows/pm-console-android.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,86 @@
name: pm-console android

# Builds the PM console's Android app (pm-stack/console/android): a
# Trusted Web Activity over https://pm.security.cab. Manual only: it is
# run when the app changes, which is rarely, since the app is the site.
# CI tier policy: see .github/ci-policy.md. This is a release, not CI,
# so it keeps a push trigger (restricted to main, and to the app's own
# files).
#
# With the signing secrets set, the APK is signed here and attached to
# the release. Without them the build is unsigned and kept as an
# artifact, to be signed by pm-stack/console/android/sign.sh on the
# machine that holds the key.
# Builds, signs and releases the PM console's Android app
# (pm-stack/console/android): a Trusted Web Activity over
# https://pm.security.cab, plus what only an installed app has. It runs
# on every push to main that touches the app, and by hand.
#
# The version is the commit's (build.sh): a code that rises with the
# commit's time, so each build installs over the one before.
#
# Signing needs the app's key, as two secrets of the pm-console-android
# environment: PM_CONSOLE_ANDROID_KEYSTORE_B64 and
# PM_CONSOLE_ANDROID_KEYSTORE_PASSWORD. An environment, not the
# repository, so that it can be limited to runs on main. Putting the key
# there is the owner's to do, by hand; no script or agent holds or moves
# it (pm-stack/console/android/README.md).
#
# With the key: the APK is signed here, checked against the certificate
# the site lists (signing-fingerprint.txt), and released twice with
# nobody involved: as pm-console-android-v<code>, which is never
# changed again, and as pm-console-android, whose address stays the same
# and always holds the newest build. The site hands out the second.
#
# Without the key: the build is unsigned and kept as an artifact, and
# the run says so. Nothing is released.
on:
push:
branches: [main]
paths:
- "pm-stack/console/android/**"
- ".github/workflows/pm-console-android.yml"
workflow_dispatch:
inputs:
publish:
description: "Attach the APK to the release pm-console-android (signed builds only)"
type: boolean
default: true

permissions:
contents: read

# Releases run one at a time, in order.
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
build:
name: "build: APK"
name: "build, sign and release the APK"
runs-on: ubuntu-latest
timeout-minutes: 25
environment: pm-console-android
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- name: Build, and sign when the signing secrets are set
- name: Build, and sign when this environment holds the key
id: build
env:
KEYSTORE_B64: ${{ secrets.PM_CONSOLE_ANDROID_KEYSTORE_B64 }}
PM_ANDROID_KEYSTORE_PASSWORD: ${{ secrets.PM_CONSOLE_ANDROID_KEYSTORE_PASSWORD }}
run: |
bash pm-stack/console/android/build.sh
if [ -f pm-stack/console/android/app/build/outputs/apk/release/pm-console.apk ]; then
out=pm-stack/console/android/app/build/outputs/apk/release
{
echo "version_name=$(sed -n 1p "$out/version")"
echo "version_code=$(sed -n 2p "$out/version")"
} >>"$GITHUB_OUTPUT"
if [ -f "$out/pm-console.apk" ]; then
echo "signed=true" >>"$GITHUB_OUTPUT"
else
echo "signed=false" >>"$GITHUB_OUTPUT"
echo "::notice::Built unsigned: the signing secrets are not set. Sign the artifact with pm-stack/console/android/sign.sh on the machine that holds the key."
echo "::notice::Built unsigned: this environment does not hold the signing key, so nothing is released. See pm-stack/console/android/README.md, Giving GitHub the key."
echo "Built $(sed -n 1p "$out/version") unsigned: the signing key is not here, so nothing was released." >>"$GITHUB_STEP_SUMMARY"
fi
- uses: actions/upload-artifact@v7
with:
name: ${{ steps.build.outputs.signed == 'true' && 'pm-console-apk' || 'pm-console-apk-unsigned' }}
path: pm-stack/console/android/app/build/outputs/apk/release/*.apk
if-no-files-found: error
- name: Attach to the release
if: inputs.publish && steps.build.outputs.signed == 'true'
- name: Release
if: steps.build.outputs.signed == 'true' && github.ref == 'refs/heads/main'
env:
GH_TOKEN: ${{ github.token }}
run: |
apk=pm-stack/console/android/app/build/outputs/apk/release/pm-console.apk
if ! gh release view pm-console-android >/dev/null 2>&1; then
gh release create pm-console-android --latest=false \
--title "PM console for Android" \
--notes "The PM stack's console as an Android app. It opens https://pm.security.cab/console/ and signs in the way the site does. Install pm-console.apk; later builds install over it."
fi
gh release upload pm-console-android "$apk" --clobber
VERSION_NAME: ${{ steps.build.outputs.version_name }}
VERSION_CODE: ${{ steps.build.outputs.version_code }}
run: bash pm-stack/console/android/release.sh pm-stack/console/android/app/build/outputs/apk/release/pm-console.apk
8 changes: 8 additions & 0 deletions .github/workflows/pm-stack-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ jobs:
- name: Test pm-git-sync rebuild markers
run: bash pm-stack/scripts/pm-git-sync-markers.test.sh

# The Android app's release (pm-stack/console/android/release.sh),
# against a stand-in for gh: the numbered release is made once and
# never changed, the fixed address always ends up on the newest
# build and never goes back, and a run started again changes
# nothing.
- name: Test the Android app's release script
run: bash pm-stack/console/android/release.test.sh

# Script suite for #5993: pm-stack/scripts/
# tailnet-bindings.test.sh (the #781 regression pin for the
# Pad/Grist tailnet bindings) was run by no workflow. The
Expand Down
10 changes: 6 additions & 4 deletions pm-stack/console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ never falls behind the site. Around that it uses what only an installed
app has: a home-screen widget, dictation from a shortcut or a
quick-settings tile, text shared or selected in any app, long-press
shortcuts, and notifications shown as its own. The `pm-console-android`
workflow builds it and the host signs it. Once the signed file is on the
host, More, Phones offers it to the signed-in owner at
`/console/pm-console.apk`, so the phone gets the app from the site it
opens. See its README.
workflow builds it on every change to it. Once the owner has given
GitHub the signing key, the workflow signs and releases each build by
itself, and More, Phones offers the newest release to the signed-in
owner at `/console/pm-console.apk`, so the phone gets the app from the
site it opens. Until then the host signs, and its build is what is
offered. See its README.
86 changes: 57 additions & 29 deletions pm-stack/console/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,80 @@ under More, Phones, and the widget then goes back to "Tap to link".

If the two disagree the app still works, with a browser bar at the top.

## Build
## Build and release

GitHub Actions builds the app on every push to `main` that touches it
(`.github/workflows/pm-console-android.yml`), and by hand:

```bash
gh workflow run pm-console-android.yml # builds the APK in CI
bash pm-stack/console/android/build.sh # locally: needs JAVA_HOME (17 or 21) and ANDROID_HOME
bash pm-stack/console/android/sign.sh app-release-unsigned.apk # sign a CI build with the key on this machine
gh workflow run pm-console-android.yml
bash pm-stack/console/android/build.sh # here: needs JAVA_HOME (17 or 21) and ANDROID_HOME
```

The signing key is on the pm-stack host at
`~/.local/state/pm-console/android/release.p12`, and it stays there. The
workflow builds an unsigned APK and keeps it as the artifact
`pm-console-apk-unsigned`; `sign.sh` on the host signs it, checks the
certificate against `signing-fingerprint.txt`, and the signed
`pm-console.apk` is uploaded to the release:
A build names its own version from its commit (`build.sh`): a code that
rises with the commit's time, so each build installs over the one
before, and a name that says the day and the commit.

What happens next depends on who holds the signing key.

**GitHub holds it.** The build is signed in the workflow, checked
against the certificate in `signing-fingerprint.txt`, and released by
`release.sh` with nobody involved, twice:

- `pm-console-android-v<code>`: that build. Once made it is never
changed.
- `pm-console-android`: one address that always holds the newest build
and is never taken back to an older one. The site hands this one out.

Each carries `pm-console.apk`, `pm-console.apk.sha256` and a
`version.json` (name, code, commit, sha256, size, when, certificate).

**Only the laptop holds it** (how it starts). The workflow's build is
unsigned, kept as the artifact `pm-console-apk-unsigned`, and the run
says nothing was released. It can be signed and put in place by hand:

```bash
gh run download <run-id> -n pm-console-apk-unsigned -D /tmp/pm-apk
nix shell nixpkgs#apksigner -c bash pm-stack/console/android/sign.sh /tmp/pm-apk/app-release-unsigned.apk
gh release upload pm-console-android /tmp/pm-apk/pm-console.apk --clobber
install -m 644 /tmp/pm-apk/pm-console.apk ~/.local/state/pm-console/android/pm-console.apk
```

If the repository secrets `PM_CONSOLE_ANDROID_KEYSTORE_B64` and
`PM_CONSOLE_ANDROID_KEYSTORE_PASSWORD` are ever set, the workflow signs
and publishes by itself instead, and fails unless the certificate
matches. Losing the key means a new key, a new fingerprint and a
### Giving GitHub the key

The key is on the pm-stack host at
`~/.local/state/pm-console/android/release.p12`, with its password in
`keystore-password` beside it. The workflow signs once the
`pm-console-android` environment of the repository holds two secrets:

- `PM_CONSOLE_ANDROID_KEYSTORE_B64`: the keystore, base64;
- `PM_CONSOLE_ANDROID_KEYSTORE_PASSWORD`: its password.

Putting them there is the owner's to do, by hand, with `gh secret set
--env pm-console-android` or in the repository's settings. No script,
workflow or agent here holds or moves the key, on purpose. The
environment is made by the workflow's first run; limiting it to the
`main` branch (Settings, Environments) keeps a workflow on any other
branch from reading the key.

A build signed by any other key fails in `build.sh` before anything is
released. Losing the key means a new key, a new fingerprint and a
reinstall; nothing else depends on it.

## Install

On the phone, open `https://pm.security.cab/console/`, sign in, and go to
More, Phones, "Download the app". That downloads the signed build from
the host (`/console/pm-console.apk`, owner only); open it to install.
Later builds install over it.
More, Phones, "Download the app" (`/console/pm-console.apk`, owner
only). What that is, in order:

1. the build GitHub released, fetched from the release and checked
against its `version.json`; this needs nothing of the laptop;
2. otherwise the laptop's signed build
(`~/.local/state/pm-console/android/pm-console.apk`), or the copy of
it kept at Cloudflare when the laptop is away.

The page says which it is. Later builds install over it.

The native parts are checked by compiling the build and reading its
merged manifest; the site's side of each (the Ask box taking handed-over
words, linking a phone, the summary) is tested in `test/`. They have not
been exercised by an automated run on a device.

The console serves whatever signed build is at
`~/.local/state/pm-console/android/pm-console.apk` on the host, so
putting a new build in place is the whole release:

```bash
install -m 644 /tmp/pm-apk/pm-console.apk ~/.local/state/pm-console/android/pm-console.apk
```

The same file can also be attached to the GitHub release
`pm-console-android` for a copy outside the host.
9 changes: 7 additions & 2 deletions pm-stack/console/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ plugins {

def site = 'https://pm.security.cab'
def keystore = System.getenv('PM_ANDROID_KEYSTORE')
// A release names its own version (build.sh works both out from the
// commit, so a later build always installs over an earlier one). A
// build with neither set is a check that the project builds.
def releaseCode = System.getenv('PM_ANDROID_VERSION_CODE')
def releaseName = System.getenv('PM_ANDROID_VERSION_NAME')

android {
namespace 'today.developing.pmconsole'
Expand All @@ -21,8 +26,8 @@ android {
applicationId 'today.developing.pmconsole'
minSdk 24
targetSdk 34
versionCode 3
versionName '0.3.0'
versionCode releaseCode ? releaseCode.toInteger() : 3
versionName releaseName ?: '0.3.0'
manifestPlaceholders = [hostName: 'pm.security.cab', defaultUrl: "${site}/console/"]
// The app's half of the link to the site. The site's half is
// /.well-known/assetlinks.json, served by pm-console.
Expand Down
18 changes: 18 additions & 0 deletions pm-stack/console/android/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,28 @@
# asset-links file, and an APK signed by anything else would open with a
# browser bar. Without them the result is an unsigned APK, for a check
# that the project builds.
#
# The version is the commit's: the code rises with the commit's time, so
# a later build always installs over an earlier one, and the name says
# the day and the commit. Both are written to
# app/build/outputs/apk/release/version (name, then code). Set
# PM_ANDROID_VERSION_CODE and PM_ANDROID_VERSION_NAME to choose them.
set -euo pipefail

cd "$(dirname "$0")"
GRADLE_VERSION="${GRADLE_VERSION:-8.9}"
OUT=app/build/outputs/apk/release

if [ -z "${PM_ANDROID_VERSION_CODE:-}" ] || [ -z "${PM_ANDROID_VERSION_NAME:-}" ]; then
if stamp="$(git log -1 --format=%ct 2>/dev/null)" && [ -n "$stamp" ]; then
# Ten-second steps since 2020: far below Android's ceiling for
# centuries, and two commits are never closer than that in practice.
PM_ANDROID_VERSION_CODE="$(((stamp - 1577836800) / 10))"
PM_ANDROID_VERSION_NAME="$(date -u -d "@$stamp" +%Y.%m.%d)-$(git rev-parse --short=7 HEAD)"
export PM_ANDROID_VERSION_CODE PM_ANDROID_VERSION_NAME
fi
fi

export JAVA_HOME="${JAVA_HOME_17_X64:-${JAVA_HOME_21_X64:-${JAVA_HOME:-}}}"
if [ -z "$JAVA_HOME" ] || [ -z "${ANDROID_HOME:-}" ]; then
echo "build.sh: JAVA_HOME and ANDROID_HOME must be set" >&2
Expand All @@ -43,6 +59,8 @@ if [ -n "${KEYSTORE_B64:-}" ] && [ -n "${PM_ANDROID_KEYSTORE_PASSWORD:-}" ]; the
fi

"$GRADLE" --no-daemon --console=plain assembleRelease
printf '%s\n%s\n' "${PM_ANDROID_VERSION_NAME:-0.3.0}" "${PM_ANDROID_VERSION_CODE:-3}" >"$OUT/version"
echo "build.sh: version ${PM_ANDROID_VERSION_NAME:-0.3.0} (code ${PM_ANDROID_VERSION_CODE:-3})"

if [ -z "${PM_ANDROID_KEYSTORE:-}" ]; then
echo "build.sh: built unsigned: $(ls $OUT/*.apk)"
Expand Down
Loading