Skip to content

Run the maintenance jobs from Mix commands and check them in CI - #4

Draft
eksperimental wants to merge 71 commits into
mainfrom
charlotte/2026-fixes
Draft

eksperimental wants to merge 71 commits into
mainfrom
charlotte/2026-fixes

Conversation

@eksperimental

Copy link
Copy Markdown
Owner

Summary

Turns the always-on Phoenix server into Mix commands you run when you need them, then makes mix check pass again and runs it in CI.

 apps/
-├── maintenance_web/          # Phoenix web app
 └── maintenance/lib/
     ├── maintenance_job/
-    │   ├── data.ex             # release data
-    │   ├── elixir_releases.ex
-    │   ├── otp_releases.ex
-    │   ├── sample_job.ex
     │   └── unicode.ex          # the remaining job
-    ├── maintenance/db.ex       # CubDB (GitHub now says whether a PR exists)
-    ├── maintenance/runner.ex
+    ├── maintenance/cli.ex
+    └── mix/tasks/
+        ├── maintenance.ex          # help
+        ├── maintenance.status.ex
+        ├── maintenance.run.ex
+        └── maintenance.publish.ex
-maintenance@.service, build.sh, setup.sh
+.example.env
+.github/workflows/check.yml       # mix check on PRs and pushes to main

The steps of a job:

mix maintenance.status   # is an update needed?
mix maintenance.run      # prepare the change in the local clone
mix maintenance.publish  # push to the fork and open the PR (needs GITHUB_ACCESS_TOKEN)

Also in this branch:

  • Upgrade to OTP 29 and Elixir 1.20, and update deps for security advisories.
  • Replace Tentacat with Req.
  • Publish only when asked, to the configured account's fork unless --fork names another.
  • Take the commit identity from whoever runs the app.
  • Rewrite the README around the three Mix commands, and add a plan in docs/plans/occasional-use-cli.md.

Evidence

  • Before: on 99efb27, mix check failed in three places.

    • Credo flagged a grouped alias and a bare _.
    • Dialyzer reported unknown_function for Mix.*.
    • Recode refused to run with "The config is out of date".

    After: on 24368ab, mix check passes end to end. Credo found no issues, dialyzer reports Total errors: 0, Skipped: 0, and recode checked all 28 files. MIX_ENV=test mix test reports 42 passed.

  • Recode now checks every file on every run. Recode 0.9 keeps a record of earlier runs and skips files that haven't changed. With that on, mix check passed with a # FIXME in config/dev.exs. With manifest: false it exits 2 and reports the FIXME.

  • CI: this PR's run is the first run of check.yml. If anything in it changes files, the git diff --exit-code step fails the job, because recode autocorrects instead of failing.

Merge Danger

Door: two-way

Everything is in git and a revert restores it. The deleted CubDB store and release data aren't needed: whether a PR exists now comes from GitHub.

Blast Radius: whole-app

Anyone running the systemd service or the web app loses it. The jobs now run only from the Mix commands. The release jobs and the sample job are gone, so only the Unicode job is left.

update_repo fetched the remote into FETCH_HEAD but never moved the local
main branch, so jobs built their commits on a stale checkout. Fetch the
configured main branch, check it out and hard-reset it to FETCH_HEAD.
unicode.org's /versions/latest/ redirect may point to an http:// URL,
which the version regex rejected, so the job could not detect new
Unicode releases.
The Annex #31 sentence in unicode-syntax.md uses the "17.0" form; keep that
convention instead of writing the full "18.0.0" version.
gradient and its Gradualizer type checker are no longer maintained, and
Gradualizer does not compile on OTP 29.
Upstream OTP's gen_unicode_mod.escript uses strict generators (<:-),
which need OTP 28 or later, so the OTP Unicode job could not regenerate
unicode_table.bin on OTP 27.
Update all dependencies within their constraints and loosen req to
~> 0.7. This resolves the advisories in ssl_verify_fun, cowboy, cowlib,
plug, plug_cowboy, mint, hpax, req, ecto, decimal, phoenix, phoenix_html
and swoosh.

