Files
app/.github/workflows/d-modem-bump.yml
T
Claude db7aa5afad D-Modem bump: wait for the checks, then merge
GitHub's auto-merge, with no checks required on main, merged the first
bump (#39) six seconds after it was opened, before any check ran. The
workflow now waits for every check on the pull request and merges only
when they have all passed (and its head is still the bump's); a failed
check leaves it open.

Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRRgas5TD8Qpbs8x2NK
2026-11-11 01:31:39 +00:00

141 lines
5.5 KiB
YAML

# D-Modem bump: moves the external/d-modem-re submodule to D-Modem's
# latest main, with the AT command reference that comes with it (the
# app's assets' copy, tools/at_reference.py), and opens (or updates) a pull request for it, set to merge
# by itself once its checks pass. Daily, by hand (Actions > D-Modem bump >
# Run workflow), or from D-Modem (a repository_dispatch of type
# "d-modem-main", for when its main changes).
#
# It needs the DMODEM_BUMP_TOKEN secret: a fine-grained personal access
# token with Contents: read on D-Modem/D-Modem (the private submodule)
# and Contents: read and write and Pull requests: read and write on
# D-Modem/app. Not the workflow's own GITHUB_TOKEN: a pull request that
# token opens starts no other workflow, so Android's checks would never
# run on it. Without the secret the run says so and stops.
#
# It merges the pull request itself once every check on it has passed
# (it waits for them: GitHub's auto-merge, with no checks required on
# main, would merge at once, before any ran); a failed check leaves it
# open for a person.
name: D-Modem bump
on:
schedule:
- cron: "17 6 * * *"
repository_dispatch:
types: [d-modem-main]
workflow_dispatch:
# (one bump at a time: a second waits for the first)
concurrency:
group: d-modem-bump
cancel-in-progress: false
permissions:
contents: read
env:
BRANCH: bot/d-modem-bump
jobs:
bump:
runs-on: ubuntu-24.04
# (a hung step ends here, not at GitHub's 6 hours)
# (the Android checks take about 15 minutes)
timeout-minutes: 60
steps:
- name: Token present
env:
TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN }}
run: |
if [ -z "$TOKEN" ]; then
echo "::error::No DMODEM_BUMP_TOKEN secret (see this workflow's header)"
exit 1
fi
- uses: actions/checkout@v6
with:
token: ${{ secrets.DMODEM_BUMP_TOKEN }}
fetch-depth: 0
# only the D-Modem submodule (proot stays where it is)
- name: D-Modem's latest main
id: bump
run: |
git submodule update --init external/d-modem-re
old=$(git -C external/d-modem-re rev-parse HEAD)
git -C external/d-modem-re fetch --quiet origin main
new=$(git -C external/d-modem-re rev-parse FETCH_HEAD)
echo "old=$old" >> "$GITHUB_OUTPUT"
echo "new=$new" >> "$GITHUB_OUTPUT"
if [ "$old" = "$new" ]; then
echo "Already at D-Modem main ${new:0:7}"
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git -C external/d-modem-re checkout --quiet "$new"
python3 tools/at_reference.py
echo "changed=true" >> "$GITHUB_OUTPUT"
{
echo 'log<<EOF'
git -C external/d-modem-re log --oneline --no-merges "$old..$new" | head -50
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Commit and push
id: commit
if: steps.bump.outputs.changed == 'true'
env:
OLD: ${{ steps.bump.outputs.old }}
NEW: ${{ steps.bump.outputs.new }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$BRANCH"
git add external/d-modem-re app/src/main/assets/docs
git commit -m "Bump D-Modem to ${NEW:0:7}" \
-m "external/d-modem-re: ${OLD:0:7} -> ${NEW:0:7} (D-Modem's main), and its AT command reference." \
-m "Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
git push --force origin "$BRANCH"
echo "head=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Pull request
id: pr
if: steps.bump.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN }}
OLD: ${{ steps.bump.outputs.old }}
NEW: ${{ steps.bump.outputs.new }}
LOG: ${{ steps.bump.outputs.log }}
run: |
body=$(printf 'Moves `external/d-modem-re` to D-Modem main: [`%s..%s`](https://github.com/D-Modem/D-Modem/compare/%s...%s)\n\n```\n%s\n```\n\nOpened by the D-Modem bump workflow (`.github/workflows/d-modem-bump.yml`); it merges once the checks pass.\n' \
"${OLD:0:7}" "${NEW:0:7}" "$OLD" "$NEW" "$LOG")
title="Bump D-Modem to ${NEW:0:7}"
pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number')
if [ -n "$pr" ]; then
gh pr edit "$pr" --title "$title" --body "$body"
else
gh pr create --base main --head "$BRANCH" --title "$title" --body "$body"
pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number')
fi
echo "number=$pr" >> "$GITHUB_OUTPUT"
# (the checks a moment to start; then all of them waited for)
- name: Merged once its checks pass
if: steps.bump.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.DMODEM_BUMP_TOKEN }}
PR: ${{ steps.pr.outputs.number }}
HEAD: ${{ steps.commit.outputs.head }}
run: |
for i in $(seq 1 20); do
n=$(gh pr checks "$PR" --json name --jq length 2>/dev/null || true)
[ "${n:-0}" -gt 0 ] && break
sleep 15
done
sleep 30
if ! gh pr checks "$PR" --watch --interval 30; then
echo "::warning::A check failed on pull request #$PR: it waits for a person"
exit 1
fi
gh pr merge "$PR" --merge --match-head-commit "$HEAD"