Add Houzez form exports and verified Gitea release updates
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 33s
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 33s
This commit is contained in:
22
scripts/build-release.py
Normal file
22
scripts/build-release.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build only the four plugin runtime files; exclude tests, config and Git data."""
|
||||
from pathlib import Path
|
||||
import hashlib, re, sys, zipfile
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
main = (root / 'jenhome-contact-exports.php').read_text()
|
||||
version = re.search(r'^ \* Version: (\d+\.\d+\.\d+)$', main, re.M).group(1)
|
||||
assert f"const VERSION = '{version}';" in main, 'Header/runtime version mismatch'
|
||||
if len(sys.argv) > 1:
|
||||
assert sys.argv[1] == 'v' + version, 'Tag must match plugin version'
|
||||
out = root / 'dist'
|
||||
out.mkdir(exist_ok=True)
|
||||
package = out / f'jenhome-contact-exports-{version}.zip'
|
||||
with zipfile.ZipFile(package, 'w', zipfile.ZIP_DEFLATED) as archive:
|
||||
for filename in ['jenhome-contact-exports.php', 'forms.js', 'crm-display.php', 'gitea-updater.php']:
|
||||
entry = zipfile.ZipInfo('jenhome-contact-exports/' + filename, (2026, 1, 1, 0, 0, 0))
|
||||
entry.compress_type = zipfile.ZIP_DEFLATED
|
||||
entry.external_attr = 0o100644 << 16
|
||||
archive.writestr(entry, (root / filename).read_bytes())
|
||||
checksum = hashlib.sha256(package.read_bytes()).hexdigest()
|
||||
package.with_suffix('.zip.sha256').write_text(f'{checksum} {package.name}\n')
|
||||
print(f'Built {package.name} SHA256 {checksum}')
|
||||
54
scripts/publish-release.py
Normal file
54
scripts/publish-release.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Publish a tested tag using Gitea Actions' ephemeral repository token."""
|
||||
from pathlib import Path
|
||||
import json, os, re, sys, urllib.error, urllib.request, uuid
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
base = 'https://git.labs.casa/api/v1/repos/josh/jenhomeforms'
|
||||
tag = os.environ.get('RELEASE_TAG', '')
|
||||
if not re.fullmatch(r'v\d+\.\d+\.\d+', tag):
|
||||
sys.exit('Release requires a stable vMAJOR.MINOR.PATCH tag.')
|
||||
token = os.environ.get('GITEA_TOKEN', '')
|
||||
if not token:
|
||||
sys.exit('Gitea Actions repository token is unavailable.')
|
||||
class NoRedirect(urllib.request.HTTPRedirectHandler):
|
||||
def redirect_request(self, *args):
|
||||
return None
|
||||
opener = urllib.request.build_opener(NoRedirect())
|
||||
def request(method, path, data=None, content_type='application/json'):
|
||||
body = json.dumps(data).encode() if isinstance(data, dict) else data
|
||||
req = urllib.request.Request(base + path, data=body, method=method, headers={
|
||||
'Authorization': 'token ' + token, 'Content-Type': content_type, 'Accept': 'application/json'})
|
||||
try:
|
||||
with opener.open(req, timeout=60) as response:
|
||||
raw = response.read()
|
||||
return response.status, json.loads(raw) if raw else {}
|
||||
except urllib.error.HTTPError as error:
|
||||
if error.code == 404:
|
||||
return 404, {}
|
||||
sys.exit(f'Gitea release API failed: HTTP {error.code} ({method} {path}).')
|
||||
status, release = request('GET', '/releases/tags/' + tag)
|
||||
if status == 200 and not release.get('draft'):
|
||||
sys.exit('This version is already published; published releases are not overwritten.')
|
||||
if status == 404:
|
||||
status, release = request('POST', '/releases', {
|
||||
'tag_name': tag, 'target_commitish': os.environ['SOURCE_COMMIT'], 'name': tag,
|
||||
'body': (root / 'CHANGELOG.md').read_text(), 'draft': True, 'prerelease': False})
|
||||
if status != 201:
|
||||
sys.exit('Gitea did not create the draft release.')
|
||||
release_id = int(release['id'])
|
||||
_, assets = request('GET', f'/releases/{release_id}/assets')
|
||||
existing = {asset['name'] for asset in assets}
|
||||
for suffix in ['.zip', '.zip.sha256']:
|
||||
path = root / 'dist' / ('jenhome-contact-exports-' + tag[1:] + suffix)
|
||||
if path.name in existing:
|
||||
sys.exit('A draft asset already exists. Review the draft before retrying publication.')
|
||||
boundary = 'jenhome-' + uuid.uuid4().hex
|
||||
body = (f'--{boundary}\r\nContent-Disposition: form-data; name="attachment"; filename="{path.name}"\r\n'
|
||||
'Content-Type: application/octet-stream\r\n\r\n').encode() + path.read_bytes() + f'\r\n--{boundary}--\r\n'.encode()
|
||||
status, _ = request('POST', f'/releases/{release_id}/assets?name={path.name}', body, 'multipart/form-data; boundary=' + boundary)
|
||||
if status != 201:
|
||||
sys.exit('Release asset upload failed; the release remains a draft.')
|
||||
status, _ = request('PATCH', f'/releases/{release_id}', {'draft': False})
|
||||
if status != 200:
|
||||
sys.exit('Release publication failed; review the draft in Gitea.')
|
||||
print('Published ' + tag + ' with the plugin ZIP and SHA256 checksum.')
|
||||
Reference in New Issue
Block a user