Still flagged: hackney and idna (pinned by tentacat via httpoison), and
plug_crypto and phoenix_live_view (pinned by Phoenix 1.6).
The maintenance_web app served no pages the jobs rely on, and it held
back Phoenix, LiveView and plug_crypto on versions with security
advisories. Remove the app, its endpoint and asset configuration, and
the PubSub process nobody subscribed to.
Tentacat was used for a single call, and it pulled in httpoison and
hackney 1.x, which carry security advisories and pinned idna to an
affected version. Create the pull request through Req, which the app
already uses for the GitHub API, in Maintenance.Github. With hackney
gone, update idna to a fixed release.
Cover the request sent to GitHub and the result for a created pull
request, a rejected request and a connection failure. The tests stub
GitHub with Req.Test, so Maintenance.Github now takes extra Req options
from config, set only in the test environment. Plug is added as a
test-only dependency because Req.Test runs stubs as plugs.
Remove unused require Logger lines, drop the second pr_exists?/3 clause,
which the first clause shadowed so it never ran, and use the :warning
log level instead of the deprecated :warn.
Jobs now push branches and open pull requests only when the
MAINTENANCE_PUBLISH environment variable is 1 or true. Without it they
still update the local checkout and commit, and log the pull request
they would have opened. This makes local runs safe by default.

The application logs whether publishing is enabled at startup. The
systemd unit sets MAINTENANCE_PUBLISH=true in place of the unused
MAINTENANCE_FULL_PRODUCTION variable.
Nothing in the repository uses it, and it had drifted from the code.
How the release is run on a server is managed outside this repository.
Pull requests are opened inside the fork, from the new branch into the
fork's main branch. Nothing kept that branch up to date, so it fell
behind upstream and pull requests showed every upstream commit since
the fork was last synced.

The push now sends the main branch along with the new branch, in one
atomic push. The main branch is only fast-forwarded, so if the fork's
main branch has diverged nothing is pushed. A pull request is only
opened when the push succeeds, and a failed push now returns git's
message.

Tests run the push against a local bare repository, and the test
environment uses its own data directory instead of ~/maintenance_data.
With publishing disabled, submit_pr returns :ok, pushes nothing to the
fork and does not request a pull request. The git repository setup is
now shared by all tests in the module, and the push tests use the dev
fork URL from the project config.
The README now says which fork a publish goes to, that the pull request
targets the fork's main branch, and that the fork's main branch is
fast-forwarded to upstream when publishing.
The job ran gen_unicode_mod.escript in parallel with the tasks that write
the new Unicode files and update the escript's spec_version(), so the
tests could be regenerated from the old data. The file updates now run
first and the escript runs after them.

The escript's exit status was also ignored, so a failed run was still
committed and reported as updated. run_tasks now checks every task's
result. On a failure it discards the working tree changes, returns to the
previous branch, deletes the new branch and returns the error, so nothing
is committed or published.
The OTP and Elixir release jobs, the sample job and the beam_langs_meta_data path dependency are kept in git history. The path dependency stopped a fresh clone from building.
Quantum and its cron entries, Swoosh and the mailer, the release configuration and its build script, and setup.sh, which set global git config. Git.config/1 already sets it per checkout.
The record of opened pull requests lived in a local database that is lost on a new machine and forgotten after a year. GitHub already knows, in any state. Also remove Github.fetch, which only the deleted release jobs used.
Listing and running no longer need GITHUB_ACCESS_TOKEN, only the commands that push or open a pull request do.
…built

A job now reports its status from the network alone and prepares a local commit without pushing. Maintenance.run/2 and Maintenance.publish/3 do the rest for any job: publish pushes the commit run left behind, unchanged, and opens the pull request titled with its subject. The fork is an argument instead of a function of MIX_ENV, the configured owners are plain strings, and MAINTENANCE_PUBLISH is gone because publishing is its own command.
…nce.publish Mix tasks

