element-x-ada/.gitea/workflows/upstream-sync.yml
Cobb d25549fcc9 ci(upstream-sync): fetch from GitHub directly, skip the mirror layer
The Gitea pull-mirror of element-hq/element-x-android is slow to
populate its initial clone (~12 GB). Rather than block workflow
verification on the mirror landing, fetch straight from GitHub — the
runner has outbound access and GitHub isn't flaky. The mirror stays in
place as a fallback / LAN-cache for humans doing manual git fetches.
2026-04-17 11:06:57 -07:00

97 lines
3.9 KiB
YAML

name: Upstream sync
# Daily check against the upstream mirror. Fast-forwards `main` to
# `upstream/develop` when upstream has advanced, then pings the Infra
# Matrix room so we know the wallet branch is due for a rebase.
#
# See SYNC.md on the wallet branch for the full topology + procedure
# this job implements.
on:
schedule:
# 12:00 UTC daily — quiet time for all our time zones, avoids the
# morning-meeting window where an unexpected Matrix ping is noise.
- cron: '0 12 * * *'
workflow_dispatch: # manual trigger from the Actions UI too
jobs:
sync-main:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
# Built-in token Gitea hands us — scoped to this repo, has push.
token: ${{ secrets.GITEA_TOKEN }}
- name: Fetch upstream + wallet
run: |
set -euo pipefail
# Fetch directly from GitHub. We also have a Gitea pull-mirror
# at Sulkta-Coop/element-x-upstream that tracks this same repo,
# but sourcing from GitHub keeps the workflow independent of
# the mirror's health — one less moving part to diagnose.
git remote add upstream https://github.com/element-hq/element-x-android.git
git fetch --depth=500 upstream develop
git fetch origin wallet:refs/remotes/origin/wallet
- name: Fast-forward main
id: ff
run: |
set -euo pipefail
git config user.name "sulkta-bot"
git config user.email "bot@sulkta.com"
OLD=$(git rev-parse --short HEAD)
echo "main was at $OLD"
if git merge --ff-only upstream/develop; then
NEW=$(git rev-parse --short HEAD)
if [ "$OLD" = "$NEW" ]; then
echo "main already up to date with upstream/develop"
echo "advanced=false" >> "$GITHUB_OUTPUT"
else
echo "main advanced: $OLD -> $NEW"
git push origin main
echo "advanced=true" >> "$GITHUB_OUTPUT"
echo "old=$OLD" >> "$GITHUB_OUTPUT"
echo "new=$NEW" >> "$GITHUB_OUTPUT"
fi
else
echo "::warning::main could not fast-forward to upstream/develop — someone committed to main directly?"
echo "advanced=false" >> "$GITHUB_OUTPUT"
fi
- name: Measure wallet drift
if: steps.ff.outputs.advanced == 'true'
id: drift
run: |
set -euo pipefail
MB=$(git merge-base refs/remotes/origin/wallet main)
BEHIND=$(git rev-list --count "$MB..main")
NEW_ADDED=$(git rev-list --count "$MB..upstream/develop")
echo "behind=$BEHIND" >> "$GITHUB_OUTPUT"
echo "new_added=$NEW_ADDED" >> "$GITHUB_OUTPUT"
echo "wallet is $BEHIND commits behind main now; $NEW_ADDED new upstream commits this run"
- name: Matrix notification (Infra room)
if: steps.ff.outputs.advanced == 'true'
env:
MATRIX_TOKEN: ${{ secrets.MATRIX_HOUSE_BOT_TOKEN }}
run: |
set -euo pipefail
TXN=$(date +%s%N)
ROOM='!rvxiUrWpgvMTAwzjGm:sulkta.com' # Infra
BODY="element-x upstream advanced · main ${{ steps.ff.outputs.old }} → ${{ steps.ff.outputs.new }} (${{ steps.drift.outputs.new_added }} commits). wallet is ${{ steps.drift.outputs.behind }} commits behind — rebase before next build."
# jq keeps the body properly JSON-escaped; safer than shell interp
# shellcheck disable=SC2086
PAYLOAD=$(printf '%s' "$BODY" | jq -Rs '{msgtype: "m.text", body: .}')
curl --fail -s -X PUT \
-H "Authorization: Bearer $MATRIX_TOKEN" \
-H "Content-Type: application/json" \
"https://chat.sulkta.com/_matrix/client/v3/rooms/${ROOM}/send/m.room.message/${TXN}" \
-d "$PAYLOAD"
echo "notified"