Build the standalone plugin with pinned HG shared files
This commit is contained in:
1 parent
db897ac2dd
commit
5e18f65a16
4 files changed
+87
No files matched your search
@@ -29,3 +29,9 @@ Voor automatische berichten zijn aanvullende toegangsgegevens nodig.
|
||||
## Bouwen en testen
|
||||
|
||||
Bouw de installeerbare ZIP met `python3 scripts/build.py`. Voer de integratietest uit met `wp --skip-plugins=hg_socialfeed eval-file /pad/naar/tests/integration.php` op een testinstallatie met een bestaande WordPress-beheerder. De test simuleert API-antwoorden en houdt testdata in het testproces.
|
||||
|
||||
## Gedeeld HG-beheer
|
||||
|
||||
De installatie-ZIP bevat het HG-beheermenu en de updater. De build controleert de vastgelegde bestanden in `shared.lock.json`. [Gedeelde code](https://code.hosting.hippogrief.nl/hippogrief/wp-plugins)
|
||||
|
||||
Open **HG Plugins → Updates** om openbare plug-inreleases te controleren. [Openbare releases](https://code.hosting.hippogrief.nl/hippogrief/wp-plugins/releases)
|
||||
@@ -7,7 +7,10 @@ import sys
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
|
||||
from sync_shared import verify_shared
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
verify_shared(root)
|
||||
destination = Path(sys.argv[1]) if len(sys.argv) > 1 else root / "dist"
|
||||
version = re.search(r"^ \* Version: (\S+)$", (root / "hg-socialfeed.php").read_text(), re.MULTILINE)
|
||||
if not version:
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Sync or verify the shared HG files bundled by a standalone plugin."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
|
||||
SOURCE_URL = 'https://code.hosting.hippogrief.nl/hippogrief/wp-plugins'
|
||||
SHARED_FILES = (
|
||||
'assets/hg-admin-menu.css',
|
||||
'includes/hg-admin-menu.php',
|
||||
'includes/hg-plugin-updates.php',
|
||||
'scripts/sync_shared.py',
|
||||
)
|
||||
|
||||
|
||||
def verify_shared(root: Path) -> None:
|
||||
try:
|
||||
lock = json.loads((root / 'shared.lock.json').read_text())
|
||||
if lock['source'] != SOURCE_URL or not re.fullmatch(r'[0-9a-f]{40}', lock['commit']):
|
||||
raise ValueError('invalid source or commit')
|
||||
if set(lock['sha256']) != set(SHARED_FILES):
|
||||
raise ValueError('unexpected shared file list')
|
||||
for name in SHARED_FILES:
|
||||
checksum = hashlib.sha256((root / name).read_bytes()).hexdigest()
|
||||
if checksum != lock['sha256'][name]:
|
||||
raise ValueError(f'checksum differs for {name}')
|
||||
except (OSError, ValueError, TypeError, KeyError) as error:
|
||||
raise SystemExit(f'HG shared files failed verification: {error}') from error
|
||||
|
||||
|
||||
def sync_shared(root: Path, source: Path, ref: str) -> None:
|
||||
git = ['git', '-C', str(source)]
|
||||
commit = subprocess.check_output(
|
||||
git + ['rev-parse', '--verify', '--end-of-options', f'{ref}^{{commit}}'],
|
||||
text=True,
|
||||
).strip()
|
||||
shared_paths = {name: f'shared/{name}' for name in SHARED_FILES}
|
||||
shared_paths['scripts/sync_shared.py'] = 'shared/sync_shared.py'
|
||||
files = {
|
||||
name: subprocess.check_output(git + ['show', f'{commit}:{remote_path}'])
|
||||
for name, remote_path in shared_paths.items()
|
||||
}
|
||||
for name, contents in files.items():
|
||||
(root / name).write_bytes(contents)
|
||||
lock = {
|
||||
'source': SOURCE_URL,
|
||||
'commit': commit,
|
||||
'sha256': {name: hashlib.sha256(contents).hexdigest() for name, contents in files.items()},
|
||||
}
|
||||
(root / 'shared.lock.json').write_text(json.dumps(lock, indent=2) + '\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--source', type=Path, help='Path to a checkout of wp-plugins')
|
||||
parser.add_argument('--ref', help='Tag or commit to copy from the shared checkout')
|
||||
options = parser.parse_args()
|
||||
if bool(options.source) != bool(options.ref):
|
||||
parser.error('--source and --ref must be supplied together')
|
||||
plugin_root = Path(__file__).resolve().parents[1]
|
||||
if options.source:
|
||||
sync_shared(plugin_root, options.source, options.ref)
|
||||
verify_shared(plugin_root)
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"source": "https://code.hosting.hippogrief.nl/hippogrief/wp-plugins",
|
||||
"commit": "b812c041a91981b1034d65f2e4ee1daff6cefaf6",
|
||||
"sha256": {
|
||||
"assets/hg-admin-menu.css": "a2af6a52dc9abef9127a9d26903b9809c1001720a89f7d85f4c22bc7d8b7f581",
|
||||
"includes/hg-admin-menu.php": "0723f681aeb651f1737de686ba8657e8f7adc7c53073a47025fcd1565bbe1047",
|
||||
"includes/hg-plugin-updates.php": "337705f1a5f1901080c5a5450a8f2e4f394a9fa8a4a7975ec5a2371fe2e55a52",
|
||||
"scripts/sync_shared.py": "a803f6d9dbcd34e6023397d9a61cd028bd04867cd0309c5b709e4282be752871"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user