GithubSync
A docs module that connects a live SepoDesk install to its GitHub repositories and works in both directions. It shows exactly what changed and lets an administrator copy files from GitHub to the site one at a time, with a diff in front of them and a rollback behind them. It also sends files made on the server up to GitHub, tests and checks code before it goes anywhere, manages files and folders on the server, and creates new repositories.
Built for the case this exists to solve: you push a change to the repo, and the Hostinger site should pick it up without you hand-copying the file over FTP. The reverse case is covered too: you make a file on the live site, and it should reach GitHub without being re-created there by hand. The repository stays the source of truth. The live site is updated deliberately, never automatically, and never all at once unless you ask.
What it does
Syncing
- Lists what has landed in the repository since the last time you updated this site, commit by commit and file by file.
- Shows a side-by-side diff of the server copy against the repository copy before anything is written.
- Writes only the files you tick, backing up the current version first.
- Rolls an update back from the History tab: the whole set, or just the files you tick.
- Tells you when someone edited a file directly on the server, so an update never silently discards work.
- Lists files that are only on the server and creates them on GitHub, many at once, as a single commit.
- Commits a changed server file back up to the branch.
- Handles several repositories at once (engine, docs, one per module), each writing into its own folder, with its own baseline and its own restore points.
Working on code
- A line-numbered code editor that saves to the server, to GitHub, or both.
- Tests and checks: syntax and lint for PHP, JS, CSS, JSON, XML and YAML; a check that every file a file needs is present; PHP and JS unit tests; a PHP console and a JS console; and a one-button pipeline. A gate refuses to write code that is certain to break.
- A file manager for the whole project. You can browse, create files of any type and folders, edit, upload, rename, move and delete. A recycle bin and an activity log stand behind every change.
- Shows which PHP files the live site is running, so you can tell which ones are risky to edit.
GitHub
- Creates a new GitHub repository, optionally filled from a folder on the
server, and gives you the
.envlines that connect it. - Builds release packages for the engine's updater from a per-file selection.
It answers "which of these changes are mine?" by keeping a baseline commit. Everything since that commit is what is waiting for you.
The console
The page at /docs/admin/github has these tabs:
| Tab | What it is for |
|---|---|
| Waiting | What changed on GitHub since your last update. The usual place to start. |
| All files | Every file in the repository, with its state. |
| Only on server | Files in the mapped folder that GitHub does not have, ready to create there. |
| Files | The file manager for the whole project, with the recycle bin, activity log and running files. |
| History | Recent commits, restore points, and what this console has done. |
| Release | Choose files and build an update package. |
| Flow | An interactive map of how the module's files connect. |
| Tests | The pipeline, test files, PHP console and JS console. |
The header shows the repository picker (once there are two or more connections), Check for updates, Mark as up to date, and New repository (when pushing is allowed).
Opening a file from Waiting, All files or Only on server shows these panes: Changes (the diff), Edit, Checks, GitHub version, Server version and History.
Files
SepoEngine/App/Modules/GithubSync/ Manifest.php module manifest for ModuleManager Partial.php docs partial, renders the console Routes.php POST /api/v2/github/* endpoints Lib.php Config, Log, GithubClient, Workspace Service.php SyncService — states, apply, revert, push, editor save State.php SyncState (locked JSON) + ScanIndex Diff.php line diff engine Security.php admin gate and actor identity PackageBuilder.php builds release packages for SystemUpdater Architecture.php data for the Flow view ServerOnly.php files only on the server; creates them on GitHub FileManager.php project file manager, recycle bin, running files RepoCreator.php creates GitHub repositories Ci.php CiConfig, CiLint, CiDeps, CiGate — static checks CiRunner.php test runner (separate PHP process) + CiService Testing.php the built-in test framework (TestCase + runner) Overlay.php stream wrapper for testing unsaved / GitHub versions TestWorker.php command-line entry for test runs (403 on the web) Views/ Console.php markup, setup screen, denied screen; loads the rest Console.css styles, scoped to .gsy-console Console.js console behaviour, no dependencies Console.Flow.js the Flow view Console.Ci.js Checks pane, editor extras, Tests view, sandbox Console.Ci.css Console.Files.js the Files tab Console.Files.css Console.Repo.js the New repository dialog Console.Repo.css
tests/GithubSync/Test.php, tests/GithubSync/Support.php, tests/js/.test.js the module's own tests (kept in the repo)
No Composer packages, no CDN, no database tables. State lives in
Storage/GithubSync/.
Every optional file is loaded only if it is present. Until ServerOnly.php,
FileManager.php, RepoCreator.php or the CI files are uploaded, their tab,
button or endpoints simply do not appear. Nothing else breaks.
Install
1. Copy the folder to SepoEngine/App/Modules/GithubSync/.
2. Add the settings to .env:
GITHUB_SYNC_ENABLED=true GITHUB_REPO=your-account/your-repo GITHUB_BRANCH=main GITHUB_TOKEN=github_pat_xxxxxxxxxxxxxxxxxx
A fine-grained personal access token needs Contents: read on that repository. Add Contents: write for anything that sends to GitHub: push, editor commits, and Only on server. See Pushing changes back to GitHub.
3. Create the page. ModuleInstaller writes Content/Pages/admin/github.md
from the manifest. The flag comes from indexPage.front, the same way the
Dictionary module writes dictionary: true. If you are installing by hand,
copy page-admin-github.md across; the front matter is what matters:
title: Repository sync github_sync: true
4. Grant it in CoreSettings. See CoreSettings review. Run the review on GithubSync and grant the capabilities it asks for.
5. Visit /docs/admin/github signed in as an administrator. Nothing else
needs wiring: Docs.php already discovers the partial through
ModuleManager::partials(false) and the routes through loadRoutes().
Settings
Required:
GITHUB_SYNC_ENABLED:trueswitches the module on. When it is off, the routes are not even registered.GITHUB_REPO:owner/name.GITHUB_TOKEN: the access token. UseGITHUB_TOKEN_ENCinstead to store it encrypted; it is read throughSpEnvLoader::secret(), which decrypts.
Optional, with their defaults:
Connection
GITHUB_BRANCH:main. The branch the console tracks.GITHUB_SYNC_LABEL: the repository name. What the connection is called in the picker.GITHUB_SYNC_REPO_ROOT: empty. Set it when the repository holds more than this install, for examplepluginif the plugin lives in aplugin/sub-folder. Files outside it are hidden from the console.GITHUB_SYNC_TARGET: the plugin root. The folder files are written under; nothing may escape it. Either an absolute path, or a path relative to the plugin root such asSepoEngine/App/Modules/UpdateNotice.GITHUB_SYNC_STORAGE:Storage/GithubSyncbeside the engine. Holds state, the response cache, backups and the recycle bin.
Limits and safety
GITHUB_SYNC_ALLOW_EXT:php,js,mjs,css,md,json,html,htm,txt,svg,sql,yml,yaml,xml. Anything else is shown read-only in the sync views. The file manager is not limited by this.GITHUB_SYNC_DENY: extra protected paths, comma separated..env,wp-config.php,.htpasswdand.git/are always protected.GITHUB_SYNC_MAX_BYTES:2097152. Files above this are not fetched, and the editors will not open them.GITHUB_SYNC_BACKUPS:30restore points kept.GITHUB_SYNC_HISTORY:200log entries kept.GITHUB_SYNC_ALLOW_PUSH:false. Enables everything that writes to GitHub: Send to GitHub, editor commits, Only on server and New repository. Must betruetogether with a write-scoped token.GITHUB_SYNC_NORMALIZE_EOL:false. See Windows line endings.GITHUB_SYNC_TIMEOUT:20seconds per API call.GITHUB_SYNC_ALLOW_INSECURE:false. Allows anhttp://API base for local testing only.GITHUB_API_BASEandGITHUB_API_HOSTS: for GitHub Enterprise.
Only on server
GITHUB_SYNC_LOCAL_SKIP:node_modules,vendor,Storage,cache,uploads. Folders the scan does not enter. A plain name skips that folder anywhere; an entry with a slash (SepoEngine/Storage) is a path from the mapped folder.noneturns the list off.
Tests and checks
GITHUB_SYNC_LINT_GATE:true.falsemeans never refuse a write; this is the escape hatch.GITHUB_SYNC_TESTS:false.trueallows running*Test.phpfiles.GITHUB_SYNC_PHP_BIN: auto-detected. The full path of the command-line PHP, only if detection finds none. On Hostinger it is usually/opt/alt/phpXY/usr/bin/php, where XY is your PHP version, for example/opt/alt/php82/usr/bin/php.GITHUB_SYNC_TEST_DIRS:tests. Comma-separated, relative to the connection's folder.GITHUB_SYNC_TEST_TIMEOUT:25seconds per run (3–120). Keep it under the host proxy timeout.GITHUB_SYNC_TEST_MEMORY:256MB per run.GITHUB_SYNC_TEST_BOOTSTRAP: empty. A file loaded before tests, relative to the project root.GITHUB_SYNC_TEST_INPROCESS:true.falsemeans never fall back to running tests inside the web request.GITHUB_SYNC_PHP_CONSOLE:false.truelets the PHP console run typed code on the server.GITHUB_SYNC_RELEASE_TESTS:false.trueships test folders inside release packages.
File manager
GITHUB_SYNC_FILE_MANAGER:false.trueturns the Files tab on.GITHUB_SYNC_FILES_ROOT: the plugin folder. An absolute path, only if the file manager should reach beyond the plugin, for example/home/u123/domains/example.com/public_html. Leave it commented out otherwise: a path that does not exist switches the file manager off rather than falling back.GITHUB_SYNC_FILES_PROTECT: empty. Files and folders that cannot be deleted, renamed or moved. See Protected items.GITHUB_SYNC_FILES_MAX_MB:8. Upload size limit. PHP's ownupload_max_filesizeandpost_max_sizealso apply.GITHUB_SYNC_TRASH_DAYS:14. How long the recycle bin keeps things.
New repository
GITHUB_SYNC_CREATE_TOKENorGITHUB_SYNC_CREATE_TOKEN_ENC: empty. A token used only for creating repositories, for when the main token is limited to selected repositories.
All of these are read raw from the environment rather than through
SpEnvLoader::int() or ::bool(), because env() rewrites 1 to true
and 0 to false before coercion and int() then throws. Values may be
quoted and may carry a trailing # comment.
The connection and test keys accept the _N suffix per connection, for example
GITHUB_SYNC_TEST_DIRS_20 or GITHUB_SYNC_LOCAL_SKIP_3; see
More than one repository. The file manager and
create-token keys are global.
CoreSettings review
CoreSettings reviews every module's code and refuses to load a module that contains something no module should need. GithubSync contains one such construct by design, and has a narrow, named exception for it.
Why. Tests run in a separate PHP process, so a test that fatals, loops
or exits cannot take the admin request down. That needs proc_open(), which the
scanner normally refuses as exec.shell.
The exception (in CoreSettings Scanner.php, PROCESS_MODULES) allows
proc_open() only when all three of these hold:
- the module folder is
GithubSync; - the call is in
CiRunner.php; - the command is a single plain variable. That is the argument array
CiRunner::exec(array $cmd, …)passes, so no shell ever parses it.
Every other launcher (exec, shell_exec, system, passthru, popen,
backticks), and proc_open() in any other file or module, is still refused. The
line is not hidden: it shows on the review page as exec.process (HIGH), which
implies the capability system.process.run.
What to do:
- Add
system.process.runto the manifest's capabilities:
'capabilities' => ['files.write', 'system.settings.read', 'network.request', 'system.process.run'],
- After every upload, run the review on GithubSync again and grant what it asks for. The verdict should be read. A review is tied to the files' bytes, so a new version always needs a fresh one.
The test worker gets REQUEST_METHOD, HTTP_HOST and REQUEST_URI from its
environment rather than writing to $_SERVER, so the module does not need
system.settings.write.
Pushing changes back to GitHub
Everything that writes to GitHub is off by default and needs two things at once: a token that is allowed to write, and the module flag. That covers Send to GitHub, editor commits, Only on server and New repository.
1. Create a token with write access
Fine-grained personal access token (recommended). GitHub → Settings → Developer settings → Personal access tokens → Fine-grained tokens → Generate new token.
- Resource owner: the account or org that owns the repository.
- Repository access: Only select repositories → pick the repo.
- Permissions → Repository permissions:
- Contents → Read and write ← this is the one that matters
- Metadata → Read-only (auto-selected)
- Expiration: your call.
Copy the token (github_pat_…).
Classic token. Settings → Developer settings → Tokens (classic) →
Generate new token (classic). Scope: repo. That single scope already
includes write access to contents on private repos; public_repo is enough on
a public one. A classic token with only public_repo on a private repo reads
fine but fails the push with 403. This is the most common cause.
Creating repositories needs more; see Creating a repository.
2. Put it in .env
GITHUB_TOKEN=github_pat_xxxxxxxxxxxxxxxxxxxx GITHUB_SYNC_ALLOW_PUSH=true
For a second connection (slot _2), the token and the push flag are inherited
from slot 1 unless you override them. Give it a different token only if it
needs one:
GITHUB_TOKEN_2=github_pat_yyyyyyyyyyyyyyyyyyyy GITHUB_SYNC_ALLOW_PUSH_2=true
3. Verify
Reload the admin page. Send to GitHub appears on the file pane only when
Security::canPush($cfg) is true: GITHUB_SYNC_ALLOW_PUSH is set and you
are signed in as an admin. If it is missing, check the flag first, then the
role.
Confirm the token itself has push:
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ https://api.github.com/repos/OWNER/REPO | grep -E '"permissions"'
Look for "push": true. If it says push: false, regenerate the token rather
than trying to patch it.
4. What happens on push
SyncService::push() does this, in order:
Security::canPush($this->cfg): fails with403if the flag is off.$this->ws->isWritable($local): the extension and path allow-list. Fails with422if the file is not inGITHUB_SYNC_ALLOW_EXTor is inGITHUB_SYNC_DENY.- Compares the server file's git blob SHA against the current repo blob. If
they are identical, it returns
{pushed:false}and does nothing. - The lint gate: a file that would not parse is refused.
GithubClient::putFile()→PUT /repos/{owner}/{repo}/contents/{path}withbase64(content),message,branch, and the currentshaso GitHub treats it as an update, not a create.
The PUT fails with 403 if the token lacks write access, 409 if the branch
moved between your read and your write (GitHub rejects a stale sha), and
404 if the token cannot see the repo at all.
5. Common mistakes
| Symptom | Cause |
|---|---|
| Button missing entirely | GITHUB_SYNC_ALLOW_PUSH not set, or you are not an admin |
Pushing to the repository is switched off. (403) | Same flag, but the request reached the service |
GitHub refused the request. Check the token… (403) | Token lacks contents: write (fine-grained) or repo (classic) |
GitHub could not find that… (404) | Token has no access to the repo at all: wrong resource owner, or repo not in the fine-grained selection |
That repository or branch is empty. (409) | Branch name typo, or push raced a force-push |
Not sent to GitHub: … line N — Syntax error … (422) | The lint gate. Fix the line, or set GITHUB_SYNC_LINT_GATE=false |
The server took too long… (504/524) | Host proxy timeout: adjust GITHUB_SYNC_TIMEOUT or the prefetch budget |
GITHUB_TOKEN_ENC did not decrypt in the log | Wrong APP_SECRET_KEY; unset the _ENC key or fix the key |
Files only on the server
The Only on server tab works the opposite way to the rest of the console. It walks the folder the connection is mapped to and lists every file GitHub does not have, so a file made on the server no longer has to be re-created by hand on GitHub first.
Creating them on GitHub. Tick files and press Create N files on GitHub, or open one and press Create on GitHub. Everything chosen goes up as one commit through the Git Data API (blobs, tree, commit, branch update), so twenty files make one history entry. The branch update is fast-forward only: if someone pushed in the meantime, nothing changes on GitHub and you are asked to try again. Nothing on the live site changes.
If the site was at the old branch head, it is moved to the new one too, because the server already has exactly those bytes. Without this the console would report "1 commit behind" for a commit made from this very server. The History tab records it as "created N files on GitHub from the server".
Checked before anything is sent. One failure stops the whole commit, so the branch never ends up with half a feature:
- the lint gate (a file that would not parse);
- a secret check: a private key, a GitHub, AWS, Stripe live, Slack, Google or SendGrid token anywhere in the file;
- the file must not already be on GitHub (open it and use Send to GitHub to
update instead), must not be ignored, and must not match
.gitignore.
Never listed:
- the protected list (
.env,wp-config.php,.git/…), never even named; - folders whose name starts with a dot, and symbolic links (never followed);
- folders on
GITHUB_SYNC_LOCAL_SKIP; - this module's own storage folder;
- folders another connection is mapped to, because those files belong to that repository;
- whatever the server's
.gitignoreat the mapped folder excludes (comments,!negation, trailing/, anchoring,*,?,**,[...]); - extensions not on the writable list. These are counted, not listed.
A line above the list says what was left out, so an empty list is never mistaken for "checked everything". File names with characters other than letters, digits, dot, dash and underscore are listed as read-only, because the console cannot write those paths.
At most 50 files go in one commit. Very large folders stop listing at 5,000
rows; narrow them with GITHUB_SYNC_LOCAL_SKIP.
The code editor
The Edit pane of any file is a line-numbered editor with no external libraries. Save to server, Commit to GitHub or both. GitHub goes first, so a refusal there never leaves the live site edited with nothing committed. The server copy is backed up before it is replaced, and the file's original line endings are kept.
Built-in help, from Console.Ci.js:
- Live checks a moment after you stop typing, with a problems bar, red and amber line bands, an overview ruler, and the message for the caret's line.
- Keys:
F8andShift+F8: next and previous problemCtrl/Cmd+F: find, with match case and regex options- replace and replace all, both undoable
F3orCtrl/Cmd+G: next matchCtrl/Cmd+Shift+Enter: check now- Checks before saving (up to 15 seconds, and never blocks if the check cannot run). A JS syntax error asks "Save anyway". A PHP error stops before the dialog, because the server would refuse it anyway.
If the file changed on GitHub after you opened it, the commit is refused with a
409 so nothing is overwritten. Reopen it and redo the edit.
Tests and checks
A CI/CD-style safety layer, with no dependencies, built for shared hosting.
| Layer | What it does | Default |
|---|---|---|
| Lint | See What lint checks. | On |
| Links & dependencies | See What the link check covers. Each one is checked on the server and in GitHub. | On |
| Gate | Refuses to apply, save, commit, push or package a file with a certain error: a parse error, a conflict marker, invalid JSON, a duplicate declaration or a misplaced strict_types. Heuristics never block. | On |
| PHP tests | *Test.php files (PHPUnit-style, built-in framework), run in a separate PHP process with time and memory limits | Off |
| Overlay | Runs tests against your unsaved edit or the GitHub version of waiting files, without writing anything to the live site | with PHP tests |
| JS tests | *.test.js files with test()/expect(), run in a sandboxed iframe | On |
| PHP console | Run typed PHP on the server and see the output, return value, warnings and exceptions | Off |
| JS console | Run JS with chosen files preloaded, in the sandbox | On |
| Pipeline | One button: collect files → lint and links → all tests (against the GitHub versions) → a pass/fail verdict |
What lint checks
- PHP: parse errors (the real PHP parser),
php -lcompile errors, the position ofstrict_types, duplicate classes or methods, a BOM or whitespace before<?php, and leftovervar_dumpordd. - JS: syntax (checked in the browser sandbox) and leftover
debugger. - CSS: braces and comments.
- JSON and XML/SVG: that the file parses.
- YAML: tabs used for indentation.
- Any file: merge-conflict markers.
What the link check covers
- every
requireandinclude, with__DIR__,dirname(__DIR__, n)and concatenation evaluated; - every class used:
new,extends,implements,::,catch,instanceofand traits; - JS
import; - CSS
@importandurl(); @requireslines in JS tests.
Using it
Checks pane (any file). Pick Server copy, GitHub copy or My unsaved edit. You get:
- syntax and lint results; click an issue to jump to its line;
- links and dependencies, each marked present, not on server, server only, missing, external or dynamic;
- the tests that cover the file, with Run, Run with my edit and Run with GitHub version.
Tests view.
- Pipeline: choose what to check:
- files waiting on GitHub (what Update would write);
- files edited on the server (what Send to GitHub would commit);
- the ticked files;
- everything.
With "Tests use the GitHub versions" on, tests run as if the waiting files were already applied, and nothing is written.
- Test files: every test, with Run and Run all, optionally against your unsaved edit.
- PHP console and JS console.
The header shows the runner mode, the command-line PHP version, and anything missing.
How tests run on Hostinger
On Hostinger the web PHP is LiteSpeed's lsphp, which cannot run scripts. The
console probes the usual places for a command-line PHP:
/opt/alt/phpXY/usr/bin/php, next to PHP_BINARY, and /usr/bin/php. If
none works, set GITHUB_SYNC_PHP_BIN; over SSH, ls /opt/alt/ or which php
shows it. If processes are blocked entirely, PHP tests still run
in-process against the saved files. That mode has no overlay, and a fatal
error in a test ends that request; the console says so.
Writing tests
A file links to its tests by name (Lib.php ↔ LibTest.php, app.js ↔
app.test.js), or by an @covers path/to/File.php line near the top of the
test.
<?php
declare(strict_types=1);
/** @covers SepoEngine/App/Modules/Dictionary/DictionaryStore.php */
require_once dirname(__DIR__, 2) . '/SepoEngine/App/Modules/Dictionary/DictionaryStore.php';
use SepoEngine\Testing\TestCase;
final class DictionaryStoreTest extends TestCase
{
protected function setUp(): void { /* runs before each test */ }
public function testSlugIsLowercase(): void
{
$this->assertSame('hello-world', \SepoEngine\App\Modules\Dictionary\DictionaryStore::slug('Hello World'));
}
/** @dataProvider cases */
public function testTrims(string $in, string $out): void
{
$this->assertSame($out, trim($in));
}
public static function cases(): array
{
return ['spaces' => [' a ', 'a'], 'tabs' => ["\ta\t", 'a']];
}
}
Assertions:
assertTrue,assertFalse,assertNull,assertNotNullassertSame,assertNotSame,assertEquals(with a float delta)assertCount,assertEmpty,assertNotEmptyassertContains,assertNotContains,assertArrayHasKeyassertStringContainsString,assertStringStartsWith,assertMatchesRegularExpressionassertInstanceOf,assertGreaterThan,assertLessThanassertFileExists,assertThrowsfail(),markTestSkipped()
Helpers: $this->tempDir() (deleted after the test) and
self::path('relative/to/project'). Warnings and notices fail the test;
@-silenced ones do not.
Tests run against the live server, so they must not touch the database or the
network unless they set that up deliberately. If your code needs a bootstrap
first, point GITHUB_SYNC_TEST_BOOTSTRAP at it.
// @requires SepoEngine/App/Modules/Foo/Views/foo.js ← loaded first, in order
// @covers SepoEngine/App/Modules/Foo/Views/foo.js
describe('slug', function () {
test('lowercases', function () { expect(window.FooUtil.slug('A B')).toBe('a-b'); });
});
@requires and @covers must start a comment line; the same words inside a
string are ignored.
expect(x) matchers:
toBe,toEqual,toStrictEqualtoBeTruthy,toBeFalsy,toBeNull,toBeUndefined,toBeDefined,toBeNaNtoContain,toHaveLength,toMatch,toHavePropertytoBeGreaterThan,toBeLessThan,toBeCloseTo,toBeInstanceOftoThrow.not.*before any of them
Also available: beforeEach, afterEach and test.skip. Each test has 5
seconds.
Test folders are left out of release packages unless
GITHUB_SYNC_RELEASE_TESTS=true.
The file manager
The Files tab manages the whole project without the host's file manager. It
is off until GITHUB_SYNC_FILE_MANAGER=true.
What you can do
- Browse any folder: click to go in, use the path at the top to go back up, and filter long folders.
- New file: any name, any type. You can include folders (
parts/header.php), and missing ones are created..php,.html,.json,.md,.js,.svgand.xmlstart from a small template. - New folder, including nested ones (
assets/icons). - Edit text files in an editor with line numbers.
Ctrl+Ssaves; Tab and Shift+Tab indent. Pictures show a preview, and any file can be downloaded. - Upload one or more files of any type. It asks before replacing a file.
- Rename or move by changing the path.
- Delete one item, or several with the tick boxes. Folders are deleted with everything inside them.
- Compare with GitHub on any file that belongs to a connection. It uses the repository selected when you click. If that repository does not hold the file, the console switches to the one that does (the most specific mapping first) and opens the diff there.
Nothing is gone straight away. Delete moves the item to the Recycle
bin, and every save or replacing upload keeps the version it replaced there
too. From the bin you can Restore (a previous version swaps with the current
one, which goes to the bin in turn) or Delete forever. Items older than
GITHUB_SYNC_TRASH_DAYS are cleared automatically. Activity lists every
change with the account that made it.
Refused, so a slip cannot break the site:
.envand every.env.*,wp-config.php,.htpasswd,.git/andGITHUB_SYNC_DENYcannot be opened, changed or deleted. They show with a lock.- The module's storage (state, backups, the bin itself) is hidden, and the folders that hold it cannot be moved or deleted.
..paths, paths through symbolic links, and anything outside the root are refused.- A save is refused if the file changed on the server after you opened it.
- PHP, JSON and the other checked types go through the lint gate.
- Writes are atomic (temp file, then rename), keep the file's permissions, and
clear OPcache for that
.phpfile.
Protected items
Two kinds of item cannot be deleted, renamed or moved.
Built in. The project root; the GithubSync and CoreSettings folders and
everything inside them; and any folder above those. These are what you would
use to undo a mistake. Their files can still be edited.
GITHUB_SYNC_FILES_PROTECT. Only the named item itself is fixed:
- a protected file cannot be deleted, renamed or moved, but can still be edited;
- a protected folder cannot be deleted, renamed or moved, but everything inside it can still be created, edited, renamed, moved and deleted, unless it is named on the list too;
- a folder above a protected item is fixed as well, because deleting it would take the item with it.
Paths are from the project root:
GITHUB_SYNC_FILES_PROTECT=index.php,.htaccess,SepoEngine/Core,SepoEngine/App,Content,Storage,tests
It is worth adding the plugin's main WordPress file. Deleting that one file switches the whole plugin off.
What is running
So you can tell which files are risky to edit, the Files tab shows which PHP files the live site is actually running.
- Badges next to each file name:
- START-UP: loaded on every request to the engine. These are the riskiest.
- LIVE: ran in the last 5 minutes.
- TODAY: ran in the last 24 hours.
- No badge: has not run since the cache last restarted. These are the safest.
Folders get a LIVE badge when something inside them is running.
- Opening a running file shows a warning, for example "Runs on every request to the engine. 1,234 runs since the cache started. A save takes effect for the next visitor."
- Running in the toolbar lists everything sorted by most recent, with run counts and last-run times. You can limit it to the current folder or include files not run today.
The source is PHP's opcode cache (OPcache), which records every PHP file any
visitor's request runs. It covers all visitors, not just yours. The start-up set
is what the engine has loaded by the end of Routes.php.
Three limits apply:
- Only PHP is covered. JavaScript and CSS run in visitors' browsers.
- Counts reset when the cache restarts; the panel shows when counting started.
- If the host blocks reading the cache, only the start-up files are shown and the panel says why. Check that OPcache is on in hPanel → PHP Configuration.
On a running file, a save goes live for the next visitor. The syntax check stops broken code but not wrong logic, so for START-UP or LIVE files, test with a copy first. The previous version is always in the recycle bin.
Creating a repository
New repository in the header creates a GitHub repository and can fill it in the same step. It suits keeping each module in its own repository.
- Owner and name. Your account or one of your organisations. Typing a folder
like
SepoEngine/App/Modules/UpdateNoticesuggests the namesepo-update-notice. - Who can see it. Private (the default) or Public, plus an optional description.
- Start with.
- Files from a folder on this server. Module folders are suggested as you
type. The files go up as the first commits, in batches of 50, and nothing on
the server changes. The same rules as Only on server apply: protected files,
.gitignore, skipped folders, the lint gate and the secret check. - Just a README.
- Completely empty.
- Result. A link to the repository, how many files were sent, and the exact
lines for
.env, with Copy. The next free slot number is already filled in:
GITHUB_REPO_21=Happy984/sepo-update-notice GITHUB_BRANCH_21=main GITHUB_SYNC_LABEL_21="sepo-update-notice" GITHUB_SYNC_TARGET_21=SepoEngine/App/Modules/UpdateNotice
Save .env, reload, and pick the new repository at the top. If the folder
already matches what was sent, press Mark as up to date once.
The module never writes .env itself, because one bad value there and the site
cannot boot.
What it needs:
GITHUB_SYNC_ALLOW_PUSH=true; the button is hidden without it.- A token that can create repositories: classic with the
reposcope, or fine-grained with "Administration: read and write" on all repositories. When the main token is limited to selected repositories, setGITHUB_SYNC_CREATE_TOKEN(or_ENC). It is used for this and nothing else. - Organisations appear in the Owner list only if the token can read them
(
read:orgon a classic token). - The main token must reach the new repository. If it is limited to selected repositories, add the new one to it on GitHub, or the new connection cannot read it. The result screen says so.
A name that is taken, a token that is not allowed, or a missing organisation gets a plain message, for example "Happy984/sepo-demo already exists on GitHub. Pick another name."
Choosing what goes into a release
Not every change is worth shipping, so a release is a selection, not a sweep.
The list shows only files that have changed on GitHub since they were last released, worked out per file rather than per commit. Every file is compared against the blob id that actually went into a package. Change it on GitHub and its id changes, so it reappears in the list on its own. Leave it alone and it stays out of the way.
A commit range cannot express this. Release three of ten changed files and a range-based baseline either drags the other seven along or loses them. This tracks each file independently, so a partial release is just a partial release: the seven you skipped are still waiting next time.
The Release view is two tabs:
- Build a release, with the count still waiting. Within it, "Choose what goes in" and "Never packaged" both fold away. A first release can list a thousand files, and the form above should not end up a thousand rows from the button that uses it. Collapsing the chooser keeps the selection; the header shows "12 of 40 selected" either way.
- Published, listing what has gone out, with file counts and source commit.
Published files move into a collapsed "already released" section showing which version each went out in. They are not offered by default, but you can tick one deliberately to send it out again. That is what you want when a deploy went wrong on one installation.
A file that was released and has since been deleted from the repository becomes a delete operation in the next package, so installations do not keep a file the product dropped. A file that was never released and then deleted just disappears, because there is nothing to undo.
Every file is linted before it goes into a package, and test folders are left
out unless GITHUB_SYNC_RELEASE_TESTS=true. Tests that already shipped are not
turned into deletions.
A release published before this existed
If a version went out under the older commit-range builder, the per-file map is empty and the whole repository looks unreleased. The Release tab notices that exact combination (a ledger entry with no per-file record) and offers to adopt it.
Adoption reads the tree at the commit that release was built from and records every packageable file at the blob id it had then, not at head. Anything changed on GitHub since that commit correctly stays pending, which is the point. Nothing is written to the server and no package is built.
The state lives in released.json in the connection's storage folder, written
under a lock, and only after a package has been registered. Marking beforehand
would drop files off the list for a release that never happened.
Releases time out on shared hosting
Building a release means one HTTPS request per changed file, and a host's proxy cuts the connection long before that finishes. The 504 that comes back is the gateway giving up, not the application failing.
So the download is a separate, resumable step. release/prefetch fetches a
batch, returns what is left, and the console calls it again until nothing
remains, showing progress as it goes. Blobs are content-addressed, so a pass
that dies mid-way costs only that batch. release/create then builds from
files already on disk and returns quickly.
If the default batches are still too big for your host, the prefetch endpoint
has two settings: budget (seconds per call, default 12) and max_files
(default 40).
Caching is what makes resuming work, so prefetch verifies it. If a downloaded file is not on disk afterwards, it stops and names the directory rather than looping forever.
More than one repository
You can configure as many connections as you like. Slot 1 is the unsuffixed
keys you already have; slots 2 and up add an _N suffix.
Slots are discovered from the environment rather than counted up to a fixed
number, so adding GITHUB_REPO_12 needs no code change. Numbers may be sparse:
1, 2, 5, 9 is perfectly ordinary after deleting a connection, and the gaps are
skipped. There is a ceiling of 200, but only so a typo like GITHUB_REPO_99999
is not treated as a connection. Anything above it is ignored and logged with the
slot number rather than silently dropped.
Anything a slot does not set for itself is inherited from slot 1, so a second repository is usually three lines. New repository writes them for you.
Slot 1 — the engine
GITHUB_REPO=Happy984/sepodesk GITHUB_BRANCH=main GITHUB_TOKEN=github_pat_... GITHUB_SYNC_LABEL=SepoDesk core
Slot 2 — documentation, writing into Content/
GITHUB_REPO_2=Happy984/sepodesk-docs GITHUB_SYNC_LABEL_2=Documentation GITHUB_SYNC_TARGET_2=Content GITHUB_SYNC_ALLOW_EXT_2=md,txt,svg,png,jpg
That second connection reuses slot 1's token, timeouts, backup count and
limits. Give it GITHUB_TOKEN_2 only if it needs a different one, because a
token scoped to a single repository will not read the other.
What never inherits: GITHUB_REPO, GITHUB_BRANCH, GITHUB_SYNC_LABEL,
GITHUB_SYNC_TARGET and GITHUB_SYNC_REPO_ROOT. These identify a connection.
If they inherited, an unset GITHUB_REPO_4 would conjure a duplicate of slot 1
out of nothing, and a docs repository with no target of its own would start
writing into the plugin root.
Everything else inherits: the token, limits, timeouts, extension and deny lists, push and end-of-line flags, the API base, and the test settings.
Each connection gets its own folder under Storage/GithubSync/, named after its
repository and branch, with its own baseline, scan index, response cache and
restore points. Nothing is shared, so rolling back the docs repo cannot touch
the engine. Only on server skips folders that another connection is mapped to,
so a module with its own repository never shows up as "only on server" in the
engine's repository.
The picker sits in the console header and only appears once a second connection is configured. Number keys 1 to 9 switch between them.
Upgrading from a single repository: nothing to do. The first time the module
loads, it moves the existing state.json, scan.json and backups/ into the
matching connection's folder, so the baseline and every restore point survive.
Without that the console would report every file as changed.
Scoping a target. A connection can only write inside its own
GITHUB_SYNC_TARGET. Pointing the docs connection at Content/ means it
physically cannot touch SepoEngine/, whatever is in that repository. That is
worth doing even when both repos are yours.
How a file's state is decided
Every file gets a git blob id: sha1("blob " + length + NUL + contents). That
is the same id GitHub already publishes for every blob in the tree, so the
console can tell whether the server copy is byte-identical to the repository
copy without downloading anything. This was verified against git hash-object.
The states you will see:
- Up to date: identical bytes.
- Update ready: the server copy is exactly what this console last wrote, and the repository has moved on. The normal case.
- Edited on server: the server copy matches neither the repository nor the last version applied. Somebody changed it in place. Updating will overwrite that, which is why the backup is taken first.
- Different: differs, and there is no record of this console ever writing it, so it cannot tell which side is newer.
- Not on server: in the repository, absent here.
- Only on server: here, absent from the repository. Listed in its own tab.
- Ignored: you asked the console to leave it alone.
- Read-only: the extension or path is not writable, by configuration.
Local hashes are cached in scan.json, keyed by size and modification time, so
only touched files are re-read.
The baseline
The console keeps one commit id as the baseline: the last commit whose files are known to be on this server. "Waiting" lists everything between the baseline and the branch head, using GitHub's compare endpoint. That is what gives you the per-commit, per-file breakdown of exactly what changed.
The baseline moves forward on its own once every writable file in the tree
matches the repository, and after you create server files on GitHub from a site
that was up to date. If you deployed some other way, such as FTP or a
git pull on the server, press Mark as up to date so the next change list
starts from the right place.
If the branch is force-pushed or rebased, the old baseline stops being reachable. The console notices, says so, and falls back to comparing bytes across the whole tree, which still gives a correct answer.
Safety
- Administrators only.
SessionSecurity::isAdmin()gates the page, the routes, and again inside each service before any write. There is no api-user-key path. - CSRF is the engine's own middleware on
/api/v2. This module does not mint or check a token of its own. - CoreSettings. The module passes the review with a read verdict. Its one
exception (
proc_openwith an argument array, inCiRunner.phponly) is named, narrow and visible on the review page. - Path sandbox. Every segment is checked,
.and..are rejected outright, and the resolved path is checked against the deepest existing ancestor, so the guard also holds for files that do not exist yet. Symbolic links are never followed. - Protected paths.
.env(and every.env.*in the file manager),wp-config.php,.htpasswdand.git/can never be written. That includes push, Only on server and repository imports: a file the console will not write is a file it will not send either. - The lint gate refuses to write code that is certain to break, wherever it is going: apply, editor save, commit, push, Only on server, file manager and release packages. If the checker itself crashes, the write goes ahead and is logged, so a checker bug can never block a deploy.
- The secret check stops private keys and live API tokens reaching GitHub.
- Writes are atomic (temp file, then rename) and preserve the existing
file's permissions, so a deploy never loosens a file. New files get
0644. - OPcache is invalidated for each
.phpfile written, so a change takes effect on the next request instead of the next restart. - Nothing is lost by accident. Applies and editor saves keep restore points; file manager deletes and saves go to the recycle bin.
- State writes re-read under an exclusive lock before mutating, so two admins working at once cannot lose each other's changes.
- Code runs isolated. Tests run in a separate process with a minimal
environment (not the web request's).
TestWorker.phpanswers 403 to any web request. All JavaScript checks, tests and the JS console run in an<iframe sandbox="allow-scripts">with no access to the console page, cookies or CSRF token. - The PHP console is off unless enabled. Each run is logged with the actor, size and a hash, never the code.
- Only
*Test.phpfiles inside the test folders can be run, so "run test" can never mean "include any file". - File text travels as
b64:-prefixed base64, so host request filters cannot mangle source code on the way in. - SSRF. Only
api.github.comand any host you configure explicitly are called, over https only. - The storage folder is sealed with
.htaccess,web.configand anindex.php. On nginx none of that applies, so add the deny rule to the site config yourself. - Writing to GitHub is off by default. It needs both
GITHUB_SYNC_ALLOW_PUSH=trueand a token with write scope; enabling either on its own changes nothing. - The file manager is off by default, and so are PHP tests and the PHP console.
.envis never written by the module.- Every apply, revert, push, file-manager change and repository creation is
logged through
Helpers\Loggerwith the acting user. - The partial never prints.
Docs.phpruns module partials inside a prep buffer that is discarded before<head>is written, so this module delivers its page by assigning$contentand hands its CSS and JS toSepoAssets.
Database connections
Zero. The module holds its state in files, so it costs nothing against the per-user MySQL connection cap. That was deliberate: this console is most useful exactly when the site is under stress.
Windows line endings
If your local checkout writes CRLF and the repository stores LF, every file
looks different even when nothing changed. There are two ways out: set
core.autocrlf=input in git, or set GITHUB_SYNC_NORMALIZE_EOL=true here,
which normalises before hashing. The second is a comparison-time fix only:
files are always written with the repository's own bytes.
The diff viewer already ignores a pure line-ending difference and says so. Both editors keep the line endings the file had when opened.
Endpoints
All POST, all under /api/v2/github, all admin-gated, all returning
{status, data} or {status, message}. Every one takes an optional
connection id naming which repository it applies to; leaving it out uses the
first connection.
Sync
status: repository, branch, head commit, baseline, rate limit.tree: every file with its state.changes: what is waiting since the baseline.file: repository copy, server copy, diff, and commit history for one path.commitsandcommit: branch history and one commit's file list.apply: writes the listed paths. Backs up first.revert: restores a backup set.ignore: adds or removes a path from the ignore list.mark-deployed: moves the baseline without writing anything.push: commits a server file up to the branch.save: the editor; saves to the server, GitHub or both.backupsandhistory: restore points and the local action log.
Only on server
server-only: lists files that GitHub does not have.server-only/push: creates the listed files on GitHub as one commit.
File manager (needs GITHUB_SYNC_FILE_MANAGER=true)
files/info,files/list,files/read.files/save(create or update),files/upload,files/mkdir,files/rename,files/delete.files/trash,files/restore,files/purge: the recycle bin.files/activity: the change log.files/usage: which PHP files are running.
Repositories
repos/owners: the account and organisations the token can create under.repos/create: creates a repository, optionally filled from a folder.
Tests and checks
ci/capabilities: runner mode, command-line PHP, what is enabled.ci/check: lint and links for the given paths or unsaved text.ci/testsandci/run: list and run tests, optionally with an overlay.ci/console: the PHP console.ci/source: a file's server or GitHub copy, for the JS sandbox.
Releases and Flow
release/preview,release/history,release/prefetch,release/adopt,release/create: the release workflow.architecture/mapandarchitecture/file: the Flow view.
Content is sent as content_b64 / code_b64 with a b64: prefix.
Deploying this module onto a live site
Files go up one at a time, and every cross-file call is guarded, so any
partial upload leaves the site working. The general rule: new files first,
then the files that use them, Views/Console.php last. A tab or button only
appears once everything it needs is on the server.
- New back-end files:
Testing.php,Overlay.php,TestWorker.php,Ci.php,CiRunner.php,ServerOnly.php,FileManager.php,RepoCreator.php. Nothing references them yet. Lib.php,State.php,Diff.php,Security.php, thenService.phpandPackageBuilder.php. The lint gate becomes active here.Routes.php. The new endpoints appear.- Views:
Console.Ci.css,Console.Ci.js,Console.Files.css,Console.Files.js,Console.Repo.css,Console.Repo.js,Console.css,Console.Flow.js,Console.js, andConsole.phplast. - Commit
tests/to GitHub and apply it through the console. - Add the
.envlines you want, press Ctrl+F5 on the console page, and run the CoreSettings review on GithubSync again.
Nothing outside the module folder calls into it, so a half-finished upload cannot take another page down. The partial catches its own errors and prints a short notice instead.
To back it out:
| To turn off | Set |
|---|---|
| Everything | GITHUB_SYNC_ENABLED=false (routes stop being registered; the page falls back to its Markdown) |
| Writing to GitHub | unset GITHUB_SYNC_ALLOW_PUSH (read, apply and release still work) |
| The file manager | GITHUB_SYNC_FILE_MANAGER=false |
| The lint gate | GITHUB_SYNC_LINT_GATE=false |
| PHP tests and the PHP console | GITHUB_SYNC_TESTS=false, GITHUB_SYNC_PHP_CONSOLE=false |
Known limits
- Deletions on GitHub are shown as commits but are not applied by the sync views. The console never removes a file from the server on GitHub's behalf. Use the file manager to delete deliberately; it goes to the recycle bin.
- The sync file lists page at 20 rows. Select-all covers everything matching the current filter, not just the visible page.
- Repositories over 6000 files in the mapped folder are truncated in the "All files" view. "Waiting" is unaffected, because it only lists what changed.
- Only on server sends at most 50 files per commit and lists at most 5,000 files. It creates files only; to update a file already on GitHub, use Send to GitHub, which is a single-file commit.
- File names outside letters, digits, dot, dash and underscore can be managed in the file manager, but cannot be synced or sent to GitHub.
- Diffs are line based. A very large file with no common unique lines is shown as a whole-block replacement rather than a fine-grained diff.
- Running files: PHP only, counted since the opcode cache last restarted, and
unavailable if the host restricts
opcache_get_status(). - New repositories are connected by pasting the given lines into
.env; the module does not write.env. - Tested on PHP 8.3; PHP 8.0 compatibility is kept by inspection.