| workflow_payload |
name: Gitea migration identity (read only)
"on name: Gitea migration identity (read only)
"on":
push:
branches: [codex/runner-maintenance-diagnostic-20261101]
paths: [.gitea/workflows/gitea-migration-identity.yml]
workflow_dispatch:
jobs:
inspect:
name: inspect
runs-on: ubuntu-latest
if: github.repository == 'luoanwu/enterprise-platform'
steps:
- name: Read migration mapping and schema column names
run: |
set -eu
python3 <<'PY'
import datetime, hashlib, json, os, pathlib, re, socket, sqlite3, subprocess
if os.geteuid()!=0 or socket.gethostname()!='iZ2zed3pt2nygf9dy1a9d2Z':raise RuntimeError('EXPECTED_HOST_REQUIRED')
source=pathlib.Path('/root/gitea-src')
env=dict(os.environ,GIT_OPTIONAL_LOCKS='0')
def git(*args):
r=subprocess.run(['git','--no-optional-locks','-C',str(source),*args],capture_output=True,text=True,timeout=30,env=env)
if r.returncode:raise RuntimeError('SOURCE_READ_FAILED')
return r.stdout
head=git('rev-parse','HEAD').strip()
if head!='287bf811487c04cd90bcf07aa04905cbaf2e4c2d':raise RuntimeError('SOURCE_BASE_CHANGED')
report={'kind':'GiteaMigrationIdentityProbe','observedAtUTC':datetime.datetime.now(datetime.timezone.utc).isoformat(),'ci':{'sourceSha':os.environ.get('GITHUB_SHA'),'runId':os.environ.get('GITHUB_RUN_ID')},'releaseEligible':False,'sourceHead':head,'serviceChanges':False,'databaseWrites':False}
path='models/migrations/migrations.go'
current=(source/path).read_text()
base=git('show','HEAD:'+path)
# This emits migration code only, from two fixed source paths; never configuration or row data.
def entries(text):
return [{'number':int(m.group(1)), 'description':m.group(2), 'function':m.group(3)} for m in re.finditer(r'newMigration\(\s*(\d+)\s*,\s*"([^"]+)"\s*,\s*([a-zA-Z0-9_.]+)',text)]
report['baseMigrationEntries']=entries(base)[-50:]
report['workingMigrationEntries']=entries(current)[-50:]
report['migrationFileSha256']=hashlib.sha256(current.encode()).hexdigest()
delta=git('diff','--no-ext-diff','--unified=3','HEAD','--',path,'models/migrations/v1_22/v299.go')
# Any unexpectedly embedded credential literal stops export, without printing it.
if re.search(r'(?:password|secret|token|private.?key)\s*[:=]\s*["\'][^"\']{8,}["\']',delta,re.I):raise RuntimeError('SENSITIVE_LITERAL_REFUSED')
report['migrationSourceDiff']=delta[:18000]
report['migrationSourceDiffTruncated']=len(delta)>18000
report['migrationSourceDiffSha256']=hashlib.sha256(delta.encode()).hexdigest()
report['goModuleHeader']=[x for x in (source/'go.mod').read_text().splitlines()[:6] if x.startswith(('module ','go ','toolchain '))]
connection=sqlite3.connect('file:/home/git/gitea/data/gitea.db?mode=ro',uri=True,timeout=15)
connection.execute('PRAGMA query_only=ON')
tables={row[0] for row in connection.execute("SELECT name FROM sqlite_master WHERE type='table'")}
selected=['version','action_run','action_run_job','action_run_attempt','action_artifact','protected_branch','repository','team','user']
report['schemaColumns']={t:[r[1] for r in connection.execute('PRAGMA table_info("'+t+'")')] if t in tables else None for t in selected}
report['schemaVersion']=connection.execute('SELECT version FROM version WHERE id=1').fetchone()[0]
connection.close()
print('GITEA_MIGRATION_IDENTITY_JSON '+json.dumps(report,separators=(',',':')))
PY
shell: bash
timeout-minutes: "5"
permissions:
contents: read
... |