The tasks check the project, job and fork against the configured names without turning user input into atoms, and name the valid values when one is wrong. Publish checks for the token before it moves the checkout, and tells to run maintenance.run first when there is no commit to push.
Describe status, run and publish in the order they are used, say that only publish needs the token, and drop the IEx session and the environment variables that used to choose the fork and enable publishing.
They served the release jobs, CubDB and the parallel runner, which are gone.
An expired GITHUB_ACCESS_TOKEN in the shell made status and run fail with Bad credentials, although neither needs a token. The pull requests of the forks are public.
Publish without GITHUB_ACCESS_TOKEN printed a stack trace, and a failed version lookup crashed status, run and publish with a MatchError. Both now reach the Mix tasks as errors, which print one line.
The app moved from an always-on server to a tool run about once a year. The plan records the commands, the job contract, what was removed and the decisions behind them.
The help listed the fork names without saying which one gets the real pull requests. Each fork now has a description in config/config.exs, which mix maintenance, the run output and the --fork errors print. The publish task docs and the README say that the pull request opens inside the fork, and that maintenance-beam-app is for trial runs.
actions/cache v4 targets Node 20, which GitHub is retiring, so every run
warned that it was being forced onto Node 24. v6 runs on Node 24 and
takes the same inputs.
Req 0.7 stopped decoding zip responses unless asked, so get!/3 received
the raw archive and mix maintenance.run crashed on every Unicode version
that was not cached yet. Ask Req for the zip decoder, and route these
downloads through Req.Test in tests so a test covers the decoding.
A pull request closed without being merged blocked run and publish as if
it were still open, so the job could never be retried. Only an open pull
request blocks now. status shows a closed one next to the due job, and
run and publish go ahead.
publish ignored the job's status, so it pushed the branch and opened a
pull request even when upstream already had the update. It now pushes
nothing and says there is nothing to do, as run does.
When upstream had not moved, cache_repo skipped the reset and clean, so
files an earlier run left behind went into the next commit.
The OTP commit left downloadLocation and versionInfo in
lib/stdlib/uc_spec/vendor.info at the old version.
Three Unicode requests skipped the Req options that route them to the
test stubs, so the version lookups could not be tested and reached
unicode.org and GitHub when called. They now take the options, and the
tests fail on any request that no stub answers.
mix maintenance.status raised on the first job whose check failed, so it
printed no line at all. A common cause is a GITHUB_ACCOUNT with no fork of
the project, which showed up as an inspected 404 body. Each failed job now
shows its error on its own line, and the command still exits with an error
after printing them all. find_pull_request/3 reports a 404 as
{:not_found, "owner/repo"} so the line can name the missing repository.
When the fork's main branch had commits that upstream lacks, git rejected
the atomic push and mix maintenance.publish printed git's raw output.
Git.push/2 now reads the --porcelain output and returns
{:error, :fork_main_diverged} when git rejects the main branch. publish
then explains how to discard those commits with GitHub's Sync fork and
rerun it. The publish tests now share the fork checkout setup.
mix maintenance.run and mix maintenance.publish printed an inspected
{:not_found, "owner/repo"} term when the fork had no copy of the project.
They now print "owner/repo not found on GitHub", as mix maintenance.status
does. The three tasks share one renderer in Maintenance.CLI.
A job whose check hit GitHub's rate limit showed an inspected 403 body,
and one that could not reach GitHub showed an inspected Req.TransportError.
find_pull_request/3 now reports a 403 or 429 with no requests left as
{:rate_limited, reset_at}, read from GitHub's rate-limit headers. status,
run and publish print when the limit resets, or the network error in
words, through Maintenance.CLI.describe_error/1.
The unicode job reported both failed lookups as :unicode_version_not_found,
which status and run printed as the raw atom. The two failures have
different causes: the current version is read from a source file of the
project, which fails when that file changes, while the latest one comes
from the unicode.org redirect.

The lookups now return {:current_unicode_version_not_found, url} with the
URL of the project's file, or {:latest_unicode_version_not_found, url},
and describe_error/1 turns each into a sentence that names the version
and where it was looked up. The README explains both messages.
The check alias, which CI runs, never ran the tests, so a failing test
left both mix check and CI green. It now runs mix test in the test
environment, since check runs in dev, where mix test refuses to start.

The step goes before recode, because recode ends Mix when it finishes
and no step after it runs.

The all alias ran the tests a second time through test_isolated, after
a setup it had already run. check covers both now, so test_isolated is
gone.
The lookup of the current Unicode version raised Req.TransportError when
GitHub could not be reached. The lookup of the latest one raised
CaseClauseError on any answer other than a redirect, and reported a
network failure as a missing version. Both now return the error, so
status and run print "network error (...)" or "latest Unicode version
not found at ..." on the job's line instead of crashing.

The fake job's placeholder error is renamed, since it named an atom the
code no longer returns.
prepare looked up the latest Unicode version again, and once more for
each file it downloaded, after status had already found it. A network
failure in one of those lookups crashed run with a MatchError, and a
version published in between could be committed instead of the one
reported as due.

The MaintenanceJob callback is now prepare(project, info), and run
passes it the info from status. The Unicode job downloads the files of
info.latest, from the cache when they are there.
The download of the Unicode data raised Req.TransportError when
unicode.org could not be reached, and any other status than 200 was
reported as the bare status, such as "404". run now stops with
"network error (...)" or "could not download <url> (HTTP <status>)".

get!/2 is renamed to download/2, since it no longer raises.
When the clone or fetch of a project failed, for example because GitHub
could not be reached, Git.setup_repo/2 raised a MatchError. run now stops
with "Could not build the commit for ..." followed by the Git command
and the first line of what Git said.

cache_repo/1 also discarded the changes of the directory when neither
GitHub nor the cache had a commit, since both were nil. In the tests the
cache is inside this repository, so Git reset the repository around it.
That case now clones, and the tests set GIT_CEILING_DIRECTORIES so that
Git never looks above the cache for a repository.
In a folder that is not a repository, Git runs the command on the first
repository above it. When a project's checkout was missing, a command
such as the reset and clean of discard_changes/1 changed whatever
repository held the cache, such as a home folder kept in Git, or this
repository in the tests.

Every Git command of Maintenance.Git now sets GIT_CEILING_DIRECTORIES to
the cache, so it fails in a missing checkout instead. The tests no longer
need to set it themselves.
When a downloaded zip did not hold one of the files a Unicode job copies,
run crashed with File.Error while writing nil into the checkout. The jobs
now check the zips against the files they copy before touching the
checkout, and run stops with "<file> missing from <url>".

Each project's list of copied files now lives in one place, so the check
and the copy cannot disagree. The test zips hold every copied file, so
tests that reach Git still get there.
When a Git step that prepares the checkout failed, run printed the raw
{output, status} tuple, for example {"", 128} when a stale index.lock
kept git reset --hard from running. discard_changes/1, checkout/2,
checkout_new_branch/2 and delete_branch/2 now go through the same helper
as the clone and the fetch, so run names the Git command and the first
line of what Git said. update_repo/2 now calls discard_changes/1 instead
of repeating its reset and clean.

setup_repo/2 no longer asks Git for the current branch after checking
out the main branch: the answer could only be the main branch, so it
returns that branch from the config. get_branch/1 had no other caller
and is removed.
git add, git commit and the git config steps still returned the raw
{output, status} tuple, so run printed something like {"", 1} when a
pre-commit hook rejected the commit, or {"", 255} when a stale
config.lock blocked git config. They now go through the same helper as
the other Git steps. The commit error names only "git commit", because
the full command would repeat the whole commit message.

config/1 also stops at the first config setting that fails. Before,
four of them ignored their result.
The lookup of a project's current Unicode version ran its regex on the
body of any response. When GitHub answered with an error such as 404,
429 or 503, status said "current Unicode version not found in <url>",
which the README explains as the source file having changed.

A response with another status than 200 now gives the same error as
the downloads, "could not download <url> (HTTP <status>)". A 200 whose
body holds no version still reports "not found".

download/2 shares the status check with the lookup, so both report a
failed request the same way.
get_last_commit_id/1 took the first word of the ls-remote output as the
commit id. The output holds what Git writes to stderr, so a warning
became the id. ls-remote also lists branches whose names end in the
main branch, and one such as a/refs/heads/main sorts before it. Either
way the id did not match the cached checkout, and every run fetched
again.

The id now comes from the line whose ref is exactly the main branch.
When there is no such line, the error is {:ref_not_found, ref} instead
of a nil id, and a failed ls-remote reports "git ... failed" like the
other Git steps.

The tests share one put_env helper, which deletes a variable for nil.
commit_tasks/5 matched :ok on the checkout back to the main branch
after the commit, and on each undo step after a failed one. Since
those steps return {:git_failed, ...}, a Git failure there crashed run
with a MatchError. In the undo, the crash also hid the error that
started it and left the new branch behind.

A failed checkout after the commit is now a failed step like the
others, so run undoes it and reports what Git said. When the undo
fails too, run still reports the step that failed first. The next run
discards the leftover changes and replaces the branch.
A failed Git step reports the first line of Git's output. For a commit
with nothing in it, Git answers with the status of the checkout, so
that line was "On branch <branch>" and the reason came after it. A
pre-commit hook that fails without output gave an empty reason.

The commit now checks for staged changes before it runs, and reports
"nothing to commit, the checkout already has the files the job writes"
when there are none. The check ignores external diff tools, which Git
can be set to trust and which may call changed files equal. A Git step
that fails without output reports its exit status.
A failed Git step reports the first line of Git's output. When a
post-checkout hook failed, that line was Git's own "Switched to branch
'main'" or "Already on 'main'", printed before the hook ran, so the
error read like a success and hid the hook's message. A hook that
failed without output never reached the exit status either.

The checkouts now run with --quiet, so the first line is the hook's
own, or the exit status when the hook says nothing. Errors now name
the command as "git checkout --quiet <branch>".
After the commit, run asks Git for the files it changes and its
author. When either step failed, for example because a Git setting
was invalid, run crashed with a MatchError, and nothing said that the
commit was on its branch.

Now run stops with "Committed <branch> in <path>, but could not
describe it" and the failed Git command. These two steps leave
Git's stderr out of their result, so the error names the exit status
and Git prints its own reason above it.
A failed Git step reports the first line of what Git said. Git passes
on whatever bytes a hook writes, and when those were not UTF-8, Mix
crashed with an ArgumentError while it printed the error, so the
reason never showed.

Such bytes are now replaced with U+FFFD before they reach the error.
The replacement avoids String.replace_invalid/1, which needs Elixir
1.16, while the app still accepts Elixir 1.15.
After the commit, run prints its author from git log. When Git was set
to print logs in another encoding through i18n.logOutputEncoding, a
name with a letter such as é came back in that encoding, and Mix
crashed with an ArgumentError while it printed the summary, after the
commit was made.

git log now runs with --encoding=UTF-8, which overrides that setting.
CI ran only the Elixir pinned in .tool-versions, so a call that
exists only in newer Elixir passed CI and broke the app on 1.15,
which mix.exs accepts. String.replace_invalid/1 nearly landed that
way.

A second CI job now runs mix check on Elixir 1.15 with OTP 26, the
same steps as the pinned job. mix test alone would miss such a call
when no test runs that line, since Elixir only warns about an
undefined function at compile time, and it never loads
config/dev.exs. The job caches under its own key so that neither job
restores a build made by the other's Elixir.

The requirement in mix.exs moves from ~> 1.12 to ~> 1.15. The locked
dependencies already need 1.15, so older versions could not build
the app.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant