Public Access
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0016c8c889 | |||
| ccf68a1519 | |||
| 0a194828ee | |||
| a00cbf7d92 | |||
| 14ffe53158 | |||
| e20423f323 | |||
| 5e25c6e77b |
-12
@@ -1,12 +0,0 @@
|
||||
[submodule "templates/repos/Template-Client"]
|
||||
path = templates/repos/Template-Client
|
||||
url = https://git.mokoconsulting.tech/MokoConsulting/Template-Client.git
|
||||
[submodule "templates/repos/Template-Generic"]
|
||||
path = templates/repos/Template-Generic
|
||||
url = https://git.mokoconsulting.tech/MokoConsulting/Template-Generic.git
|
||||
[submodule "templates/repos/Template-Joomla"]
|
||||
path = templates/repos/Template-Joomla
|
||||
url = https://git.mokoconsulting.tech/MokoConsulting/Template-Joomla.git
|
||||
[submodule "templates/repos/Template-MCP"]
|
||||
path = templates/repos/Template-MCP
|
||||
url = https://git.mokoconsulting.tech/MokoConsulting/Template-MCP.git
|
||||
@@ -57,7 +57,7 @@ jobs:
|
||||
- name: Determine target repos
|
||||
id: repos
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1"
|
||||
|
||||
@@ -105,7 +105,7 @@ jobs:
|
||||
|
||||
- name: Apply protection rules
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
DRY_RUN: ${{ inputs.dry_run || 'false' }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1"
|
||||
|
||||
@@ -84,8 +84,8 @@ jobs:
|
||||
echo "Running: php automation/bulk_sync.php ${{ steps.args.outputs.args }}"
|
||||
php automation/bulk_sync.php ${{ steps.args.outputs.args }} 2>&1 | tee /tmp/bulk_sync.log
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
GIT_PLATFORM: gitea
|
||||
GITEA_URL: https://git.mokoconsulting.tech
|
||||
GITEA_ORG: MokoConsulting
|
||||
@@ -112,7 +112,7 @@ jobs:
|
||||
bash automation/enforce_tags.sh || echo "Tag enforcement had errors (non-fatal)"
|
||||
fi
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
GITEA_URL: https://git.mokoconsulting.tech
|
||||
GITEA_ORG: MokoConsulting
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ jobs:
|
||||
- name: Determine target repos
|
||||
id: repos
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1"
|
||||
|
||||
@@ -107,7 +107,7 @@ jobs:
|
||||
- name: Run Renovate
|
||||
if: steps.repos.outputs.repo_list != ''
|
||||
env:
|
||||
RENOVATE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
RENOVATE_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
RENOVATE_PLATFORM: gitea
|
||||
RENOVATE_ENDPOINT: ${{ env.GITEA_URL }}/api/v1
|
||||
RENOVATE_GIT_AUTHOR: 'Renovate Bot <renovate@mokoconsulting.tech>'
|
||||
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
|
||||
- name: Sync all wikis
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
|
||||
run: |
|
||||
if [ -z "$GH_TOKEN" ]; then
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: mokocli.Release
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
||||
# INGROUP: mokoplatform.Release
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
# PATH: /.mokogitea/workflows/auto-bump.yml
|
||||
# VERSION: 09.02.00
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: Auto patch-bump version on every push to dev (skips merge commits)
|
||||
|
||||
name: "Universal: Auto Version Bump"
|
||||
@@ -43,19 +43,21 @@ jobs:
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup mokocli tools
|
||||
- name: Setup mokoplatform tools
|
||||
run: |
|
||||
if ! command -v composer &> /dev/null; then
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
|
||||
fi
|
||||
if [ -d "/opt/mokocli/cli" ]; then
|
||||
echo "MOKO_CLI=/opt/mokocli/cli" >> "$GITHUB_ENV"
|
||||
if [ -f "/opt/mokoplatform/cli/version_bump.php" ] && [ -f "/opt/mokoplatform/vendor/autoload.php" ]; then
|
||||
echo "Using pre-installed /opt/mokoplatform"
|
||||
echo "MOKO_CLI=/opt/mokoplatform/cli" >> "$GITHUB_ENV"
|
||||
else
|
||||
if ! command -v composer &> /dev/null; then
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
|
||||
fi
|
||||
rm -rf /tmp/mokoplatform-api
|
||||
git clone --depth 1 --branch main --quiet \
|
||||
"https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/MokoConsulting/mokocli.git" \
|
||||
/tmp/mokocli
|
||||
cd /tmp/mokocli && composer install --no-dev --no-interaction --quiet
|
||||
echo "MOKO_CLI=/tmp/mokocli/cli" >> "$GITHUB_ENV"
|
||||
"https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/MokoConsulting/mokoplatform.git" \
|
||||
/tmp/mokoplatform-api
|
||||
cd /tmp/mokoplatform-api && composer install --no-dev --no-interaction --quiet
|
||||
echo "MOKO_CLI=/tmp/mokoplatform-api/cli" >> "$GITHUB_ENV"
|
||||
fi
|
||||
|
||||
- name: Bump version
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: mokocli.Release
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/mokocli
|
||||
# INGROUP: mokoplatform.Release
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/mokoplatform
|
||||
# PATH: /templates/workflows/universal/auto-release.yml.template
|
||||
# VERSION: 05.00.00
|
||||
# BRIEF: Universal build & release � detects platform from manifest.xml
|
||||
@@ -66,25 +66,25 @@ jobs:
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup mokocli tools
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
|
||||
run: |
|
||||
if [ -f /opt/mokocli/cli/version_bump.php ] && [ -f /opt/mokocli/vendor/autoload.php ]; then
|
||||
echo Using pre-installed /opt/mokocli
|
||||
echo MOKO_CLI=/opt/mokocli/cli >> $GITHUB_ENV
|
||||
if [ -f /opt/mokoplatform/cli/version_bump.php ] && [ -f /opt/mokoplatform/vendor/autoload.php ]; then
|
||||
echo Using pre-installed /opt/mokoplatform
|
||||
echo MOKO_CLI=/opt/mokoplatform/cli >> $GITHUB_ENV
|
||||
else
|
||||
echo Falling back to fresh clone
|
||||
if ! command -v composer > /dev/null 2>&1; then
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer > /dev/null 2>&1
|
||||
fi
|
||||
rm -rf /tmp/mokocli
|
||||
CLONE_URL=https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokocli.git
|
||||
git clone --depth 1 --branch main --quiet $CLONE_URL /tmp/mokocli
|
||||
cd /tmp/mokocli
|
||||
rm -rf /tmp/mokoplatform-api
|
||||
CLONE_URL=https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokoplatform.git
|
||||
git clone --depth 1 --branch main --quiet $CLONE_URL /tmp/mokoplatform-api
|
||||
cd /tmp/mokoplatform-api
|
||||
composer install --no-dev --no-interaction --quiet
|
||||
echo MOKO_CLI=/tmp/mokocli/cli >> $GITHUB_ENV
|
||||
echo MOKO_CLI=/tmp/mokoplatform-api/cli >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Rename branch to rc
|
||||
@@ -109,40 +109,6 @@ jobs:
|
||||
--path . --stability rc --bump minor --branch rc \
|
||||
--token "${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
|
||||
- name: Update RC release notes from CHANGELOG.md
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
|
||||
# Extract [Unreleased] section from changelog
|
||||
NOTES=""
|
||||
if [ -f "CHANGELOG.md" ]; then
|
||||
NOTES=$(awk '/^## \[Unreleased\]/{found=1; next} /^## \[/{if(found) exit} found{print}' CHANGELOG.md)
|
||||
fi
|
||||
[ -z "$NOTES" ] && NOTES="Release candidate"
|
||||
|
||||
# Find the RC release and update its body
|
||||
RELEASE_ID=$(curl -sf -H "Authorization: token ${TOKEN}" \
|
||||
"${API_BASE}/releases/tags/release-candidate" \
|
||||
| python3 -c "import json,sys; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$RELEASE_ID" ]; then
|
||||
python3 -c "
|
||||
import json, urllib.request
|
||||
body = open('/dev/stdin').read()
|
||||
payload = json.dumps({'body': body}).encode()
|
||||
req = urllib.request.Request(
|
||||
'${API_BASE}/releases/${RELEASE_ID}',
|
||||
data=payload, method='PATCH',
|
||||
headers={
|
||||
'Authorization': 'token ${TOKEN}',
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
urllib.request.urlopen(req)
|
||||
" <<< "$NOTES"
|
||||
echo "RC release notes updated from CHANGELOG.md"
|
||||
fi
|
||||
|
||||
- name: Summary
|
||||
if: always()
|
||||
run: |
|
||||
@@ -183,77 +149,50 @@ jobs:
|
||||
fi
|
||||
echo "No conflict markers found"
|
||||
|
||||
- name: Setup mokocli tools
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_MIRROR_TOKEN }}"}}'
|
||||
run: |
|
||||
if [ -f /opt/mokocli/cli/version_bump.php ] && [ -f /opt/mokocli/vendor/autoload.php ]; then
|
||||
echo Using pre-installed /opt/mokocli
|
||||
echo MOKO_CLI=/opt/mokocli/cli >> $GITHUB_ENV
|
||||
if [ -f /opt/mokoplatform/cli/version_bump.php ] && [ -f /opt/mokoplatform/vendor/autoload.php ]; then
|
||||
echo Using pre-installed /opt/mokoplatform
|
||||
echo MOKO_CLI=/opt/mokoplatform/cli >> $GITHUB_ENV
|
||||
else
|
||||
echo Falling back to fresh clone
|
||||
if ! command -v composer > /dev/null 2>&1; then
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer > /dev/null 2>&1
|
||||
fi
|
||||
rm -rf /tmp/mokocli
|
||||
CLONE_URL=https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokocli.git
|
||||
git clone --depth 1 --branch main --quiet $CLONE_URL /tmp/mokocli
|
||||
cd /tmp/mokocli
|
||||
rm -rf /tmp/mokoplatform-api
|
||||
CLONE_URL=https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokoplatform.git
|
||||
git clone --depth 1 --branch main --quiet $CLONE_URL /tmp/mokoplatform-api
|
||||
cd /tmp/mokoplatform-api
|
||||
composer install --no-dev --no-interaction --quiet
|
||||
echo MOKO_CLI=/tmp/mokocli/cli >> $GITHUB_ENV
|
||||
echo MOKO_CLI=/tmp/mokoplatform-api/cli >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: "Determine version bump level"
|
||||
id: bump
|
||||
run: |
|
||||
# Fix/patch branches: version was already bumped by pre-release, just strip suffix
|
||||
# Feature/dev branches: bump minor for the new stable release
|
||||
HEAD_REF="${{ github.event.pull_request.head.ref || 'dev' }}"
|
||||
case "$HEAD_REF" in
|
||||
fix/*|patch/*|hotfix/*|bugfix/*) BUMP="none" ;;
|
||||
*) BUMP="minor" ;;
|
||||
esac
|
||||
echo "level=${BUMP}" >> "$GITHUB_OUTPUT"
|
||||
echo "Bump level: ${BUMP} (from branch: ${HEAD_REF})"
|
||||
|
||||
- name: "Publish stable release"
|
||||
run: |
|
||||
BUMP_FLAG=""
|
||||
if [ "${{ steps.bump.outputs.level }}" != "none" ]; then
|
||||
BUMP_FLAG="--bump ${{ steps.bump.outputs.level }}"
|
||||
fi
|
||||
php ${MOKO_CLI}/release_publish.php \
|
||||
--path . --stability stable ${BUMP_FLAG} --branch main \
|
||||
--path . --stability stable --bump minor --branch main \
|
||||
--token "${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
|
||||
- name: Update release notes and promote changelog
|
||||
- name: Update release notes from CHANGELOG.md
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
|
||||
# Get the stable release info (version and ID)
|
||||
RELEASE_JSON=$(curl -sf -H "Authorization: token ${TOKEN}" \
|
||||
"${API_BASE}/releases/tags/stable" 2>/dev/null || echo '{}')
|
||||
RELEASE_ID=$(python3 -c "import json,sys; print(json.load(sys.stdin).get('id',''))" <<< "$RELEASE_JSON" 2>/dev/null || true)
|
||||
# Extract version from release name (e.g. "06.17.00" or "v06.17.00")
|
||||
VERSION=$(python3 -c "
|
||||
import json, sys, re
|
||||
r = json.load(sys.stdin)
|
||||
name = r.get('name', '')
|
||||
m = re.search(r'(\d+\.\d+\.\d+)', name)
|
||||
print(m.group(1) if m else '')
|
||||
" <<< "$RELEASE_JSON" 2>/dev/null || true)
|
||||
|
||||
# Extract [Unreleased] section from changelog
|
||||
NOTES=""
|
||||
if [ -f "CHANGELOG.md" ]; then
|
||||
NOTES=$(awk '/^## \[Unreleased\]/{found=1; next} /^## \[/{if(found) exit} found{print}' CHANGELOG.md)
|
||||
[ -z "$NOTES" ] && NOTES="Stable release"
|
||||
else
|
||||
NOTES="Stable release"
|
||||
fi
|
||||
[ -z "$NOTES" ] && NOTES="Stable release"
|
||||
|
||||
# Update release body via API
|
||||
RELEASE_ID=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
"${API_BASE}/releases/tags/stable" | python3 -c "import json,sys; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$RELEASE_ID" ]; then
|
||||
python3 -c "
|
||||
import json, urllib.request
|
||||
@@ -263,7 +202,7 @@ jobs:
|
||||
'${API_BASE}/releases/${RELEASE_ID}',
|
||||
data=payload, method='PATCH',
|
||||
headers={
|
||||
'Authorization': 'token ${TOKEN}',
|
||||
'Authorization': 'token ${{ secrets.MOKOGITEA_TOKEN }}',
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
urllib.request.urlopen(req)
|
||||
@@ -271,24 +210,6 @@ jobs:
|
||||
echo "Release notes updated from CHANGELOG.md"
|
||||
fi
|
||||
|
||||
# Promote [Unreleased] → [version] in CHANGELOG.md and reset
|
||||
if [ -n "$VERSION" ] && [ -f "CHANGELOG.md" ]; then
|
||||
DATE=$(date +%Y-%m-%d)
|
||||
python3 -c "
|
||||
import sys
|
||||
version, date = sys.argv[1], sys.argv[2]
|
||||
content = open('CHANGELOG.md').read()
|
||||
old = '## [Unreleased]'
|
||||
new = f'## [Unreleased]\n\n## [{version}] --- {date}'
|
||||
content = content.replace(old, new, 1)
|
||||
open('CHANGELOG.md', 'w').write(content)
|
||||
" "$VERSION" "$DATE"
|
||||
git add CHANGELOG.md
|
||||
git commit -m "chore: promote changelog [Unreleased] → [${VERSION}]" || true
|
||||
git push origin main || true
|
||||
echo "Changelog promoted: [Unreleased] → [${VERSION}]"
|
||||
fi
|
||||
|
||||
# -- STEP 9: Mirror to GitHub (stable only) --------------------------------
|
||||
- name: "Step 9: Mirror release to GitHub"
|
||||
if: >-
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: MokoStandards.Universal
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
||||
# INGROUP: MokoPlatform.Universal
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
# PATH: /.mokogitea/workflows/branch-cleanup.yml
|
||||
# VERSION: 01.00.00
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: Delete feature branches after PR merge
|
||||
|
||||
name: "Branch Cleanup"
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
name: "Generic: Project CI"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
- dev/**
|
||||
- rc/**
|
||||
- version/**
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: MokoStandards.Maintenance
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoStandards
|
||||
# PATH: /.gitea/workflows/cleanup.yml
|
||||
# VERSION: 01.00.00
|
||||
# INGROUP: mokoplatform.Maintenance
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
# PATH: /.mokogitea/workflows/cleanup.yml
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: Scheduled cleanup — delete merged branches and old workflow runs
|
||||
|
||||
name: "Universal: Repository Cleanup"
|
||||
@@ -33,17 +33,17 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GA_TOKEN }}
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
|
||||
- name: Delete merged branches
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
run: |
|
||||
echo "=== Merged Branch Cleanup ==="
|
||||
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
|
||||
|
||||
# List branches via API
|
||||
BRANCHES=$(curl -sS -H "Authorization: token ${GA_TOKEN}" \
|
||||
BRANCHES=$(curl -sS -H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${API}/branches?limit=50" | jq -r '.[].name')
|
||||
|
||||
DELETED=0
|
||||
@@ -56,7 +56,7 @@ jobs:
|
||||
# Check if branch is merged into main
|
||||
if git merge-base --is-ancestor "origin/${BRANCH}" origin/main 2>/dev/null; then
|
||||
echo " Deleting merged branch: ${BRANCH}"
|
||||
curl -sS -X DELETE -H "Authorization: token ${GA_TOKEN}" \
|
||||
curl -sS -X DELETE -H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${API}/branches/${BRANCH}" 2>/dev/null || true
|
||||
DELETED=$((DELETED + 1))
|
||||
fi
|
||||
@@ -66,20 +66,20 @@ jobs:
|
||||
|
||||
- name: Clean old workflow runs
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
run: |
|
||||
echo "=== Workflow Run Cleanup ==="
|
||||
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
|
||||
CUTOFF=$(date -d "30 days ago" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -v-30d +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
# Get old completed runs
|
||||
RUNS=$(curl -sS -H "Authorization: token ${GA_TOKEN}" \
|
||||
RUNS=$(curl -sS -H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${API}/actions/runs?status=completed&limit=50" | \
|
||||
jq -r ".workflow_runs[] | select(.created_at < \"${CUTOFF}\") | .id" 2>/dev/null)
|
||||
|
||||
DELETED=0
|
||||
for RUN_ID in $RUNS; do
|
||||
curl -sS -X DELETE -H "Authorization: token ${GA_TOKEN}" \
|
||||
curl -sS -X DELETE -H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${API}/actions/runs/${RUN_ID}" 2>/dev/null || true
|
||||
DELETED=$((DELETED + 1))
|
||||
done
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: MokoStandards.Security
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/MokoStandards-API
|
||||
# INGROUP: mokoplatform.Security
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/mokoplatform
|
||||
# PATH: /templates/workflows/gitleaks.yml.template
|
||||
# VERSION: 01.00.00
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: Secret scanning — detect leaked credentials, API keys, and tokens
|
||||
#
|
||||
# +========================================================================+
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: moko-platform.Automation
|
||||
# VERSION: 01.00.00
|
||||
# INGROUP: mokoplatform.Automation
|
||||
# VERSION: 09.26.02
|
||||
# BRIEF: Auto-create feature branch when an issue is opened
|
||||
|
||||
name: "Universal: Issue Branch"
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
steps:
|
||||
- name: Create branch and comment
|
||||
run: |
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
|
||||
ISSUE_NUM="${{ github.event.issue.number }}"
|
||||
ISSUE_TITLE="${{ github.event.issue.title }}"
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: MokoStandards.Notifications
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoStandards
|
||||
# PATH: /.gitea/workflows/notify.yml
|
||||
# VERSION: 01.00.00
|
||||
# INGROUP: mokoplatform.Notifications
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
# PATH: /.mokogitea/workflows/notify.yml
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: Push notifications via ntfy on release success or workflow failure
|
||||
|
||||
name: "Universal: Notifications"
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: mokocli.CI
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/mokocli
|
||||
# INGROUP: mokoplatform.CI
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/mokoplatform
|
||||
# PATH: /templates/workflows/universal/pr-check.yml.template
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: PR gate — branch policy + code validation before merge
|
||||
|
||||
@@ -4,26 +4,23 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: mokocli.Release
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
||||
# INGROUP: mokoplatform.Release
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
# PATH: /templates/workflows/universal/pre-release.yml.template
|
||||
# VERSION: 05.01.00
|
||||
# BRIEF: Auto pre-release on push to dev/alpha/beta/rc branches
|
||||
# BRIEF: Manual pre-release -- builds dev/alpha/beta/rc packages from any branch
|
||||
|
||||
name: "Universal: Pre-Release"
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
branches:
|
||||
- dev
|
||||
- 'fix/**'
|
||||
- 'patch/**'
|
||||
- 'hotfix/**'
|
||||
- 'bugfix/**'
|
||||
- 'chore/**'
|
||||
- alpha
|
||||
- beta
|
||||
- rc
|
||||
pull_request_target:
|
||||
types: [synchronize, opened, reopened]
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
stability:
|
||||
@@ -46,11 +43,12 @@ env:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: "Build Pre-Release (${{ inputs.stability || github.ref_name }})"
|
||||
name: "Build Pre-Release (${{ inputs.stability || 'development' }})"
|
||||
runs-on: release
|
||||
if: >-
|
||||
github.event_name == 'workflow_dispatch' ||
|
||||
github.event_name == 'push'
|
||||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev') ||
|
||||
(github.event_name == 'pull_request_target' && github.event.pull_request.base.ref == 'main')
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -58,47 +56,40 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
ref: ${{ github.ref_name }}
|
||||
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }}
|
||||
|
||||
- name: Setup mokocli tools
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
|
||||
run: |
|
||||
# Use pre-installed /opt/mokocli if available (updated by cron every 6h)
|
||||
if [ -f /opt/mokocli/cli/version_bump.php ] && [ -f /opt/mokocli/cli/manifest_element.php ] && [ -f /opt/mokocli/vendor/autoload.php ]; then
|
||||
echo Using pre-installed /opt/mokocli
|
||||
echo MOKO_CLI=/opt/mokocli/cli >> $GITHUB_ENV
|
||||
# Use pre-installed /opt/mokoplatform if available (updated by cron every 6h)
|
||||
if [ -f /opt/mokoplatform/cli/version_bump.php ] && [ -f /opt/mokoplatform/cli/manifest_element.php ] && [ -f /opt/mokoplatform/vendor/autoload.php ]; then
|
||||
echo Using pre-installed /opt/mokoplatform
|
||||
echo MOKO_CLI=/opt/mokoplatform/cli >> $GITHUB_ENV
|
||||
else
|
||||
echo Falling back to fresh clone
|
||||
if ! command -v composer > /dev/null 2>&1; then
|
||||
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer > /dev/null 2>&1
|
||||
fi
|
||||
rm -rf /tmp/mokocli
|
||||
CLONE_URL=https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokocli.git
|
||||
git clone --depth 1 --branch main --quiet $CLONE_URL /tmp/mokocli
|
||||
cd /tmp/mokocli && composer install --no-dev --no-interaction --quiet
|
||||
echo MOKO_CLI=/tmp/mokocli/cli >> $GITHUB_ENV
|
||||
rm -rf /tmp/mokoplatform-api
|
||||
CLONE_URL=https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokoplatform.git
|
||||
git clone --depth 1 --branch main --quiet $CLONE_URL /tmp/mokoplatform-api
|
||||
cd /tmp/mokoplatform-api && composer install --no-dev --no-interaction --quiet
|
||||
echo MOKO_CLI=/tmp/mokoplatform-api/cli >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Detect platform
|
||||
id: platform
|
||||
run: |
|
||||
# Auto-detect and update platform if not set in manifest
|
||||
php ${MOKO_CLI}/platform_detect.php --path . --github-output 2>/dev/null || true
|
||||
php ${MOKO_CLI}/manifest_read.php --path . --github-output
|
||||
|
||||
- name: Resolve metadata and bump version
|
||||
id: meta
|
||||
run: |
|
||||
# Auto-detect stability from branch name on push, or use input on dispatch
|
||||
if [ "${{ github.event_name }}" = "push" ]; then
|
||||
case "${{ github.ref_name }}" in
|
||||
rc) STABILITY="release-candidate" ;;
|
||||
alpha) STABILITY="alpha" ;;
|
||||
beta) STABILITY="beta" ;;
|
||||
*) STABILITY="development" ;;
|
||||
esac
|
||||
# Auto-detect stability: RC for PRs targeting main, else use input or default to development
|
||||
if [ "${{ github.event_name }}" = "pull_request_target" ] && [ "${{ github.event.pull_request.base.ref }}" = "main" ]; then
|
||||
STABILITY="release-candidate"
|
||||
else
|
||||
STABILITY="${{ inputs.stability || 'development' }}"
|
||||
fi
|
||||
@@ -173,7 +164,7 @@ jobs:
|
||||
php ${MOKO_CLI}/release_create.php \
|
||||
--path . --version "$VERSION" --tag "$TAG" \
|
||||
--token "${{ secrets.MOKOGITEA_TOKEN }}" --api-base "$API_BASE" \
|
||||
--repo "${GITEA_REPO}" --branch "${{ github.ref_name }}" --prerelease
|
||||
--repo "${GITEA_REPO}" --branch dev --prerelease
|
||||
|
||||
- name: Update release notes from CHANGELOG.md
|
||||
run: |
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: mokocli.Validation
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/mokocli
|
||||
# INGROUP: mokoplatform.Validation
|
||||
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/mokoplatform
|
||||
# PATH: /templates/workflows/joomla/repo_health.yml.template
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: Enforces repository guardrails by validating scripts governance, tooling availability, and core repository health artifacts.
|
||||
@@ -33,8 +33,7 @@ on:
|
||||
- scripts
|
||||
- repo
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: MokoStandards.Security
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoStandards
|
||||
# PATH: /.gitea/workflows/security-audit.yml
|
||||
# VERSION: 01.00.00
|
||||
# INGROUP: mokoplatform.Security
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
# PATH: /.mokogitea/workflows/security-audit.yml
|
||||
# VERSION: 09.23.00
|
||||
# BRIEF: Dependency vulnerability scanning for composer and npm packages
|
||||
|
||||
name: "Universal: Security Audit"
|
||||
@@ -80,3 +80,19 @@ jobs:
|
||||
-H "Priority: high" \
|
||||
-d "Security audit found vulnerabilities. Review dependency updates." \
|
||||
"${NTFY_URL}/${NTFY_TOPIC}" || true
|
||||
|
||||
|
||||
- name: Joomla version audit
|
||||
if: always()
|
||||
run: |
|
||||
if [ -f "monitoring/joomla-version-audit.php" ] && [ -n "$JOOMLA_SITES" ]; then
|
||||
echo "$JOOMLA_SITES" > /tmp/sites.json
|
||||
php monitoring/joomla-version-audit.php --sites /tmp/sites.json || true
|
||||
echo "### Joomla Version Audit" >> $GITHUB_STEP_SUMMARY
|
||||
rm -f /tmp/sites.json
|
||||
else
|
||||
echo "Joomla audit skipped (no script or JOOMLA_SITES_JSON not configured)"
|
||||
fi
|
||||
env:
|
||||
JOOMLA_SITES: ${{ vars.JOOMLA_SITES_JSON }}
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: MokoPlatform.Universal
|
||||
# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
# PATH: /.mokogitea/workflows/workflow-sync-trigger.yml
|
||||
# VERSION: 01.01.00
|
||||
# BRIEF: Trigger workflow sync to live repos when a PR is merged to main
|
||||
|
||||
name: "Universal: Workflow Sync Trigger"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
name: Sync workflows to live repos
|
||||
runs-on: ubuntu-latest
|
||||
if: >-
|
||||
github.event.pull_request.merged == true &&
|
||||
!contains(github.event.pull_request.title, '[skip sync]')
|
||||
|
||||
steps:
|
||||
- name: Determine platform from repo name
|
||||
id: platform
|
||||
run: |
|
||||
REPO="${{ github.event.repository.name }}"
|
||||
case "$REPO" in
|
||||
Template-Joomla) PLATFORM="joomla" ;;
|
||||
Template-Dolibarr) PLATFORM="dolibarr" ;;
|
||||
Template-Go) PLATFORM="go" ;;
|
||||
Template-MCP) PLATFORM="mcp" ;;
|
||||
Template-Generic) PLATFORM="" ;;
|
||||
*) PLATFORM="" ;;
|
||||
esac
|
||||
echo "platform=$PLATFORM" >> "$GITHUB_OUTPUT"
|
||||
echo "Platform: ${PLATFORM:-all}"
|
||||
|
||||
- name: Clone mokoplatform
|
||||
env:
|
||||
MOKOGITEA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
run: |
|
||||
GITEA_URL="${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}"
|
||||
git clone --depth 1 "${GITEA_URL}/MokoConsulting/mokoplatform.git" /tmp/mokoplatform
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd /tmp/mokoplatform
|
||||
composer install --no-dev --no-interaction --quiet 2>/dev/null || true
|
||||
|
||||
- name: Run workflow sync
|
||||
env:
|
||||
MOKOGITEA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
run: |
|
||||
ARGS="--token ${MOKOGITEA_TOKEN}"
|
||||
ARGS="${ARGS} --org ${{ vars.GITEA_ORG || github.repository_owner }}"
|
||||
ARGS="${ARGS} --phase repos"
|
||||
|
||||
PLATFORM="${{ steps.platform.outputs.platform }}"
|
||||
if [ -n "$PLATFORM" ]; then
|
||||
ARGS="${ARGS} --platform-filter ${PLATFORM}"
|
||||
fi
|
||||
|
||||
php /tmp/mokoplatform/cli/workflow_sync.php ${ARGS}
|
||||
+28
-3
@@ -12,11 +12,20 @@ BRIEF: Release changelog
|
||||
# Changelog
|
||||
## [Unreleased]
|
||||
|
||||
## [09.29.00] --- 2026-06-09
|
||||
### Added
|
||||
- `cli/manifest_integrity.php` — org-wide manifest validation tool (564 lines)
|
||||
- `manifest_detect.php` — detect `display_name`, `target_version`, `php_minimum` fields
|
||||
|
||||
## [09.28.00] --- 2026-06-07
|
||||
### Changed
|
||||
- MokoSuite → MokoSuiteClient rename: updated MCP README reference, composer template, metadata_detect comment
|
||||
- MCP servers extracted from monorepo to standalone `A:/MCP/` directories
|
||||
- All 9 MCP servers published to npm (`@mokoconsulting/`) and Gitea package registry
|
||||
- `.mcp.json` converted from local file paths to `npx -y @mokoconsulting/...@latest`
|
||||
- `NPM_TOKEN` saved as MokoConsulting org secret for CI/CD
|
||||
- Templates: Joomla Makefile and composer.json updated with MokoSuite references
|
||||
|
||||
## [09.27.00] --- 2026-06-07
|
||||
### Removed
|
||||
- `mcp/servers/` directory — all MCP server source moved to `A:/MCP/mcp_*/`
|
||||
|
||||
## [09.26.00] --- 2026-06-07
|
||||
|
||||
@@ -41,3 +50,19 @@ BRIEF: Release changelog
|
||||
|
||||
### Removed
|
||||
- `mcp/servers/mokowaas_api/` — consolidated into mcp-mokowaas-api repo
|
||||
|
||||
## [09.25.00] --- 2026-06-04
|
||||
|
||||
## [09.23] --- 2026-05-31
|
||||
|
||||
## [09.22] --- 2026-05-31
|
||||
|
||||
### Changed
|
||||
- **refactor(cli):** migrate 64 legacy scripts to CliFramework (#235) — all tools in cli/, automation/, maintenance/, deploy/, release/ now extend CliFramework with free --help, --verbose, --quiet, --dry-run, --json, banners, and coloured logging
|
||||
|
||||
### Fixed
|
||||
- fix: auto-detect org/repo in updates_xml_build from manifest and git remote
|
||||
- fix: restore hyphen in version suffixes
|
||||
- fix: release names use standardized format
|
||||
- fix: remove lesser stream copies, each stream updates independently
|
||||
- fix: sort updates.xml entries dev first, stable last
|
||||
|
||||
@@ -6,7 +6,7 @@ DEFGROUP: MokoPlatform.Root
|
||||
INGROUP: MokoPlatform
|
||||
REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
PATH: /README.md
|
||||
VERSION: 09.29.01
|
||||
VERSION: 09.26.02
|
||||
BRIEF: Project overview and documentation
|
||||
-->
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/branch_rename.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Rename a git branch via Gitea API (create new, update PR, delete old)
|
||||
*/
|
||||
|
||||
|
||||
+309
-407
@@ -1,407 +1,309 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* This file is part of a Moko Consulting project.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokocli.CLI
|
||||
* INGROUP: mokocli
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
||||
* PATH: /cli/bulk_workflow_push.php
|
||||
* VERSION: 09.29.01
|
||||
* BRIEF: Push a workflow file to all governed repos via the Gitea Contents API
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
class BulkWorkflowPushCli extends CliFramework
|
||||
{
|
||||
private int $updated = 0;
|
||||
private int $created = 0;
|
||||
private int $skipped = 0;
|
||||
private int $errors = 0;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Push a workflow file to all governed repos via the Gitea Contents API');
|
||||
$this->addArgument('--gitea-url', 'Gitea URL (default: https://git.mokoconsulting.tech)', 'https://git.mokoconsulting.tech');
|
||||
$this->addArgument('--token', 'Gitea API token', '');
|
||||
$this->addArgument('--org', 'Target organization', '');
|
||||
$this->addArgument('--file', 'Local workflow file to push', '');
|
||||
$this->addArgument('--dest', 'Destination path in repos (default: .mokogitea/workflows/<filename>)', '');
|
||||
$this->addArgument('--branch', 'Target branch (default: main)', 'main');
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$giteaUrl = rtrim($this->getArgument('--gitea-url'), '/');
|
||||
$token = $this->getArgument('--token');
|
||||
$org = $this->getArgument('--org');
|
||||
$workflowFile = $this->getArgument('--file');
|
||||
$destPath = $this->getArgument('--dest');
|
||||
$branch = $this->getArgument('--branch');
|
||||
|
||||
if ($token === '') {
|
||||
$this->log('ERROR', '--token is required.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($workflowFile === '') {
|
||||
$this->log('ERROR', '--file is required.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!file_exists($workflowFile)) {
|
||||
$this->log('ERROR', "File not found: {$workflowFile}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($org === '') {
|
||||
$this->log('ERROR', '--org is required.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($destPath === '') {
|
||||
$destPath = '.mokogitea/workflows/' . basename($workflowFile);
|
||||
}
|
||||
|
||||
$localContent = file_get_contents($workflowFile);
|
||||
|
||||
if ($localContent === false) {
|
||||
$this->log('ERROR', "Could not read file: {$workflowFile}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Pushing: {$workflowFile}");
|
||||
$this->log('INFO', " -> {$destPath} (branch: {$branch})");
|
||||
$this->log('INFO', " -> Org: {$org} @ {$giteaUrl}");
|
||||
|
||||
if ($this->dryRun) {
|
||||
$this->log('INFO', '[DRY RUN] No changes will be made.');
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
$repos = $this->fetchOrgRepos($giteaUrl, $token, $org);
|
||||
|
||||
if ($repos === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Found " . count($repos) . " repo(s) in \"{$org}\".");
|
||||
echo "\n";
|
||||
fprintf(STDERR, "%-45s | %s\n", 'Repo', 'Status');
|
||||
fprintf(STDERR, "%s\n", str_repeat('-', 70));
|
||||
|
||||
$encodedContent = base64_encode($localContent);
|
||||
|
||||
foreach ($repos as $repo) {
|
||||
$this->pushToRepo($giteaUrl, $token, $repo, $encodedContent, $localContent, $destPath, $branch);
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
$this->log('INFO', "Done: {$this->created} created, {$this->updated} updated, "
|
||||
. "{$this->skipped} skipped, {$this->errors} error(s).");
|
||||
|
||||
return $this->errors > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
private function pushToRepo(
|
||||
string $giteaUrl,
|
||||
string $token,
|
||||
string $repoFullName,
|
||||
string $encodedContent,
|
||||
string $localContent,
|
||||
string $destPath,
|
||||
string $branch
|
||||
): void {
|
||||
[$owner, $repoName] = explode('/', $repoFullName, 2);
|
||||
|
||||
$existing = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'GET',
|
||||
"/api/v1/repos/{$owner}/{$repoName}/contents/"
|
||||
. "{$destPath}?ref={$branch}"
|
||||
);
|
||||
|
||||
if ($existing['code'] === 200) {
|
||||
$data = json_decode($existing['body'], true);
|
||||
$remoteSha = $data['sha'] ?? '';
|
||||
$remoteContent = base64_decode($data['content'] ?? '');
|
||||
|
||||
if ($remoteContent === $localContent) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'IDENTICAL (skipped)');
|
||||
$this->skipped++;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->dryRun) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'WOULD UPDATE');
|
||||
$this->updated++;
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = json_encode([
|
||||
'content' => $encodedContent,
|
||||
'sha' => $remoteSha,
|
||||
'message' => "chore: sync {$destPath} "
|
||||
. "from mokocli [skip ci]",
|
||||
'branch' => $branch,
|
||||
]);
|
||||
|
||||
$response = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'PUT',
|
||||
"/api/v1/repos/{$owner}/{$repoName}/contents/"
|
||||
. $destPath,
|
||||
$payload
|
||||
);
|
||||
|
||||
if ($response['code'] === 200) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'UPDATED');
|
||||
$this->updated++;
|
||||
} elseif ($response['code'] === 403) {
|
||||
// Branch protection — fall back to chore branch + PR
|
||||
$this->pushViaPR($giteaUrl, $token, $owner, $repoName, $encodedContent, $remoteSha, $destPath, $branch);
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (HTTP {$response['code']})");
|
||||
$this->errors++;
|
||||
}
|
||||
} elseif ($existing['code'] === 404) {
|
||||
if ($this->dryRun) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'WOULD CREATE');
|
||||
$this->created++;
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = json_encode([
|
||||
'content' => $encodedContent,
|
||||
'message' => "chore: add {$destPath} "
|
||||
. "from mokocli [skip ci]",
|
||||
'branch' => $branch,
|
||||
]);
|
||||
|
||||
$response = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'POST',
|
||||
"/api/v1/repos/{$owner}/{$repoName}/contents/"
|
||||
. $destPath,
|
||||
$payload
|
||||
);
|
||||
|
||||
if ($response['code'] === 201) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'CREATED');
|
||||
$this->created++;
|
||||
} elseif ($response['code'] === 403) {
|
||||
$this->pushViaPR($giteaUrl, $token, $owner, $repoName, $encodedContent, '', $destPath, $branch);
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (HTTP {$response['code']})");
|
||||
$this->errors++;
|
||||
}
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (HTTP {$existing['code']})");
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback: push via chore branch + PR when direct push is blocked (403).
|
||||
*/
|
||||
private function pushViaPR(
|
||||
string $giteaUrl,
|
||||
string $token,
|
||||
string $owner,
|
||||
string $repoName,
|
||||
string $encodedContent,
|
||||
string $remoteSha,
|
||||
string $destPath,
|
||||
string $targetBranch
|
||||
): void {
|
||||
$repoFullName = "{$owner}/{$repoName}";
|
||||
$choreBranch = 'chore/workflow-sync';
|
||||
$commitMsg = "chore: sync {$destPath} from mokocli [skip ci]";
|
||||
$apiBase = "/api/v1/repos/{$owner}/{$repoName}";
|
||||
|
||||
// 1. Create chore branch from target
|
||||
$branchPayload = json_encode([
|
||||
'new_branch_name' => $choreBranch,
|
||||
'old_branch_name' => $targetBranch,
|
||||
]);
|
||||
$branchResp = $this->apiRequest($giteaUrl, $token, 'POST', "{$apiBase}/branches", $branchPayload);
|
||||
if ($branchResp['code'] !== 201 && $branchResp['code'] !== 409) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (branch create HTTP {$branchResp['code']})");
|
||||
$this->errors++;
|
||||
return;
|
||||
}
|
||||
|
||||
// If branch already exists (409), get the current SHA of the file on that branch
|
||||
if ($branchResp['code'] === 409 || $remoteSha === '') {
|
||||
$existing = $this->apiRequest($giteaUrl, $token, 'GET',
|
||||
"{$apiBase}/contents/{$destPath}?ref={$choreBranch}");
|
||||
if ($existing['code'] === 200) {
|
||||
$data = json_decode($existing['body'], true);
|
||||
$remoteSha = $data['sha'] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Push file to chore branch
|
||||
$filePayload = ['content' => $encodedContent, 'message' => $commitMsg, 'branch' => $choreBranch];
|
||||
if ($remoteSha !== '') {
|
||||
$filePayload['sha'] = $remoteSha;
|
||||
$method = 'PUT';
|
||||
} else {
|
||||
$method = 'POST';
|
||||
}
|
||||
$fileResp = $this->apiRequest($giteaUrl, $token, $method,
|
||||
"{$apiBase}/contents/{$destPath}", json_encode($filePayload));
|
||||
if ($fileResp['code'] !== 200 && $fileResp['code'] !== 201) {
|
||||
// 422 = file unchanged, still create PR if branch is new
|
||||
if ($fileResp['code'] !== 422) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (file push HTTP {$fileResp['code']})");
|
||||
$this->errors++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Create PR
|
||||
$prPayload = json_encode([
|
||||
'title' => "chore: sync workflows from mokocli",
|
||||
'body' => "Automated workflow sync via bulk_workflow_push.",
|
||||
'head' => $choreBranch,
|
||||
'base' => $targetBranch,
|
||||
]);
|
||||
$prResp = $this->apiRequest($giteaUrl, $token, 'POST', "{$apiBase}/pulls", $prPayload);
|
||||
|
||||
if ($prResp['code'] === 201) {
|
||||
$prData = json_decode($prResp['body'], true);
|
||||
$prNumber = $prData['number'] ?? '?';
|
||||
|
||||
// 4. Auto-merge the PR
|
||||
$mergePayload = json_encode(['Do' => 'merge', 'merge_message_field' => $commitMsg]);
|
||||
$mergeResp = $this->apiRequest($giteaUrl, $token, 'POST',
|
||||
"{$apiBase}/pulls/{$prNumber}/merge", $mergePayload);
|
||||
|
||||
if ($mergeResp['code'] === 200 || $mergeResp['code'] === 204) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "UPDATED (via PR #{$prNumber}, merged)");
|
||||
$this->updated++;
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "PR #{$prNumber} created (merge HTTP {$mergeResp['code']})");
|
||||
$this->updated++;
|
||||
}
|
||||
} elseif ($prResp['code'] === 409 || $prResp['code'] === 422) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'PR already exists');
|
||||
$this->skipped++;
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (PR create HTTP {$prResp['code']})");
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
|
||||
private function fetchOrgRepos(string $giteaUrl, string $token, string $org): ?array
|
||||
{
|
||||
$this->log('INFO', "Fetching repos from org: {$org}");
|
||||
|
||||
$page = 1;
|
||||
$repos = [];
|
||||
|
||||
while (true) {
|
||||
$response = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'GET',
|
||||
"/api/v1/orgs/{$org}/repos?"
|
||||
. "limit=50&page={$page}"
|
||||
);
|
||||
|
||||
if ($response['code'] < 200 || $response['code'] >= 300) {
|
||||
if ($page === 1) {
|
||||
$this->log('ERROR', "Could not fetch repos "
|
||||
. "(HTTP {$response['code']}).");
|
||||
return null;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$data = json_decode($response['body'], true);
|
||||
|
||||
if (!is_array($data) || count($data) === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($data as $repo) {
|
||||
if (!empty($repo['archived'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fullName = $repo['full_name'] ?? '';
|
||||
|
||||
if ($fullName !== '') {
|
||||
$repos[] = $fullName;
|
||||
}
|
||||
}
|
||||
|
||||
$page++;
|
||||
}
|
||||
|
||||
return $repos;
|
||||
}
|
||||
|
||||
private function apiRequest(
|
||||
string $giteaUrl,
|
||||
string $token,
|
||||
string $method,
|
||||
string $endpoint,
|
||||
?string $body = null
|
||||
): array {
|
||||
$url = $giteaUrl . $endpoint;
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
"Authorization: token {$token}",
|
||||
]);
|
||||
|
||||
if ($body !== null) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
}
|
||||
|
||||
$responseBody = curl_exec($ch);
|
||||
$httpCode = (int) curl_getinfo(
|
||||
$ch,
|
||||
CURLINFO_HTTP_CODE
|
||||
);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'body' => "cURL error: {$error}",
|
||||
];
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return ['code' => $httpCode, 'body' => $responseBody];
|
||||
}
|
||||
}
|
||||
|
||||
$app = new BulkWorkflowPushCli();
|
||||
exit($app->execute());
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* This file is part of a Moko Consulting project.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/bulk_workflow_push.php
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Push a workflow file to all governed repos via the Gitea Contents API
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
class BulkWorkflowPushCli extends CliFramework
|
||||
{
|
||||
private int $updated = 0;
|
||||
private int $created = 0;
|
||||
private int $skipped = 0;
|
||||
private int $errors = 0;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Push a workflow file to all governed repos via the Gitea Contents API');
|
||||
$this->addArgument('--gitea-url', 'Gitea URL (default: https://git.mokoconsulting.tech)', 'https://git.mokoconsulting.tech');
|
||||
$this->addArgument('--token', 'Gitea API token', '');
|
||||
$this->addArgument('--org', 'Target organization', '');
|
||||
$this->addArgument('--file', 'Local workflow file to push', '');
|
||||
$this->addArgument('--dest', 'Destination path in repos (default: .mokogitea/workflows/<filename>)', '');
|
||||
$this->addArgument('--branch', 'Target branch (default: main)', 'main');
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$giteaUrl = rtrim($this->getArgument('--gitea-url'), '/');
|
||||
$token = $this->getArgument('--token');
|
||||
$org = $this->getArgument('--org');
|
||||
$workflowFile = $this->getArgument('--file');
|
||||
$destPath = $this->getArgument('--dest');
|
||||
$branch = $this->getArgument('--branch');
|
||||
|
||||
if ($token === '') {
|
||||
$this->log('ERROR', '--token is required.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($workflowFile === '') {
|
||||
$this->log('ERROR', '--file is required.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!file_exists($workflowFile)) {
|
||||
$this->log('ERROR', "File not found: {$workflowFile}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($org === '') {
|
||||
$this->log('ERROR', '--org is required.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($destPath === '') {
|
||||
$destPath = '.mokogitea/workflows/' . basename($workflowFile);
|
||||
}
|
||||
|
||||
$localContent = file_get_contents($workflowFile);
|
||||
|
||||
if ($localContent === false) {
|
||||
$this->log('ERROR', "Could not read file: {$workflowFile}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Pushing: {$workflowFile}");
|
||||
$this->log('INFO', " -> {$destPath} (branch: {$branch})");
|
||||
$this->log('INFO', " -> Org: {$org} @ {$giteaUrl}");
|
||||
|
||||
if ($this->dryRun) {
|
||||
$this->log('INFO', '[DRY RUN] No changes will be made.');
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
$repos = $this->fetchOrgRepos($giteaUrl, $token, $org);
|
||||
|
||||
if ($repos === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Found " . count($repos) . " repo(s) in \"{$org}\".");
|
||||
echo "\n";
|
||||
fprintf(STDERR, "%-45s | %s\n", 'Repo', 'Status');
|
||||
fprintf(STDERR, "%s\n", str_repeat('-', 70));
|
||||
|
||||
$encodedContent = base64_encode($localContent);
|
||||
|
||||
foreach ($repos as $repo) {
|
||||
$this->pushToRepo($giteaUrl, $token, $repo, $encodedContent, $localContent, $destPath, $branch);
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
$this->log('INFO', "Done: {$this->created} created, {$this->updated} updated, "
|
||||
. "{$this->skipped} skipped, {$this->errors} error(s).");
|
||||
|
||||
return $this->errors > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
private function pushToRepo(
|
||||
string $giteaUrl,
|
||||
string $token,
|
||||
string $repoFullName,
|
||||
string $encodedContent,
|
||||
string $localContent,
|
||||
string $destPath,
|
||||
string $branch
|
||||
): void {
|
||||
[$owner, $repoName] = explode('/', $repoFullName, 2);
|
||||
|
||||
$existing = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'GET',
|
||||
"/api/v1/repos/{$owner}/{$repoName}/contents/"
|
||||
. "{$destPath}?ref={$branch}"
|
||||
);
|
||||
|
||||
if ($existing['code'] === 200) {
|
||||
$data = json_decode($existing['body'], true);
|
||||
$remoteSha = $data['sha'] ?? '';
|
||||
$remoteContent = base64_decode($data['content'] ?? '');
|
||||
|
||||
if ($remoteContent === $localContent) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'IDENTICAL (skipped)');
|
||||
$this->skipped++;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->dryRun) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'WOULD UPDATE');
|
||||
$this->updated++;
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = json_encode([
|
||||
'content' => $encodedContent,
|
||||
'sha' => $remoteSha,
|
||||
'message' => "chore: sync {$destPath} "
|
||||
. "from mokoplatform [skip ci]",
|
||||
'branch' => $branch,
|
||||
]);
|
||||
|
||||
$response = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'PUT',
|
||||
"/api/v1/repos/{$owner}/{$repoName}/contents/"
|
||||
. $destPath,
|
||||
$payload
|
||||
);
|
||||
|
||||
if ($response['code'] === 200) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'UPDATED');
|
||||
$this->updated++;
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (HTTP {$response['code']})");
|
||||
$this->errors++;
|
||||
}
|
||||
} elseif ($existing['code'] === 404) {
|
||||
if ($this->dryRun) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'WOULD CREATE');
|
||||
$this->created++;
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = json_encode([
|
||||
'content' => $encodedContent,
|
||||
'message' => "chore: add {$destPath} "
|
||||
. "from mokoplatform [skip ci]",
|
||||
'branch' => $branch,
|
||||
]);
|
||||
|
||||
$response = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'POST',
|
||||
"/api/v1/repos/{$owner}/{$repoName}/contents/"
|
||||
. $destPath,
|
||||
$payload
|
||||
);
|
||||
|
||||
if ($response['code'] === 201) {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, 'CREATED');
|
||||
$this->created++;
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (HTTP {$response['code']})");
|
||||
$this->errors++;
|
||||
}
|
||||
} else {
|
||||
fprintf(STDERR, "%-45s | %s\n", $repoFullName, "ERROR (HTTP {$existing['code']})");
|
||||
$this->errors++;
|
||||
}
|
||||
}
|
||||
|
||||
private function fetchOrgRepos(string $giteaUrl, string $token, string $org): ?array
|
||||
{
|
||||
$this->log('INFO', "Fetching repos from org: {$org}");
|
||||
|
||||
$page = 1;
|
||||
$repos = [];
|
||||
|
||||
while (true) {
|
||||
$response = $this->apiRequest(
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'GET',
|
||||
"/api/v1/orgs/{$org}/repos?"
|
||||
. "limit=50&page={$page}"
|
||||
);
|
||||
|
||||
if ($response['code'] < 200 || $response['code'] >= 300) {
|
||||
if ($page === 1) {
|
||||
$this->log('ERROR', "Could not fetch repos "
|
||||
. "(HTTP {$response['code']}).");
|
||||
return null;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$data = json_decode($response['body'], true);
|
||||
|
||||
if (!is_array($data) || count($data) === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($data as $repo) {
|
||||
if (!empty($repo['archived'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fullName = $repo['full_name'] ?? '';
|
||||
|
||||
if ($fullName !== '') {
|
||||
$repos[] = $fullName;
|
||||
}
|
||||
}
|
||||
|
||||
$page++;
|
||||
}
|
||||
|
||||
return $repos;
|
||||
}
|
||||
|
||||
private function apiRequest(
|
||||
string $giteaUrl,
|
||||
string $token,
|
||||
string $method,
|
||||
string $endpoint,
|
||||
?string $body = null
|
||||
): array {
|
||||
$url = $giteaUrl . $endpoint;
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
"Authorization: token {$token}",
|
||||
]);
|
||||
|
||||
if ($body !== null) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
}
|
||||
|
||||
$responseBody = curl_exec($ch);
|
||||
$httpCode = (int) curl_getinfo(
|
||||
$ch,
|
||||
CURLINFO_HTTP_CODE
|
||||
);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'body' => "cURL error: {$error}",
|
||||
];
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return ['code' => $httpCode, 'body' => $responseBody];
|
||||
}
|
||||
}
|
||||
|
||||
$app = new BulkWorkflowPushCli();
|
||||
exit($app->execute());
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/bulk_workflow_trigger.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Trigger a workflow across multiple repos at once
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/client_dashboard.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Generate unified client dashboard HTML
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/client_inventory.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Discover and list all client-waas repos with their server configuration status
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/client_provision.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Provision a new client environment end-to-end
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/grafana_dashboard.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Manage Grafana dashboards via API
|
||||
*/
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/joomla_build.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Build a Joomla extension ZIP from manifest — all types supported
|
||||
* NOTE: Called by pre-release and auto-release workflows.
|
||||
*/
|
||||
|
||||
@@ -1,507 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/joomla_metadata_validate.php
|
||||
* VERSION: 09.29.01
|
||||
* BRIEF: Validate MokoGitea repo metadata against Joomla extension manifest XML
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
class JoomlaMetadataValidateCli extends CliFramework
|
||||
{
|
||||
/** Joomla element prefix map — must match MokoGitea's cleanJoomlaElement() */
|
||||
private const JOOMLA_PREFIX = [
|
||||
'package' => 'pkg_',
|
||||
'component' => 'com_',
|
||||
'module' => 'mod_',
|
||||
'template' => 'tpl_',
|
||||
'library' => 'lib_',
|
||||
'file' => 'file_',
|
||||
];
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Validate MokoGitea repo metadata against Joomla extension manifest XML');
|
||||
$this->addArgument('--path', 'Repo root path (default: current directory)', '.');
|
||||
$this->addArgument('--token', 'Gitea API token (or GITEA_TOKEN env)', '');
|
||||
$this->addArgument('--org', 'Gitea org', 'MokoConsulting');
|
||||
$this->addArgument('--repo', 'Repo name (auto-detected from git if empty)', '');
|
||||
$this->addArgument('--api-base', 'Gitea API base URL', 'https://git.mokoconsulting.tech/api/v1');
|
||||
$this->addArgument('--ci', 'CI mode: exit 1 on any error', false);
|
||||
$this->addArgument('--json', 'Output as JSON', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = realpath($this->getArgument('--path')) ?: $this->getArgument('--path');
|
||||
$token = $this->getArgument('--token') ?: getenv('GITEA_TOKEN') ?: '';
|
||||
$org = $this->getArgument('--org');
|
||||
$repoName = $this->getArgument('--repo');
|
||||
$apiBase = rtrim($this->getArgument('--api-base'), '/');
|
||||
$ciMode = (bool) $this->getArgument('--ci');
|
||||
$jsonMode = (bool) $this->getArgument('--json');
|
||||
|
||||
if (!is_dir($path)) {
|
||||
$this->log('ERROR', "Path does not exist: {$path}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($repoName === '') {
|
||||
$repoName = $this->detectRepoName($path);
|
||||
}
|
||||
|
||||
// ── Step 1: Find the Joomla extension manifest XML ──────────
|
||||
$joomlaXml = $this->findJoomlaManifest($path);
|
||||
|
||||
if ($joomlaXml === null) {
|
||||
$this->log('ERROR', 'No Joomla extension manifest XML found');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Joomla manifest: {$joomlaXml['path']}");
|
||||
|
||||
// ── Step 2: Load MokoGitea metadata ─────────────────────────
|
||||
$metadata = $this->loadMetadata($path, $org, $repoName, $token, $apiBase);
|
||||
|
||||
if ($metadata === null) {
|
||||
$this->log('ERROR', 'Could not load MokoGitea metadata');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ── Step 3: Compare ─────────────────────────────────────────
|
||||
$results = $this->compare($metadata, $joomlaXml, $path);
|
||||
|
||||
// ── Step 4: Output ──────────────────────────────────────────
|
||||
if ($jsonMode) {
|
||||
echo json_encode([
|
||||
'repo' => $repoName,
|
||||
'results' => $results,
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
$this->printResults($repoName, $results);
|
||||
}
|
||||
|
||||
$errors = count(array_filter($results, fn($r) => $r['status'] === 'error'));
|
||||
|
||||
return ($ciMode && $errors > 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Find Joomla manifest XML
|
||||
// =================================================================
|
||||
|
||||
private function findJoomlaManifest(string $root): ?array
|
||||
{
|
||||
// Search common locations for a Joomla extension manifest
|
||||
$candidates = [];
|
||||
|
||||
// Package manifest: source/pkg_*.xml
|
||||
foreach (glob("{$root}/source/pkg_*.xml") as $file) {
|
||||
$candidates[] = $file;
|
||||
}
|
||||
|
||||
// Component manifest: source/packages/com_*/[name].xml
|
||||
foreach (glob("{$root}/source/packages/com_*/*.xml") as $file) {
|
||||
$basename = basename($file);
|
||||
// Skip access.xml, config.xml, etc.
|
||||
if (in_array($basename, ['access.xml', 'config.xml'], true)) {
|
||||
continue;
|
||||
}
|
||||
$candidates[] = $file;
|
||||
}
|
||||
|
||||
// Direct source/*.xml
|
||||
foreach (glob("{$root}/source/*.xml") as $file) {
|
||||
if (basename($file) !== 'pkg_mokosuitebackup.xml') {
|
||||
// Already caught above
|
||||
}
|
||||
$candidates[] = $file;
|
||||
}
|
||||
|
||||
// src/ fallback
|
||||
foreach (glob("{$root}/src/pkg_*.xml") as $file) {
|
||||
$candidates[] = $file;
|
||||
}
|
||||
|
||||
// Find the first one that has <extension type="...">
|
||||
foreach (array_unique($candidates) as $file) {
|
||||
$content = file_get_contents($file);
|
||||
if ($content === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/<extension\s[^>]*type=["\']([^"\']+)["\']/', $content, $typeMatch)) {
|
||||
$xml = @simplexml_load_string($content);
|
||||
if ($xml === false) {
|
||||
$relPath = str_replace($root . '/', '', $file);
|
||||
$relPath = str_replace($root . '\\', '', $relPath);
|
||||
$this->log('WARN', "Skipping {$relPath}: malformed XML");
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = strtolower($typeMatch[1]);
|
||||
$relPath = str_replace($root . '/', '', $file);
|
||||
$relPath = str_replace($root . '\\', '', $relPath);
|
||||
|
||||
return [
|
||||
'path' => $relPath,
|
||||
'type' => $type,
|
||||
'xml' => $xml,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Load metadata (from API)
|
||||
// =================================================================
|
||||
|
||||
private function loadMetadata(string $root, string $org, string $repoName, string $token, string $apiBase): ?array
|
||||
{
|
||||
if ($token === '') {
|
||||
$this->log('ERROR', 'No API token provided (use --token or set GITEA_TOKEN env var)');
|
||||
return null;
|
||||
}
|
||||
|
||||
$url = "{$apiBase}/repos/{$org}/{$repoName}/metadata";
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
|
||||
'timeout' => 10,
|
||||
'ignore_errors' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = file_get_contents($url, false, $ctx);
|
||||
|
||||
// Extract HTTP status from response headers
|
||||
$httpCode = 0;
|
||||
if (isset($http_response_header[0]) && preg_match('/\d{3}/', $http_response_header[0], $m)) {
|
||||
$httpCode = (int) $m[0];
|
||||
}
|
||||
|
||||
if ($body === false) {
|
||||
$this->log('ERROR', "Failed to connect to {$url} — check network or TLS configuration");
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($httpCode === 404) {
|
||||
$this->log('ERROR', "API endpoint not found: {$url}");
|
||||
$this->log('ERROR', 'Server may need MokoGitea-Fork >= #650 (metadata endpoint rename)');
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($httpCode === 401 || $httpCode === 403) {
|
||||
$this->log('ERROR', "Authentication failed (HTTP {$httpCode}) — check your API token");
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($httpCode >= 400) {
|
||||
$this->log('ERROR', "API returned HTTP {$httpCode}: " . substr($body, 0, 200));
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($body, true);
|
||||
if (!is_array($data)) {
|
||||
$this->log('ERROR', "API returned invalid JSON from {$url}");
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['source'] = 'api';
|
||||
return $data;
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Compare metadata against Joomla manifest
|
||||
// =================================================================
|
||||
|
||||
private function compare(array $metadata, array $joomlaXml, string $root): array
|
||||
{
|
||||
$results = [];
|
||||
$xml = $joomlaXml['xml'];
|
||||
$type = $joomlaXml['type'];
|
||||
|
||||
// 1. Extension type
|
||||
$metaType = $this->normalizeExtensionType(
|
||||
$metadata['extension_type'] ?? $metadata['package_type'] ?? ''
|
||||
);
|
||||
$results[] = [
|
||||
'field' => 'extension_type',
|
||||
'metadata' => $metaType,
|
||||
'joomla' => $type,
|
||||
'status' => ($metaType === $type) ? 'ok' : 'error',
|
||||
'message' => ($metaType === $type)
|
||||
? "matches <extension type=\"{$type}\">"
|
||||
: "metadata has \"{$metaType}\" but Joomla manifest has \"{$type}\"",
|
||||
];
|
||||
|
||||
// 2. Element name
|
||||
$metaName = strtolower($metadata['name'] ?? '');
|
||||
$metaElement = $this->deriveElement($metaType, $metaName);
|
||||
$joomlaElement = $this->extractJoomlaElement($xml, $type);
|
||||
|
||||
$elementMatch = ($metaElement === $joomlaElement);
|
||||
$results[] = [
|
||||
'field' => 'element',
|
||||
'metadata' => $metaElement,
|
||||
'joomla' => $joomlaElement,
|
||||
'status' => $elementMatch ? 'ok' : 'error',
|
||||
'message' => $elementMatch
|
||||
? "derived correctly"
|
||||
: "metadata derives \"{$metaElement}\" but Joomla uses \"{$joomlaElement}\"",
|
||||
];
|
||||
|
||||
// 3. Version
|
||||
$metaVersion = $metadata['version'] ?? '';
|
||||
$joomlaVersion = (string) ($xml->version ?? '');
|
||||
|
||||
if ($metaVersion !== '' && $joomlaVersion !== '') {
|
||||
// Strip dev/rc suffixes for comparison (CI bumps these)
|
||||
$metaBase = preg_replace('/-(dev|rc|alpha|beta)\d*$/', '', $metaVersion);
|
||||
$joomlaBase = preg_replace('/-(dev|rc|alpha|beta)\d*$/', '', $joomlaVersion);
|
||||
$versionMatch = ($metaBase === $joomlaBase);
|
||||
|
||||
$results[] = [
|
||||
'field' => 'version',
|
||||
'metadata' => $metaVersion,
|
||||
'joomla' => $joomlaVersion,
|
||||
'status' => $versionMatch ? 'ok' : 'warn',
|
||||
'message' => $versionMatch
|
||||
? 'matches (base version)'
|
||||
: "metadata has \"{$metaVersion}\" but Joomla has \"{$joomlaVersion}\"",
|
||||
];
|
||||
}
|
||||
|
||||
// 4. PHP minimum (from composer.json)
|
||||
$composerPhp = $this->readComposerPhpRequirement($root);
|
||||
$metaPhp = $metadata['php_minimum'] ?? '';
|
||||
|
||||
if ($composerPhp !== '' && $metaPhp !== '') {
|
||||
$phpMatch = ($metaPhp === $composerPhp);
|
||||
$results[] = [
|
||||
'field' => 'php_minimum',
|
||||
'metadata' => $metaPhp,
|
||||
'joomla' => $composerPhp . ' (composer.json)',
|
||||
'status' => $phpMatch ? 'ok' : 'warn',
|
||||
'message' => $phpMatch
|
||||
? 'matches composer.json'
|
||||
: "metadata has \"{$metaPhp}\" but composer.json requires \"{$composerPhp}\"",
|
||||
];
|
||||
}
|
||||
|
||||
// 5. Description
|
||||
$metaDesc = $metadata['description'] ?? '';
|
||||
$joomlaDesc = (string) ($xml->description ?? '');
|
||||
|
||||
// Joomla descriptions are often language keys, skip those
|
||||
if ($metaDesc !== '' && $joomlaDesc !== '' && !str_starts_with($joomlaDesc, 'COM_') && !str_starts_with($joomlaDesc, 'PKG_')) {
|
||||
$descMatch = ($metaDesc === $joomlaDesc);
|
||||
$results[] = [
|
||||
'field' => 'description',
|
||||
'metadata' => substr($metaDesc, 0, 60) . (strlen($metaDesc) > 60 ? '...' : ''),
|
||||
'joomla' => substr($joomlaDesc, 0, 60) . (strlen($joomlaDesc) > 60 ? '...' : ''),
|
||||
'status' => $descMatch ? 'ok' : 'info',
|
||||
'message' => $descMatch ? 'matches' : 'descriptions differ (informational)',
|
||||
];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Helpers
|
||||
// =================================================================
|
||||
|
||||
/**
|
||||
* Normalize extension_type — map MokoGitea types to Joomla types.
|
||||
*/
|
||||
private function normalizeExtensionType(string $type): string
|
||||
{
|
||||
return match (strtolower($type)) {
|
||||
'joomla-extension' => 'package', // legacy mapping
|
||||
default => strtolower($type),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive the Joomla element name from type + name.
|
||||
* Replicates MokoGitea's cleanJoomlaElement() + prefix logic.
|
||||
*/
|
||||
private function deriveElement(string $type, string $name): string
|
||||
{
|
||||
// Clean: lowercase, strip non-alphanumeric except . _ -
|
||||
$clean = strtolower($name);
|
||||
$clean = preg_replace('/[^a-z0-9._-]/', '', $clean);
|
||||
|
||||
$prefix = self::JOOMLA_PREFIX[$type] ?? '';
|
||||
|
||||
return $prefix . $clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the element name from a Joomla manifest XML.
|
||||
* Follows the same logic as Joomla's InstallerAdapter::getElement().
|
||||
*/
|
||||
private function extractJoomlaElement(\SimpleXMLElement $xml, string $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case 'package':
|
||||
$packagename = (string) ($xml->packagename ?? '');
|
||||
if ($packagename !== '') {
|
||||
return 'pkg_' . strtolower(preg_replace('/[^a-zA-Z0-9._-]/', '', $packagename));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'component':
|
||||
$element = (string) ($xml->element ?? '');
|
||||
if ($element !== '') {
|
||||
$element = strtolower($element);
|
||||
return str_starts_with($element, 'com_') ? $element : 'com_' . $element;
|
||||
}
|
||||
$name = (string) ($xml->name ?? '');
|
||||
$name = strtolower(preg_replace('/[^a-zA-Z0-9._-]/', '', $name));
|
||||
return str_starts_with($name, 'com_') ? $name : 'com_' . $name;
|
||||
|
||||
case 'module':
|
||||
$element = (string) ($xml->element ?? '');
|
||||
if ($element !== '') {
|
||||
return strtolower($element);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'plugin':
|
||||
// Plugins derive element from the file attribute
|
||||
if (isset($xml->files)) {
|
||||
foreach ($xml->files->children() as $file) {
|
||||
$plugin = (string) ($file->attributes()->plugin ?? '');
|
||||
if ($plugin !== '') {
|
||||
return strtolower($plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'library':
|
||||
$libname = (string) ($xml->libraryname ?? '');
|
||||
if ($libname !== '') {
|
||||
return strtolower($libname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallback: use <name> tag
|
||||
$name = (string) ($xml->name ?? '');
|
||||
return strtolower(preg_replace('/[^a-zA-Z0-9._-]/', '', $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read PHP version requirement from composer.json.
|
||||
*/
|
||||
private function readComposerPhpRequirement(string $root): string
|
||||
{
|
||||
$composerFile = "{$root}/composer.json";
|
||||
|
||||
if (!is_file($composerFile)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents($composerFile), true);
|
||||
|
||||
if (!is_array($data)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$phpReq = $data['require']['php'] ?? '';
|
||||
|
||||
// Extract version number from constraint like ">=8.1"
|
||||
if (preg_match('/(\d+\.\d+)/', $phpReq, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function detectRepoName(string $root): string
|
||||
{
|
||||
$gitConfig = "{$root}/.git/config";
|
||||
|
||||
if (!file_exists($gitConfig)) {
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
$content = file_get_contents($gitConfig);
|
||||
|
||||
if (preg_match('/url\s*=\s*.*\/([^\/\s]+?)(?:\.git)?\s*$/m', $content, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Output
|
||||
// =================================================================
|
||||
|
||||
private function printResults(string $repoName, array $results): void
|
||||
{
|
||||
$errors = count(array_filter($results, fn($r) => $r['status'] === 'error'));
|
||||
$warns = count(array_filter($results, fn($r) => $r['status'] === 'warn'));
|
||||
$oks = count(array_filter($results, fn($r) => $r['status'] === 'ok'));
|
||||
|
||||
$this->log('INFO', "Validating {$repoName} Joomla metadata...\n");
|
||||
|
||||
foreach ($results as $r) {
|
||||
$icon = match ($r['status']) {
|
||||
'ok' => "\xE2\x9C\x93", // ✓
|
||||
'error' => "\xE2\x9C\x97", // ✗
|
||||
'warn' => "\xE2\x9A\xA0", // ⚠
|
||||
default => "\xE2\x84\xB9", // ℹ
|
||||
};
|
||||
|
||||
$line = sprintf(
|
||||
" %s %-16s %s",
|
||||
$icon,
|
||||
$r['field'],
|
||||
$r['message']
|
||||
);
|
||||
|
||||
$this->log(
|
||||
match ($r['status']) {
|
||||
'error' => 'ERROR',
|
||||
'warn' => 'WARN',
|
||||
'ok' => 'OK',
|
||||
default => 'INFO',
|
||||
},
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
||||
if ($errors > 0) {
|
||||
$this->log('ERROR', "{$errors} error(s) — update delivery will fail");
|
||||
} elseif ($warns > 0) {
|
||||
$this->log('WARN', "All critical checks passed, {$warns} warning(s)");
|
||||
} else {
|
||||
$this->log('OK', "All {$oks} checks passed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$app = new JoomlaMetadataValidateCli();
|
||||
exit($app->execute());
|
||||
+2
-747
@@ -1,749 +1,4 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_detect.php
|
||||
* VERSION: 09.29.01
|
||||
* BRIEF: Auto-detect manifest fields from source files and optionally push to API
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\{CliFramework, SourceResolver};
|
||||
|
||||
class ManifestDetectCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Auto-detect manifest fields from source files');
|
||||
$this->addArgument('--path', 'Repository root path', '.');
|
||||
$this->addArgument('--json', 'Output as JSON', false);
|
||||
$this->addArgument('--diff', 'Show diff against current manifest API values', false);
|
||||
$this->addArgument('--update', 'Push detected fields to manifest API', false);
|
||||
$this->addArgument('--token', 'Gitea API token (or GITEA_TOKEN env)', '');
|
||||
$this->addArgument('--api-base', 'Gitea API base URL', 'https://git.mokoconsulting.tech/api/v1');
|
||||
$this->addArgument('--org', 'Gitea org', 'MokoConsulting');
|
||||
$this->addArgument('--repo', 'Gitea repo name (auto-detected from remote if empty)', '');
|
||||
$this->addArgument('--github-output', 'Append fields to $GITHUB_OUTPUT', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$jsonMode = (bool) $this->getArgument('--json');
|
||||
$diffMode = (bool) $this->getArgument('--diff');
|
||||
$updateMode = (bool) $this->getArgument('--update');
|
||||
$ghOutput = (bool) $this->getArgument('--github-output');
|
||||
$token = $this->getArgument('--token') ?: getenv('GITEA_TOKEN') ?: '';
|
||||
$apiBase = rtrim($this->getArgument('--api-base'), '/');
|
||||
$org = $this->getArgument('--org');
|
||||
$repoName = $this->getArgument('--repo');
|
||||
|
||||
$root = realpath($path) ?: $path;
|
||||
|
||||
if (!is_dir($root)) {
|
||||
$this->log('ERROR', "Path does not exist: {$path}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Auto-detect repo name from git remote
|
||||
if ($repoName === '') {
|
||||
$repoName = $this->detectRepoName($root);
|
||||
}
|
||||
|
||||
// ── Detect all fields ───────────────────────────────────────
|
||||
$detected = $this->detectAll($root, $repoName);
|
||||
|
||||
// ── Warn about missing fields ────────────────────────────────
|
||||
$expected = ['platform', 'name', 'version', 'package_type', 'language', 'entry_point'];
|
||||
foreach ($expected as $field) {
|
||||
if (!isset($detected[$field]) || $detected[$field] === '') {
|
||||
$this->log('WARN', "Could not detect: {$field}");
|
||||
}
|
||||
}
|
||||
|
||||
// ── Output ──────────────────────────────────────────────────
|
||||
if ($diffMode || $updateMode) {
|
||||
if ($token === '') {
|
||||
$this->log('ERROR', 'API token required for --diff/--update (use --token or GITEA_TOKEN env)');
|
||||
return 1;
|
||||
}
|
||||
if ($repoName === '') {
|
||||
$this->log('ERROR', 'Could not determine repo name (use --repo)');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$current = $this->fetchManifest($apiBase, $org, $repoName, $token);
|
||||
if ($current === null) {
|
||||
$this->log('ERROR', 'Failed to fetch current manifest from API');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$changes = $this->computeDiff($current, $detected);
|
||||
|
||||
if ($diffMode) {
|
||||
if (empty($changes)) {
|
||||
$this->log('INFO', 'No differences — manifest matches source');
|
||||
} else {
|
||||
$this->sectionHeader('Manifest Drift');
|
||||
foreach ($changes as $field => $info) {
|
||||
$this->log('WARN', sprintf(
|
||||
'%-20s API: %-30s Detected: %s',
|
||||
$field,
|
||||
$info['current'] === '' ? '(empty)' : $info['current'],
|
||||
$info['detected']
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($updateMode) {
|
||||
if (empty($changes)) {
|
||||
$this->log('INFO', 'Nothing to update');
|
||||
} else {
|
||||
$update = array_map(fn($i) => $i['detected'], $changes);
|
||||
$ok = $this->pushManifest($apiBase, $org, $repoName, $token, $current, $update);
|
||||
if ($ok) {
|
||||
$this->log('OK', 'Updated ' . count($update) . ' field(s): ' . implode(', ', array_keys($update)));
|
||||
} else {
|
||||
$this->log('ERROR', 'Failed to push manifest update');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($ghOutput) {
|
||||
$outputFile = getenv('GITHUB_OUTPUT');
|
||||
$lines = [];
|
||||
foreach ($detected as $k => $v) {
|
||||
$envKey = str_replace('-', '_', $k);
|
||||
$lines[] = "{$envKey}={$v}";
|
||||
}
|
||||
if ($outputFile !== false && $outputFile !== '') {
|
||||
file_put_contents($outputFile, implode("\n", $lines) . "\n", FILE_APPEND);
|
||||
$this->log('INFO', 'Wrote ' . count($detected) . ' fields to GITHUB_OUTPUT');
|
||||
} else {
|
||||
$this->log('WARN', 'GITHUB_OUTPUT not set — printing to stdout instead');
|
||||
echo implode("\n", $lines) . "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($jsonMode) {
|
||||
echo json_encode($detected, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
foreach ($detected as $k => $v) {
|
||||
echo "{$k}={$v}\n";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Detection engine
|
||||
// =====================================================================
|
||||
|
||||
private function detectAll(string $root, string $repoName): array
|
||||
{
|
||||
$platform = $this->detectPlatform($root);
|
||||
|
||||
$fields = [
|
||||
'platform' => $platform,
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'version' => '',
|
||||
'element_name' => '',
|
||||
'package_type' => '',
|
||||
'language' => '',
|
||||
'entry_point' => '',
|
||||
'license_spdx' => '',
|
||||
'display_name' => '',
|
||||
'target_version' => '',
|
||||
'php_minimum' => '',
|
||||
];
|
||||
|
||||
switch ($platform) {
|
||||
case 'joomla':
|
||||
$this->detectJoomla($root, $repoName, $fields);
|
||||
break;
|
||||
case 'dolibarr':
|
||||
$this->detectDolibarr($root, $repoName, $fields);
|
||||
break;
|
||||
case 'go':
|
||||
$this->detectGo($root, $repoName, $fields);
|
||||
break;
|
||||
case 'mcp':
|
||||
$this->detectNode($root, $repoName, $fields);
|
||||
break;
|
||||
case 'node':
|
||||
$this->detectNode($root, $repoName, $fields);
|
||||
$fields['platform'] = 'node';
|
||||
break;
|
||||
default:
|
||||
$this->detectGeneric($root, $repoName, $fields);
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallbacks
|
||||
if ($fields['name'] === '') {
|
||||
$fields['name'] = $repoName ?: basename($root);
|
||||
}
|
||||
if ($fields['entry_point'] === '') {
|
||||
$fields['entry_point'] = $this->detectEntryPoint($root);
|
||||
}
|
||||
if ($fields['license_spdx'] === '') {
|
||||
$fields['license_spdx'] = $this->detectLicense($root);
|
||||
}
|
||||
// description: only from platform-specific source, never guessed
|
||||
|
||||
// Strip empty values
|
||||
return array_filter($fields, fn($v) => $v !== '');
|
||||
}
|
||||
|
||||
// ── Platform detection ──────────────────────────────────────────
|
||||
|
||||
private function detectPlatform(string $root): string
|
||||
{
|
||||
// Joomla: look for pkg_*.xml or extension XML in source dirs
|
||||
$joomlaXmls = array_merge(
|
||||
SourceResolver::globSource($root, 'pkg_*.xml'),
|
||||
glob("{$root}/pkg_*.xml") ?: []
|
||||
);
|
||||
if (!empty($joomlaXmls)) {
|
||||
return 'joomla';
|
||||
}
|
||||
|
||||
// Check source dirs for any Joomla extension XML
|
||||
foreach (SourceResolver::globSource($root, '*.xml') as $xmlFile) {
|
||||
$content = file_get_contents($xmlFile);
|
||||
if (strpos($content, '<extension') !== false) {
|
||||
return 'joomla';
|
||||
}
|
||||
}
|
||||
|
||||
// Dolibarr: mod*.class.php with DolibarrModules
|
||||
$modFiles = array_merge(
|
||||
SourceResolver::globSource($root, 'core/modules/mod*.class.php'),
|
||||
glob("{$root}/core/modules/mod*.class.php") ?: []
|
||||
);
|
||||
foreach ($modFiles as $file) {
|
||||
if (strpos(file_get_contents($file), 'DolibarrModules') !== false) {
|
||||
return 'dolibarr';
|
||||
}
|
||||
}
|
||||
|
||||
// Go
|
||||
if (file_exists("{$root}/go.mod")) {
|
||||
return 'go';
|
||||
}
|
||||
|
||||
// MCP: package.json with mcp-related content
|
||||
if (file_exists("{$root}/package.json")) {
|
||||
$pkg = json_decode(file_get_contents("{$root}/package.json"), true) ?? [];
|
||||
$deps = array_merge(
|
||||
array_keys($pkg['dependencies'] ?? []),
|
||||
array_keys($pkg['devDependencies'] ?? [])
|
||||
);
|
||||
foreach ($deps as $dep) {
|
||||
if (strpos($dep, '@modelcontextprotocol/') === 0 || $dep === '@anthropic/mcp-sdk') {
|
||||
return 'mcp';
|
||||
}
|
||||
}
|
||||
return 'node';
|
||||
}
|
||||
|
||||
// Python
|
||||
if (file_exists("{$root}/pyproject.toml") || file_exists("{$root}/setup.py")) {
|
||||
return 'python';
|
||||
}
|
||||
|
||||
return 'generic';
|
||||
}
|
||||
|
||||
// ── Joomla ──────────────────────────────────────────────────────
|
||||
|
||||
private function detectJoomla(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['language'] = 'PHP';
|
||||
|
||||
// Find the primary extension manifest XML
|
||||
$extManifest = $this->findJoomlaManifest($root);
|
||||
if ($extManifest === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xml = file_get_contents($extManifest);
|
||||
|
||||
// Type
|
||||
$extType = '';
|
||||
if (preg_match('/type="([^"]*)"/', $xml, $m)) {
|
||||
$extType = $m[1];
|
||||
}
|
||||
$fields['package_type'] = $extType;
|
||||
|
||||
// Element name
|
||||
$element = '';
|
||||
if (preg_match('/<element>([^<]+)<\/element>/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($element === '' && preg_match('/module="([^"]*)"/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($element === '' && preg_match('/plugin="([^"]*)"/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($extType === 'package' && preg_match('/<packagename>([^<]+)<\/packagename>/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($element === '') {
|
||||
$element = strtolower(basename($extManifest, '.xml'));
|
||||
}
|
||||
|
||||
// Ensure element has type prefix (API stores full element_name like pkg_mokosuite)
|
||||
$prefixMap = [
|
||||
'package' => 'pkg_', 'component' => 'com_', 'module' => 'mod_',
|
||||
'template' => 'tpl_', 'library' => 'lib_', 'file' => 'file_',
|
||||
];
|
||||
if (isset($prefixMap[$extType])) {
|
||||
$prefix = $prefixMap[$extType];
|
||||
// Only add prefix if not already present (check all known prefixes)
|
||||
$hasPrefix = false;
|
||||
foreach ($prefixMap as $p) {
|
||||
if (strpos($element, $p) === 0) { $hasPrefix = true; break; }
|
||||
}
|
||||
if (strpos($element, 'plg_') === 0) { $hasPrefix = true; }
|
||||
if (!$hasPrefix) {
|
||||
$element = $prefix . $element;
|
||||
}
|
||||
} elseif ($extType === 'plugin') {
|
||||
$folder = '';
|
||||
if (preg_match('/group="([^"]*)"/', $xml, $gm)) {
|
||||
$folder = $gm[1];
|
||||
}
|
||||
if ($folder !== '' && strpos($element, 'plg_') !== 0) {
|
||||
$element = "plg_{$folder}_" . $element;
|
||||
}
|
||||
}
|
||||
$fields['element_name'] = $element;
|
||||
|
||||
// Name
|
||||
if (preg_match('/<name>([^<]+)<\/name>/', $xml, $m)) {
|
||||
$fields['name'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// Version
|
||||
if (preg_match('/<version>([^<]+)<\/version>/', $xml, $m)) {
|
||||
$fields['version'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// Description
|
||||
if (preg_match('/<description>([^<]+)<\/description>/', $xml, $m)) {
|
||||
$desc = trim($m[1]);
|
||||
// Skip language string keys like COM_MOKOSUITE_DESCRIPTION
|
||||
if (strpos($desc, '_') === false || strlen($desc) > 60) {
|
||||
$fields['description'] = $desc;
|
||||
}
|
||||
}
|
||||
|
||||
// Display name for update feeds
|
||||
if (!empty($fields['name'])) {
|
||||
$name = $fields['name'];
|
||||
// If name already has "Type - " prefix, use as-is
|
||||
if (preg_match('/^(Package|Component|Module|Plugin|Template|Library)\s*-\s*/i', $name)) {
|
||||
$fields['display_name'] = $name;
|
||||
} elseif (!empty($extType)) {
|
||||
$fields['display_name'] = ucfirst($extType) . ' - ' . $name;
|
||||
}
|
||||
}
|
||||
|
||||
// Target Joomla version
|
||||
if (preg_match('/<targetplatform\s[^>]*version="([^"]+)"/', $xml, $m)) {
|
||||
$fields['target_version'] = trim($m[1]);
|
||||
} else {
|
||||
// Default for Joomla 5/6
|
||||
$fields['target_version'] = '(5|6)\..*';
|
||||
}
|
||||
|
||||
// PHP minimum
|
||||
if (preg_match('/<php_minimum>([^<]+)<\/php_minimum>/', $xml, $m)) {
|
||||
$fields['php_minimum'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// License
|
||||
if (preg_match('/<license>([^<]+)<\/license>/', $xml, $m)) {
|
||||
$fields['license_spdx'] = $this->normalizeLicense(trim($m[1]));
|
||||
}
|
||||
}
|
||||
|
||||
private function findJoomlaManifest(string $root): ?string
|
||||
{
|
||||
// Priority: pkg_*.xml (package manifest)
|
||||
$pkgXmls = array_merge(
|
||||
SourceResolver::globSource($root, 'pkg_*.xml'),
|
||||
glob("{$root}/pkg_*.xml") ?: []
|
||||
);
|
||||
if (!empty($pkgXmls)) {
|
||||
return $pkgXmls[0];
|
||||
}
|
||||
|
||||
// Any extension XML in source dir
|
||||
foreach (SourceResolver::globSource($root, '*.xml') as $file) {
|
||||
$content = file_get_contents($file);
|
||||
if (strpos($content, '<extension') !== false) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Root level
|
||||
foreach (glob("{$root}/*.xml") ?: [] as $file) {
|
||||
$content = file_get_contents($file);
|
||||
if (strpos($content, '<extension') !== false) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Dolibarr ────────────────────────────────────────────────────
|
||||
|
||||
private function detectDolibarr(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['language'] = 'PHP';
|
||||
$fields['package_type'] = 'dolibarr-module';
|
||||
|
||||
$modFile = $this->findDolibarrModule($root);
|
||||
if ($modFile === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = file_get_contents($modFile);
|
||||
|
||||
// Element name from class file
|
||||
$modBasename = basename($modFile, '.class.php');
|
||||
$fields['element_name'] = strtolower(preg_replace('/^mod/', '', $modBasename));
|
||||
|
||||
// Name
|
||||
if (preg_match('/\$this->name\s*=\s*[\'"]([^\'"]+)[\'"]/', $content, $m)) {
|
||||
$fields['name'] = $m[1];
|
||||
}
|
||||
|
||||
// Version
|
||||
if (preg_match('/\$this->version\s*=\s*[\'"]([^\'"]+)[\'"]/', $content, $m)) {
|
||||
$fields['version'] = $m[1];
|
||||
}
|
||||
|
||||
// Description
|
||||
if (preg_match('/\$this->description\s*=\s*[\'"]([^\'"]+)[\'"]/', $content, $m)) {
|
||||
$desc = $m[1];
|
||||
if (strpos($desc, '$') === false) {
|
||||
$fields['description'] = $desc;
|
||||
}
|
||||
}
|
||||
|
||||
// License
|
||||
if (preg_match('/SPDX-License-Identifier:\s*(\S+)/', $content, $m)) {
|
||||
$fields['license_spdx'] = $m[1];
|
||||
}
|
||||
}
|
||||
|
||||
private function findDolibarrModule(string $root): ?string
|
||||
{
|
||||
$candidates = array_merge(
|
||||
SourceResolver::globSource($root, 'core/modules/mod*.class.php'),
|
||||
glob("{$root}/core/modules/mod*.class.php") ?: []
|
||||
);
|
||||
foreach ($candidates as $file) {
|
||||
if (strpos(file_get_contents($file), 'DolibarrModules') !== false) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Go ──────────────────────────────────────────────────────────
|
||||
|
||||
private function detectGo(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['language'] = 'Go';
|
||||
$fields['package_type'] = 'application';
|
||||
$fields['entry_point'] = './';
|
||||
|
||||
$goMod = "{$root}/go.mod";
|
||||
if (!file_exists($goMod)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = file_get_contents($goMod);
|
||||
|
||||
// Module path → name
|
||||
if (preg_match('/^module\s+(\S+)/m', $content, $m)) {
|
||||
$modulePath = $m[1];
|
||||
$parts = explode('/', $modulePath);
|
||||
$fields['name'] = end($parts);
|
||||
}
|
||||
|
||||
// Go version
|
||||
if (preg_match('/^go\s+(\S+)/m', $content, $m)) {
|
||||
// This is Go language version, not the project version
|
||||
// Project version comes from git tags or source files
|
||||
}
|
||||
|
||||
// License
|
||||
$fields['license_spdx'] = $this->detectLicense($root);
|
||||
}
|
||||
|
||||
// ── Node / MCP ──────────────────────────────────────────────────
|
||||
|
||||
private function detectNode(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$pkgFile = "{$root}/package.json";
|
||||
if (!file_exists($pkgFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pkg = json_decode(file_get_contents($pkgFile), true) ?? [];
|
||||
|
||||
$fields['name'] = $pkg['name'] ?? '';
|
||||
// Strip npm scope
|
||||
if (strpos($fields['name'], '/') !== false) {
|
||||
$fields['name'] = explode('/', $fields['name'])[1];
|
||||
}
|
||||
|
||||
$fields['version'] = $pkg['version'] ?? '';
|
||||
$fields['description'] = $pkg['description'] ?? '';
|
||||
$fields['license_spdx'] = $pkg['license'] ?? '';
|
||||
|
||||
// Language detection
|
||||
if (file_exists("{$root}/tsconfig.json")) {
|
||||
$fields['language'] = 'TypeScript';
|
||||
} else {
|
||||
$fields['language'] = 'JavaScript';
|
||||
}
|
||||
|
||||
// Package type
|
||||
$deps = array_merge(
|
||||
array_keys($pkg['dependencies'] ?? []),
|
||||
array_keys($pkg['devDependencies'] ?? [])
|
||||
);
|
||||
$isMcp = false;
|
||||
foreach ($deps as $dep) {
|
||||
if (strpos($dep, '@modelcontextprotocol/') === 0 || $dep === '@anthropic/mcp-sdk') {
|
||||
$isMcp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fields['package_type'] = $isMcp ? 'mcp-server' : 'application';
|
||||
|
||||
// Entry point
|
||||
if (file_exists("{$root}/dist")) {
|
||||
$fields['entry_point'] = 'dist/';
|
||||
} elseif (file_exists("{$root}/src")) {
|
||||
$fields['entry_point'] = 'src/';
|
||||
} else {
|
||||
$fields['entry_point'] = './';
|
||||
}
|
||||
}
|
||||
|
||||
// ── Generic ─────────────────────────────────────────────────────
|
||||
|
||||
private function detectGeneric(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['package_type'] = 'generic';
|
||||
|
||||
// Try to detect language from file extensions
|
||||
$fields['language'] = $this->detectLanguageFromFiles($root);
|
||||
$fields['license_spdx'] = $this->detectLicense($root);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Shared detection helpers
|
||||
// =====================================================================
|
||||
|
||||
private function detectEntryPoint(string $root): string
|
||||
{
|
||||
$abs = SourceResolver::resolveAbsolute($root);
|
||||
if ($abs !== null) {
|
||||
return basename($abs) . '/';
|
||||
}
|
||||
if (is_dir("{$root}/dist")) return 'dist/';
|
||||
if (is_dir("{$root}/src")) return 'src/';
|
||||
return './';
|
||||
}
|
||||
|
||||
private function detectLicense(string $root): string
|
||||
{
|
||||
// Check LICENSE file
|
||||
foreach (['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'COPYING'] as $name) {
|
||||
$file = "{$root}/{$name}";
|
||||
if (!file_exists($file)) continue;
|
||||
$content = file_get_contents($file);
|
||||
|
||||
// SPDX header
|
||||
if (preg_match('/SPDX-License-Identifier:\s*(\S+)/', $content, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
// Common license patterns
|
||||
if (strpos($content, 'GNU GENERAL PUBLIC LICENSE') !== false) {
|
||||
if (strpos($content, 'Version 3') !== false) return 'GPL-3.0-or-later';
|
||||
if (strpos($content, 'Version 2') !== false) return 'GPL-2.0-or-later';
|
||||
}
|
||||
if (strpos($content, 'MIT License') !== false) return 'MIT';
|
||||
if (strpos($content, 'Apache License') !== false && strpos($content, 'Version 2.0') !== false) return 'Apache-2.0';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
private function detectLanguageFromFiles(string $root): string
|
||||
{
|
||||
$counts = ['PHP' => 0, 'Go' => 0, 'TypeScript' => 0, 'JavaScript' => 0, 'Python' => 0, 'Shell' => 0];
|
||||
|
||||
$extensions = [
|
||||
'php' => 'PHP', 'go' => 'Go', 'ts' => 'TypeScript',
|
||||
'js' => 'JavaScript', 'py' => 'Python', 'sh' => 'Shell',
|
||||
];
|
||||
|
||||
// Quick scan: only check top two levels
|
||||
foreach (glob("{$root}/*") ?: [] as $item) {
|
||||
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||
if (isset($extensions[$ext])) {
|
||||
$counts[$extensions[$ext]]++;
|
||||
}
|
||||
if (is_dir($item) && basename($item)[0] !== '.') {
|
||||
foreach (glob("{$item}/*") ?: [] as $subItem) {
|
||||
$ext = pathinfo($subItem, PATHINFO_EXTENSION);
|
||||
if (isset($extensions[$ext])) {
|
||||
$counts[$extensions[$ext]]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arsort($counts);
|
||||
$top = key($counts);
|
||||
return $counts[$top] > 0 ? $top : '';
|
||||
}
|
||||
|
||||
private function normalizeLicense(string $license): string
|
||||
{
|
||||
$lower = strtolower($license);
|
||||
$isGpl = strpos($lower, 'gpl') !== false || strpos($lower, 'general public license') !== false;
|
||||
if ($isGpl && strpos($lower, '3') !== false) return 'GPL-3.0-or-later';
|
||||
if ($isGpl && strpos($lower, '2') !== false) return 'GPL-2.0-or-later';
|
||||
if ($lower === 'mit' || strpos($lower, 'mit license') !== false) return 'MIT';
|
||||
if (strpos($lower, 'apache') !== false) return 'Apache-2.0';
|
||||
return $license;
|
||||
}
|
||||
|
||||
private function detectRepoName(string $root): string
|
||||
{
|
||||
$gitConfig = "{$root}/.git/config";
|
||||
if (!file_exists($gitConfig)) {
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
$content = file_get_contents($gitConfig);
|
||||
if (preg_match('/url\s*=\s*.*\/([^\/\s]+?)(?:\.git)?\s*$/m', $content, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// API interaction
|
||||
// =====================================================================
|
||||
|
||||
private function fetchManifest(string $apiBase, string $org, string $repo, string $token): ?array
|
||||
{
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) return null;
|
||||
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
private function computeDiff(array $current, array $detected): array
|
||||
{
|
||||
// Map detected keys to API keys (underscores match)
|
||||
$changes = [];
|
||||
|
||||
foreach ($detected as $key => $value) {
|
||||
$apiKey = $key;
|
||||
$currentVal = $current[$apiKey] ?? '';
|
||||
|
||||
// Only flag as changed if detected value is non-empty and differs
|
||||
if ($value !== '' && $value !== $currentVal) {
|
||||
// Don't overwrite a non-empty API value with a detected value
|
||||
// unless the API value is actually empty
|
||||
if ($currentVal === '' || $this->shouldOverride($key, $currentVal, $value)) {
|
||||
$changes[$key] = [
|
||||
'current' => $currentVal,
|
||||
'detected' => $value,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $changes;
|
||||
}
|
||||
|
||||
private function shouldOverride(string $field, string $current, string $detected): bool
|
||||
{
|
||||
// Version: detected from source is authoritative
|
||||
if ($field === 'version') return true;
|
||||
|
||||
// These fields: source files are authoritative
|
||||
if (in_array($field, ['element_name', 'package_type', 'language', 'entry_point'], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// For other fields, only fill empty — don't overwrite manual edits
|
||||
return false;
|
||||
}
|
||||
|
||||
private function pushManifest(string $apiBase, string $org, string $repo, string $token, array $current, array $update): bool
|
||||
{
|
||||
$merged = array_merge($current, $update);
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$payload = json_encode($merged);
|
||||
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'PUT',
|
||||
'header' => "Authorization: token {$token}\r\nContent-Type: application/json\r\nAccept: application/json\r\n",
|
||||
'content' => $payload,
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
return $body !== false;
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestDetectCli();
|
||||
exit($app->execute());
|
||||
// Backward-compatibility wrapper — manifest_* renamed to metadata_*
|
||||
require __DIR__ . '/metadata_detect.php';
|
||||
|
||||
+2
-189
@@ -1,191 +1,4 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_element.php
|
||||
* BRIEF: Extract element name, type, type prefix, and ZIP name from manifest
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\{CliFramework, SourceResolver};
|
||||
|
||||
class ManifestElementCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Extract element name, type, type prefix, and ZIP name from manifest');
|
||||
$this->addArgument('--path', 'Repository root', '.');
|
||||
$this->addArgument('--version', 'Version string', null);
|
||||
$this->addArgument('--stability', 'Stability level', 'stable');
|
||||
$this->addArgument('--repo', 'Repository name', '');
|
||||
$this->addArgument('--github-output', 'Export results to $GITHUB_OUTPUT', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$version = $this->getArgument('--version');
|
||||
$stability = $this->getArgument('--stability');
|
||||
$repoName = $this->getArgument('--repo');
|
||||
$githubOutput = (bool) $this->getArgument('--github-output');
|
||||
$root = realpath($path) ?: $path;
|
||||
$platform = 'generic';
|
||||
$manifestXml = "{$root}/.mokogitea/manifest.xml";
|
||||
if (file_exists($manifestXml)) {
|
||||
$content = file_get_contents($manifestXml);
|
||||
if (preg_match('/<platform>([^<]+)<\/platform>/', $content, $pm)) {
|
||||
$platform = trim($pm[1]);
|
||||
}
|
||||
}
|
||||
$extManifest = null;
|
||||
$manifestFiles = array_merge(SourceResolver::globSource($root, 'pkg_*.xml'), SourceResolver::globSource($root, '*.xml'), glob("{$root}/*.xml") ?: []);
|
||||
foreach ($manifestFiles as $file) {
|
||||
$c = file_get_contents($file);
|
||||
if (strpos($c, '<extension') !== false) {
|
||||
$extManifest = $file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$modFile = null;
|
||||
$modFiles = array_merge(
|
||||
SourceResolver::globSource($root, 'core/modules/mod*.class.php'),
|
||||
glob("{$root}/core/modules/mod*.class.php") ?: []
|
||||
);
|
||||
foreach ($modFiles as $file) {
|
||||
$c = file_get_contents($file);
|
||||
if (strpos($c, 'extends DolibarrModules') !== false) {
|
||||
$modFile = $file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$extElement = '';
|
||||
$extType = '';
|
||||
$extFolder = '';
|
||||
$extName = '';
|
||||
switch (true) {
|
||||
case in_array($platform, ['joomla', 'waas-component'], true) && $extManifest !== null:
|
||||
$xml = file_get_contents($extManifest);
|
||||
if (preg_match('/type="([^"]*)"/', $xml, $tm)) {
|
||||
$extType = $tm[1];
|
||||
}
|
||||
if (preg_match('/group="([^"]*)"/', $xml, $gm)) {
|
||||
$extFolder = $gm[1];
|
||||
}
|
||||
if (preg_match('/<element>([^<]+)<\/element>/', $xml, $em)) {
|
||||
$extElement = $em[1];
|
||||
}
|
||||
if (empty($extElement) && preg_match('/module="([^"]*)"/', $xml, $mm)) {
|
||||
$extElement = $mm[1];
|
||||
}
|
||||
if (empty($extElement) && preg_match('/plugin="([^"]*)"/', $xml, $pm2)) {
|
||||
$extElement = $pm2[1];
|
||||
}
|
||||
if ($extType === 'package' && preg_match('/<packagename>([^<]+)<\/packagename>/', $xml, $pn)) {
|
||||
$extElement = $pn[1];
|
||||
}
|
||||
if (empty($extElement)) {
|
||||
$extElement = strtolower(basename($extManifest, '.xml'));
|
||||
if (in_array($extElement, ['templatedetails', 'manifest'], true)) {
|
||||
$extElement = strtolower(str_replace([' ', '-'], '', $repoName ?: basename($root)));
|
||||
}
|
||||
}
|
||||
if (preg_match('/<name>([^<]+)<\/name>/', $xml, $nm)) {
|
||||
$extName = trim($nm[1]);
|
||||
}
|
||||
break;
|
||||
case in_array($platform, ['dolibarr', 'crm-module'], true) && $modFile !== null:
|
||||
$extType = 'dolibarr-module';
|
||||
$modBasename = basename($modFile, '.class.php');
|
||||
$extElement = strtolower(preg_replace('/^mod/', '', $modBasename));
|
||||
$modContent = file_get_contents($modFile);
|
||||
if (preg_match('/\$this->name\s*=\s*[\'"]([^\'"]+)[\'"]/', $modContent, $nm)) {
|
||||
$extName = $nm[1];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$extElement = strtolower(str_replace([' ', '-'], '', $repoName ?: basename($root)));
|
||||
$extType = 'generic';
|
||||
break;
|
||||
}
|
||||
$extElement = preg_replace('/^(pkg_|com_|mod_|plg_[a-z]+_|tpl_|lib_)/', '', $extElement);
|
||||
$typePrefix = '';
|
||||
switch ($extType) {
|
||||
case 'plugin':
|
||||
$typePrefix = "plg_{$extFolder}_";
|
||||
break;
|
||||
case 'module':
|
||||
$typePrefix = 'mod_';
|
||||
break;
|
||||
case 'component':
|
||||
$typePrefix = 'com_';
|
||||
break;
|
||||
case 'template':
|
||||
$typePrefix = 'tpl_';
|
||||
break;
|
||||
case 'library':
|
||||
$typePrefix = 'lib_';
|
||||
break;
|
||||
case 'package':
|
||||
$typePrefix = 'pkg_';
|
||||
break;
|
||||
}
|
||||
$suffixMap = [
|
||||
'development' => '-dev',
|
||||
'dev' => '-dev',
|
||||
'alpha' => '-alpha',
|
||||
'beta' => '-beta',
|
||||
'rc' => '-rc',
|
||||
'release-candidate' => '-rc',
|
||||
'stable' => '',
|
||||
];
|
||||
$suffix = $suffixMap[$stability] ?? '';
|
||||
$zipName = '';
|
||||
if ($version !== null) {
|
||||
$zipName = "{$typePrefix}{$extElement}-{$version}{$suffix}.zip";
|
||||
}
|
||||
if (empty($extName)) {
|
||||
$extName = $repoName ?: basename($root);
|
||||
}
|
||||
$outputs = [
|
||||
'platform' => $platform,
|
||||
'ext_element' => $extElement,
|
||||
'ext_type' => $extType,
|
||||
'ext_folder' => $extFolder,
|
||||
'ext_name' => $extName,
|
||||
'type_prefix' => $typePrefix,
|
||||
'zip_name' => $zipName,
|
||||
];
|
||||
if ($githubOutput) {
|
||||
$ghOutput = getenv('GITHUB_OUTPUT');
|
||||
$lines = [];
|
||||
foreach ($outputs as $key => $value) {
|
||||
$lines[] = "{$key}={$value}";
|
||||
}
|
||||
if ($ghOutput) {
|
||||
file_put_contents($ghOutput, implode("\n", $lines) . "\n", FILE_APPEND);
|
||||
} else {
|
||||
foreach ($outputs as $key => $value) {
|
||||
echo "::set-output name={$key}::{$value}\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($outputs as $key => $value) {
|
||||
echo "{$key}={$value}\n";
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestElementCli();
|
||||
exit($app->execute());
|
||||
// Backward-compatibility wrapper — manifest_* renamed to metadata_*
|
||||
require __DIR__ . '/metadata_element.php';
|
||||
|
||||
+2
-562
@@ -1,564 +1,4 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_integrity.php
|
||||
* VERSION: 09.29.01
|
||||
* BRIEF: Cross-check manifest API fields against repo contents across the org
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
class ManifestIntegrityCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Cross-check manifest fields against repo contents across the org');
|
||||
$this->addArgument('--path', 'Single repo path (local mode)', '');
|
||||
$this->addArgument('--org', 'Gitea org (bulk mode)', 'MokoConsulting');
|
||||
$this->addArgument('--repo', 'Single repo name (remote mode)', '');
|
||||
$this->addArgument('--token', 'Gitea API token (or GITEA_TOKEN env)', '');
|
||||
$this->addArgument('--api-base', 'Gitea API base URL', 'https://git.mokoconsulting.tech/api/v1');
|
||||
$this->addArgument('--fix', 'Push fixes for detected drift', false);
|
||||
$this->addArgument('--json', 'Output as JSON', false);
|
||||
$this->addArgument('--quiet', 'Only show repos with issues', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$org = $this->getArgument('--org');
|
||||
$repoName = $this->getArgument('--repo');
|
||||
$token = $this->getArgument('--token') ?: getenv('GITEA_TOKEN') ?: '';
|
||||
$apiBase = rtrim($this->getArgument('--api-base'), '/');
|
||||
$fixMode = (bool) $this->getArgument('--fix');
|
||||
$jsonMode = (bool) $this->getArgument('--json');
|
||||
$quiet = (bool) $this->getArgument('--quiet');
|
||||
|
||||
if ($token === '') {
|
||||
$this->log('ERROR', 'API token required (use --token or GITEA_TOKEN env)');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ── Mode selection ──────────────────────────────────────────
|
||||
if ($path !== '') {
|
||||
// Local mode: detect from source + compare to API
|
||||
return $this->checkLocal($path, $org, $repoName, $token, $apiBase, $fixMode, $jsonMode);
|
||||
}
|
||||
|
||||
if ($repoName !== '') {
|
||||
// Single remote repo
|
||||
return $this->checkRemoteRepo($org, $repoName, $token, $apiBase, $fixMode, $jsonMode);
|
||||
}
|
||||
|
||||
// Bulk mode: all repos in org
|
||||
return $this->checkOrg($org, $token, $apiBase, $fixMode, $jsonMode, $quiet);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Local mode — detect from source, compare to API
|
||||
// =====================================================================
|
||||
|
||||
private function checkLocal(string $path, string $org, string $repoName, string $token, string $apiBase, bool $fix, bool $json): int
|
||||
{
|
||||
$root = realpath($path) ?: $path;
|
||||
if (!is_dir($root)) {
|
||||
$this->log('ERROR', "Path does not exist: {$path}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($repoName === '') {
|
||||
$repoName = $this->detectRepoName($root);
|
||||
}
|
||||
|
||||
// Run manifest_detect logic
|
||||
$detected = $this->runDetect($root, $repoName);
|
||||
$current = $this->fetchManifest($apiBase, $org, $repoName, $token);
|
||||
|
||||
if ($current === null) {
|
||||
$this->log('ERROR', "Failed to fetch manifest for {$org}/{$repoName}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$issues = $this->validate($current, $detected, $repoName);
|
||||
|
||||
if ($json) {
|
||||
echo json_encode(['repo' => $repoName, 'issues' => $issues], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
$this->printIssues($repoName, $issues);
|
||||
}
|
||||
|
||||
if ($fix && !empty($issues)) {
|
||||
return $this->applyFixes($apiBase, $org, $repoName, $token, $current, $issues);
|
||||
}
|
||||
|
||||
return empty($issues) ? 0 : 1;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Remote single repo mode — fetch source files via API
|
||||
// =====================================================================
|
||||
|
||||
private function checkRemoteRepo(string $org, string $repoName, string $token, string $apiBase, bool $fix, bool $json): int
|
||||
{
|
||||
$current = $this->fetchManifest($apiBase, $org, $repoName, $token);
|
||||
if ($current === null) {
|
||||
$this->log('ERROR', "Failed to fetch manifest for {$org}/{$repoName}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$issues = $this->validateManifestOnly($current, $repoName);
|
||||
|
||||
if ($json) {
|
||||
echo json_encode(['repo' => $repoName, 'issues' => $issues], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
$this->printIssues($repoName, $issues);
|
||||
}
|
||||
|
||||
if ($fix && !empty($issues)) {
|
||||
return $this->applyFixes($apiBase, $org, $repoName, $token, $current, $issues);
|
||||
}
|
||||
|
||||
return empty($issues) ? 0 : 1;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Bulk org mode — check all repos
|
||||
// =====================================================================
|
||||
|
||||
private function checkOrg(string $org, string $token, string $apiBase, bool $fix, bool $json, bool $quiet): int
|
||||
{
|
||||
$repos = $this->fetchOrgRepos($apiBase, $org, $token);
|
||||
if ($repos === null) {
|
||||
$this->log('ERROR', "Failed to fetch repos for org {$org}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Manifest Integrity Check — {$org} (" . count($repos) . " repos)");
|
||||
|
||||
$allResults = [];
|
||||
$totalIssues = 0;
|
||||
$reposWithIssues = 0;
|
||||
|
||||
foreach ($repos as $repo) {
|
||||
$name = $repo['name'];
|
||||
$manifest = $this->fetchManifest($apiBase, $org, $name, $token);
|
||||
|
||||
if ($manifest === null) {
|
||||
if (!$quiet) {
|
||||
$this->log('WARN', "{$name}: no manifest");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$issues = $this->validateManifestOnly($manifest, $name);
|
||||
|
||||
if (!empty($issues)) {
|
||||
$reposWithIssues++;
|
||||
$totalIssues += count($issues);
|
||||
|
||||
if ($json) {
|
||||
$allResults[] = ['repo' => $name, 'issues' => $issues];
|
||||
} else {
|
||||
$this->printIssues($name, $issues);
|
||||
}
|
||||
|
||||
if ($fix) {
|
||||
$this->applyFixes($apiBase, $org, $name, $token, $manifest, $issues);
|
||||
}
|
||||
} elseif (!$quiet && !$json) {
|
||||
$this->log('OK', "{$name}: clean");
|
||||
}
|
||||
}
|
||||
|
||||
if ($json) {
|
||||
echo json_encode($allResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
echo "\n";
|
||||
$level = $reposWithIssues > 0 ? 'WARN' : 'OK';
|
||||
$this->log($level, sprintf(
|
||||
'Summary: %d repos checked, %d with issues (%d total issues)',
|
||||
count($repos),
|
||||
$reposWithIssues,
|
||||
$totalIssues
|
||||
));
|
||||
}
|
||||
|
||||
return $reposWithIssues > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Validation rules
|
||||
// =====================================================================
|
||||
|
||||
/**
|
||||
* Full validation: compare API manifest against locally-detected fields.
|
||||
*/
|
||||
private function validate(array $current, array $detected, string $repoName): array
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
// Required fields that should never be empty
|
||||
$required = ['platform', 'name', 'version', 'package_type', 'language', 'entry_point'];
|
||||
foreach ($required as $field) {
|
||||
if (empty($current[$field])) {
|
||||
$fix = $detected[$field] ?? null;
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'error',
|
||||
'message' => 'Missing required field',
|
||||
'current' => '',
|
||||
'fix' => $fix,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Drift detection: detected value differs from API
|
||||
foreach ($detected as $field => $detectedValue) {
|
||||
$currentValue = $current[$field] ?? '';
|
||||
if ($detectedValue !== '' && $currentValue !== '' && $detectedValue !== $currentValue) {
|
||||
// Version drift is expected on dev branches (suffix)
|
||||
if ($field === 'version' && strpos($detectedValue, $currentValue) === 0) {
|
||||
continue; // e.g., detected "02.34.50-dev" vs API "02.34.50"
|
||||
}
|
||||
if ($field === 'version' && strpos($currentValue, $detectedValue) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'warn',
|
||||
'message' => 'Drift: source differs from manifest',
|
||||
'current' => $currentValue,
|
||||
'fix' => $detectedValue,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Platform-specific structure validation
|
||||
$platform = $current['platform'] ?? '';
|
||||
$issues = array_merge($issues, $this->validatePlatformStructure($platform, $current, $repoName));
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
/**
|
||||
* API-only validation: check manifest fields for completeness and consistency
|
||||
* without access to source files.
|
||||
*/
|
||||
private function validateManifestOnly(array $manifest, string $repoName): array
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
// Required fields
|
||||
$required = ['platform', 'name', 'version', 'language'];
|
||||
foreach ($required as $field) {
|
||||
if (empty($manifest[$field])) {
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'error',
|
||||
'message' => 'Missing required field',
|
||||
'current' => '',
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Recommended fields
|
||||
$recommended = ['package_type', 'entry_point', 'license_spdx', 'description'];
|
||||
foreach ($recommended as $field) {
|
||||
if (empty($manifest[$field])) {
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'info',
|
||||
'message' => 'Recommended field is empty',
|
||||
'current' => '',
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Platform-specific checks
|
||||
$platform = $manifest['platform'] ?? '';
|
||||
$issues = array_merge($issues, $this->validatePlatformStructure($platform, $manifest, $repoName));
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform-specific validation rules.
|
||||
*/
|
||||
private function validatePlatformStructure(string $platform, array $manifest, string $repoName): array
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
switch ($platform) {
|
||||
case 'joomla':
|
||||
case 'waas-component':
|
||||
// Joomla repos must have element_name
|
||||
if (empty($manifest['element_name'])) {
|
||||
$issues[] = [
|
||||
'field' => 'element_name',
|
||||
'severity' => 'error',
|
||||
'message' => 'Joomla repos require element_name',
|
||||
'current' => '',
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
// Language should be PHP
|
||||
if (!empty($manifest['language']) && $manifest['language'] !== 'PHP') {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'Joomla repos should have language=PHP',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => 'PHP',
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'dolibarr':
|
||||
case 'crm-module':
|
||||
if (!empty($manifest['language']) && $manifest['language'] !== 'PHP') {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'Dolibarr repos should have language=PHP',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => 'PHP',
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'go':
|
||||
if (!empty($manifest['language']) && $manifest['language'] !== 'Go') {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'Go repos should have language=Go',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => 'Go',
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mcp':
|
||||
if (!empty($manifest['language']) && !in_array($manifest['language'], ['TypeScript', 'JavaScript'], true)) {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'MCP repos should have language=TypeScript or JavaScript',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Version format check: should be XX.YY.ZZ
|
||||
$version = $manifest['version'] ?? '';
|
||||
if ($version !== '' && !preg_match('/^\d{2}\.\d{2}\.\d{2}/', $version)) {
|
||||
// Allow semver for node/go repos
|
||||
if (!in_array($platform, ['mcp', 'node', 'go'], true)) {
|
||||
$issues[] = [
|
||||
'field' => 'version',
|
||||
'severity' => 'info',
|
||||
'message' => 'Version does not match XX.YY.ZZ format',
|
||||
'current' => $version,
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Output
|
||||
// =====================================================================
|
||||
|
||||
private function printIssues(string $repoName, array $issues): void
|
||||
{
|
||||
if (empty($issues)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$errors = count(array_filter($issues, fn($i) => $i['severity'] === 'error'));
|
||||
$warns = count(array_filter($issues, fn($i) => $i['severity'] === 'warn'));
|
||||
$infos = count($issues) - $errors - $warns;
|
||||
|
||||
echo "\n";
|
||||
$summary = [];
|
||||
if ($errors > 0) $summary[] = "{$errors} error(s)";
|
||||
if ($warns > 0) $summary[] = "{$warns} warning(s)";
|
||||
if ($infos > 0) $summary[] = "{$infos} info";
|
||||
$this->log($errors > 0 ? 'ERROR' : 'WARN', "{$repoName} — " . implode(', ', $summary));
|
||||
|
||||
foreach ($issues as $issue) {
|
||||
$icon = match ($issue['severity']) {
|
||||
'error' => 'ERROR',
|
||||
'warn' => 'WARN',
|
||||
default => 'INFO',
|
||||
};
|
||||
$msg = sprintf(' %-18s %s', $issue['field'], $issue['message']);
|
||||
if ($issue['current'] !== '') {
|
||||
$msg .= " (current: {$issue['current']})";
|
||||
}
|
||||
if ($issue['fix'] !== null) {
|
||||
$msg .= " → fix: {$issue['fix']}";
|
||||
}
|
||||
$this->log($icon, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Fix application
|
||||
// =====================================================================
|
||||
|
||||
private function applyFixes(string $apiBase, string $org, string $repo, string $token, array $current, array $issues): int
|
||||
{
|
||||
$fixes = [];
|
||||
foreach ($issues as $issue) {
|
||||
if ($issue['fix'] !== null && $issue['fix'] !== '') {
|
||||
$fixes[$issue['field']] = $issue['fix'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($fixes)) {
|
||||
$this->log('INFO', "{$repo}: no auto-fixable issues");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$merged = array_merge($current, $fixes);
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$payload = json_encode($merged);
|
||||
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'PUT',
|
||||
'header' => "Authorization: token {$token}\r\nContent-Type: application/json\r\nAccept: application/json\r\n",
|
||||
'content' => $payload,
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) {
|
||||
$this->log('ERROR', "{$repo}: failed to push fixes");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('OK', "{$repo}: fixed " . implode(', ', array_keys($fixes)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// API helpers
|
||||
// =====================================================================
|
||||
|
||||
private function fetchManifest(string $apiBase, string $org, string $repo, string $token): ?array
|
||||
{
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) return null;
|
||||
|
||||
$data = json_decode($body, true);
|
||||
return is_array($data) ? $data : null;
|
||||
}
|
||||
|
||||
private function fetchOrgRepos(string $apiBase, string $org, string $token): ?array
|
||||
{
|
||||
$allRepos = [];
|
||||
$page = 1;
|
||||
$limit = 50;
|
||||
|
||||
while (true) {
|
||||
$url = "{$apiBase}/orgs/{$org}/repos?page={$page}&limit={$limit}";
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
|
||||
'timeout' => 15,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) return null;
|
||||
|
||||
$repos = json_decode($body, true);
|
||||
if (!is_array($repos) || empty($repos)) break;
|
||||
|
||||
$allRepos = array_merge($allRepos, $repos);
|
||||
|
||||
if (count($repos) < $limit) break;
|
||||
$page++;
|
||||
}
|
||||
|
||||
// Filter out archived and empty repos
|
||||
return array_filter($allRepos, fn($r) => !($r['archived'] ?? false) && !($r['empty'] ?? false));
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Detection (delegates to manifest_detect logic)
|
||||
// =====================================================================
|
||||
|
||||
private function runDetect(string $root, string $repoName): array
|
||||
{
|
||||
$script = __DIR__ . '/manifest_detect.php';
|
||||
$redirect = PHP_OS_FAMILY === 'Windows' ? '2>NUL' : '2>/dev/null';
|
||||
$cmd = sprintf(
|
||||
'php %s --path %s --repo %s --json --quiet %s',
|
||||
escapeshellarg($script),
|
||||
escapeshellarg($root),
|
||||
escapeshellarg($repoName),
|
||||
$redirect
|
||||
);
|
||||
|
||||
$output = shell_exec($cmd) ?? '';
|
||||
|
||||
// Extract JSON object from output (skip banner/log lines)
|
||||
if (preg_match('/\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}/s', $output, $m)) {
|
||||
$data = json_decode($m[0], true);
|
||||
if (is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function detectRepoName(string $root): string
|
||||
{
|
||||
$gitConfig = "{$root}/.git/config";
|
||||
if (!file_exists($gitConfig)) {
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
$content = file_get_contents($gitConfig);
|
||||
if (preg_match('/url\s*=\s*.*\/([^\/\s]+?)(?:\.git)?\s*$/m', $content, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return basename($root);
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestIntegrityCli();
|
||||
exit($app->execute());
|
||||
// Backward-compatibility wrapper — manifest_* renamed to metadata_*
|
||||
require __DIR__ . '/metadata_integrity.php';
|
||||
|
||||
+2
-278
@@ -1,280 +1,4 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_licensing.php
|
||||
* VERSION: 09.29.01
|
||||
* BRIEF: Ensure licensing tags (updateservers, dlid) in Joomla extension manifests
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\{CliFramework, SourceResolver};
|
||||
|
||||
/**
|
||||
* Reads the <licensing> block from .mokogitea/manifest.xml and ensures that the
|
||||
* Joomla extension manifest contains the correct <updateservers> and <dlid> tags.
|
||||
*
|
||||
* manifest.xml licensing block example:
|
||||
*
|
||||
* <licensing>
|
||||
* <enabled>true</enabled>
|
||||
* <dlid>true</dlid>
|
||||
* <update-server>https://git.mokoconsulting.tech/{org}/{repo}/updates.xml</update-server>
|
||||
* <update-server-name>MyExtension Updates</update-server-name>
|
||||
* </licensing>
|
||||
*
|
||||
* Supports {org} and {repo} placeholders in update-server URL, resolved from
|
||||
* the manifest's <identity> block or git remote.
|
||||
*/
|
||||
class ManifestLicensingCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Ensure licensing tags (updateservers, dlid) in Joomla extension manifests');
|
||||
$this->addArgument('--path', 'Repository root path', '.');
|
||||
$this->addArgument('--fix', 'Apply fixes (default: dry-run check only)', false);
|
||||
$this->addArgument('--github-output', 'Write results to $GITHUB_OUTPUT', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$root = realpath($this->getArgument('--path')) ?: $this->getArgument('--path');
|
||||
$fix = (bool) $this->getArgument('--fix');
|
||||
$ghOutput = (bool) $this->getArgument('--github-output');
|
||||
|
||||
// ── 1. Read manifest.xml ──────────────────────────────────────────
|
||||
$manifestFile = "{$root}/.mokogitea/manifest.xml";
|
||||
|
||||
if (!file_exists($manifestFile)) {
|
||||
$this->log('WARN', "No manifest.xml found at {$manifestFile}");
|
||||
$this->outputResult($ghOutput, 'skipped', 'No manifest.xml');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$xml = @simplexml_load_file($manifestFile);
|
||||
|
||||
if ($xml === false) {
|
||||
$this->log('ERROR', "Failed to parse {$manifestFile}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ── 2. Check if licensing is enabled ──────────────────────────────
|
||||
if (!isset($xml->licensing) || (string) ($xml->licensing->enabled ?? '') !== 'true') {
|
||||
$this->log('INFO', 'Licensing not enabled in manifest.xml — skipping');
|
||||
$this->outputResult($ghOutput, 'skipped', 'Licensing not enabled');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$licensingNode = $xml->licensing;
|
||||
$dlidEnabled = ((string) ($licensingNode->dlid ?? 'true')) === 'true';
|
||||
$updateServerUrl = (string) ($licensingNode->{'update-server'} ?? '');
|
||||
$updateServerName = (string) ($licensingNode->{'update-server-name'} ?? '');
|
||||
|
||||
// ── 3. Resolve placeholders ───────────────────────────────────────
|
||||
$org = (string) ($xml->identity->org ?? '');
|
||||
$repo = (string) ($xml->identity->name ?? '');
|
||||
|
||||
// Fallback to git remote if manifest doesn't have org/name
|
||||
if (empty($org) || empty($repo)) {
|
||||
$remote = trim((string) @shell_exec("cd " . escapeshellarg($root) . " && git remote get-url origin 2>/dev/null"));
|
||||
|
||||
if (preg_match('#[/:]([^/]+)/([^/.]+?)(?:\.git)?$#', $remote, $m)) {
|
||||
if (empty($org)) {
|
||||
$org = $m[1];
|
||||
}
|
||||
if (empty($repo)) {
|
||||
$repo = $m[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Default update server URL if not specified
|
||||
if (empty($updateServerUrl) && !empty($org) && !empty($repo)) {
|
||||
$updateServerUrl = "https://git.mokoconsulting.tech/{$org}/{$repo}/updates.xml";
|
||||
}
|
||||
|
||||
// Resolve {org} and {repo} placeholders
|
||||
$updateServerUrl = str_replace(['{org}', '{repo}'], [$org, $repo], $updateServerUrl);
|
||||
|
||||
// Default server name from display-name or repo name
|
||||
if (empty($updateServerName)) {
|
||||
$displayName = (string) ($xml->identity->{'display-name'} ?? $repo);
|
||||
$updateServerName = $displayName . ' Updates';
|
||||
}
|
||||
|
||||
if (empty($updateServerUrl)) {
|
||||
$this->log('ERROR', 'Cannot determine update server URL — set <update-server> in manifest.xml or ensure org/repo are available');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Licensing enabled — org={$org}, repo={$repo}");
|
||||
$this->log('INFO', "Update server: {$updateServerUrl}");
|
||||
$this->log('INFO', "DLID required: " . ($dlidEnabled ? 'yes' : 'no'));
|
||||
|
||||
// ── 4. Find Joomla extension manifests ────────────────────────────
|
||||
$xmlFiles = array_merge(
|
||||
SourceResolver::globSource($root, '*.xml'),
|
||||
SourceResolver::globSource($root, 'packages/*/*.xml'),
|
||||
glob("{$root}/*.xml") ?: []
|
||||
);
|
||||
|
||||
$packageManifest = null;
|
||||
|
||||
foreach ($xmlFiles as $file) {
|
||||
$content = file_get_contents($file);
|
||||
|
||||
if (!str_contains($content, '<extension')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find the package manifest (type="package") or the main extension manifest
|
||||
if (str_contains($content, 'type="package"')) {
|
||||
$packageManifest = $file;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallback: first extension manifest found
|
||||
if ($packageManifest === null) {
|
||||
$packageManifest = $file;
|
||||
}
|
||||
}
|
||||
|
||||
if ($packageManifest === null) {
|
||||
$this->log('WARN', 'No Joomla extension manifest found');
|
||||
$this->outputResult($ghOutput, 'skipped', 'No extension manifest');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$relPath = str_replace($root . '/', '', str_replace('\\', '/', $packageManifest));
|
||||
$this->log('INFO', "Package manifest: {$relPath}");
|
||||
|
||||
// ── 5. Check and fix the manifest ─────────────────────────────────
|
||||
$content = file_get_contents($packageManifest);
|
||||
$original = $content;
|
||||
$changes = [];
|
||||
|
||||
// --- 5a. Ensure <updateservers> block with correct URL ---
|
||||
if (preg_match('#<updateservers>\s*</updateservers>#s', $content)) {
|
||||
// Empty updateservers block — inject the server
|
||||
$replacement = "<updateservers>\n"
|
||||
. " <server type=\"extension\" name=\"{$updateServerName}\">{$updateServerUrl}</server>\n"
|
||||
. " </updateservers>";
|
||||
$content = preg_replace('#<updateservers>\s*</updateservers>#s', $replacement, $content);
|
||||
$changes[] = 'Added update server URL to empty <updateservers>';
|
||||
} elseif (!str_contains($content, '<updateservers>')) {
|
||||
// No updateservers at all — add before </extension>
|
||||
$serverBlock = "\n <updateservers>\n"
|
||||
. " <server type=\"extension\" name=\"{$updateServerName}\">{$updateServerUrl}</server>\n"
|
||||
. " </updateservers>\n";
|
||||
$content = str_replace('</extension>', $serverBlock . '</extension>', $content);
|
||||
$changes[] = 'Added <updateservers> block';
|
||||
} else {
|
||||
// updateservers exists — verify URL is correct
|
||||
if (preg_match('#<server[^>]*>([^<]+)</server>#', $content, $m)) {
|
||||
if ($m[1] !== $updateServerUrl) {
|
||||
$content = preg_replace(
|
||||
'#(<server[^>]*>)[^<]+(</server>)#',
|
||||
"\${1}{$updateServerUrl}\${2}",
|
||||
$content
|
||||
);
|
||||
$changes[] = "Updated server URL: {$m[1]} → {$updateServerUrl}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- 5b. Ensure <dlid> tag if required ---
|
||||
if ($dlidEnabled) {
|
||||
if (!str_contains($content, '<dlid')) {
|
||||
// Add before <updateservers> if present, otherwise before </extension>
|
||||
$dlidTag = ' <dlid prefix="dlid=" suffix=""/>' . "\n";
|
||||
|
||||
if (str_contains($content, '<updateservers>')) {
|
||||
$content = str_replace('<updateservers>', $dlidTag . "\n <updateservers>", $content);
|
||||
} else {
|
||||
$content = str_replace('</extension>', $dlidTag . '</extension>', $content);
|
||||
}
|
||||
|
||||
$changes[] = 'Added <dlid> tag';
|
||||
}
|
||||
}
|
||||
|
||||
// --- 5c. Ensure <blockChildUninstall> for packages ---
|
||||
if (str_contains($content, 'type="package"') && !str_contains($content, '<blockChildUninstall>')) {
|
||||
$blockTag = ' <blockChildUninstall>true</blockChildUninstall>' . "\n";
|
||||
|
||||
if (str_contains($content, '<dlid')) {
|
||||
// Add after <dlid>
|
||||
$content = preg_replace(
|
||||
'#(<dlid[^/]*/>\s*\n)#',
|
||||
"\${1}{$blockTag}",
|
||||
$content
|
||||
);
|
||||
} elseif (str_contains($content, '<updateservers>')) {
|
||||
$content = str_replace('<updateservers>', $blockTag . "\n <updateservers>", $content);
|
||||
} else {
|
||||
$content = str_replace('</extension>', $blockTag . '</extension>', $content);
|
||||
}
|
||||
|
||||
$changes[] = 'Added <blockChildUninstall>true</blockChildUninstall>';
|
||||
}
|
||||
|
||||
// ── 6. Report and apply ───────────────────────────────────────────
|
||||
if (empty($changes)) {
|
||||
$this->log('INFO', 'All licensing tags are correct — no changes needed');
|
||||
$this->outputResult($ghOutput, 'ok', 'No changes needed');
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($changes as $change) {
|
||||
$this->log($fix ? 'INFO' : 'WARN', ($fix ? 'Fixed: ' : 'Needs fix: ') . $change);
|
||||
}
|
||||
|
||||
if ($fix) {
|
||||
file_put_contents($packageManifest, $content);
|
||||
$this->log('INFO', "Wrote {$relPath} with " . count($changes) . " change(s)");
|
||||
$this->outputResult($ghOutput, 'fixed', implode('; ', $changes));
|
||||
} else {
|
||||
$this->log('WARN', 'Run with --fix to apply changes');
|
||||
$this->outputResult($ghOutput, 'needs-fix', implode('; ', $changes));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write result to $GITHUB_OUTPUT if requested.
|
||||
*/
|
||||
private function outputResult(bool $ghOutput, string $status, string $detail): void
|
||||
{
|
||||
if (!$ghOutput) {
|
||||
return;
|
||||
}
|
||||
|
||||
$outputFile = getenv('GITHUB_OUTPUT');
|
||||
|
||||
if ($outputFile === false || $outputFile === '') {
|
||||
echo "licensing_status={$status}\n";
|
||||
echo "licensing_detail={$detail}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$fh = fopen($outputFile, 'a');
|
||||
fwrite($fh, "licensing_status={$status}\n");
|
||||
fwrite($fh, "licensing_detail={$detail}\n");
|
||||
fclose($fh);
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestLicensingCli();
|
||||
exit($app->execute());
|
||||
// Backward-compatibility wrapper — manifest_* renamed to metadata_*
|
||||
require __DIR__ . '/metadata_licensing.php';
|
||||
|
||||
+2
-168
@@ -1,170 +1,4 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_read.php
|
||||
* VERSION: 09.29.01
|
||||
* BRIEF: Parse .manifest.xml and output requested field(s) for CI consumption
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
class ManifestReadCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Parse manifest.xml and output requested field(s) for CI consumption');
|
||||
$this->addArgument('--path', 'Repository root path', '.');
|
||||
$this->addArgument('--field', 'Single field name to output', '');
|
||||
$this->addArgument('--all', 'Print all fields as KEY=VALUE lines', false);
|
||||
$this->addArgument('--github-output', 'Append all fields to $GITHUB_OUTPUT', false);
|
||||
$this->addArgument('--json', 'Output all fields as JSON', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$field = $this->getArgument('--field');
|
||||
$showAll = $this->getArgument('--all');
|
||||
$ghOutput = $this->getArgument('--github-output');
|
||||
$jsonMode = $this->getArgument('--json');
|
||||
|
||||
// Determine mode
|
||||
if ($ghOutput) {
|
||||
$mode = 'github-output';
|
||||
} elseif ($showAll) {
|
||||
$mode = 'all';
|
||||
} elseif ($jsonMode) {
|
||||
$mode = 'json';
|
||||
} else {
|
||||
$mode = 'field';
|
||||
}
|
||||
|
||||
// -- Locate manifest --
|
||||
$root = realpath($path) ?: $path;
|
||||
$manifestFile = null;
|
||||
|
||||
// Priority: manifest.xml (current standard)
|
||||
$candidates = [
|
||||
"{$root}/.mokogitea/manifest.xml",
|
||||
"{$root}/.mokogitea/.manifest.xml", // legacy (dot-prefixed)
|
||||
"{$root}/.mokogitea/.mokoplatform", // legacy v4
|
||||
];
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
if (file_exists($candidate)) {
|
||||
$manifestFile = $candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($manifestFile === null) {
|
||||
$this->log('ERROR', "No manifest found in {$root}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// -- Parse XML --
|
||||
$xml = @simplexml_load_file($manifestFile);
|
||||
|
||||
if ($xml === false) {
|
||||
// Fallback: try YAML format (.mokostandards legacy)
|
||||
$content = file_get_contents($manifestFile);
|
||||
$fields = [];
|
||||
if (preg_match('/^platform:\s*(.+)/m', $content, $m)) {
|
||||
$fields['platform'] = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
if (preg_match('/^standards_version:\s*(.+)/m', $content, $m)) {
|
||||
$fields['standards-version'] = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
if (preg_match('/^governed_repo:\s*(.+)/m', $content, $m)) {
|
||||
$fields['name'] = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
} else {
|
||||
// Register namespace for XPath (optional, simple path works without)
|
||||
$fields = [
|
||||
'name' => (string)($xml->identity->name ?? ''),
|
||||
'display-name' => (string)($xml->identity->{"display-name"} ?? ''),
|
||||
'org' => (string)($xml->identity->org ?? ''),
|
||||
'description' => (string)($xml->identity->description ?? ''),
|
||||
'license' => (string)($xml->identity->license ?? ''),
|
||||
'license-spdx' => (string)($xml->identity->license['spdx'] ?? ''),
|
||||
'platform' => (string)($xml->governance->platform ?? ''),
|
||||
'standards-version' => (string)($xml->governance->{"standards-version"} ?? ''),
|
||||
'standards-source' => (string)($xml->governance->{"standards-source"} ?? ''),
|
||||
'language' => (string)($xml->build->language ?? ''),
|
||||
'package-type' => (string)($xml->build->{"package-type"} ?? ''),
|
||||
'entry-point' => (string)($xml->build->{"entry-point"} ?? ''),
|
||||
'version' => (string)($xml->identity->version ?? ''),
|
||||
'source-dir' => (string)($xml->deploy->{"source-dir"} ?? ''),
|
||||
'remote-subdir' => (string)($xml->deploy->{"remote-subdir"} ?? ''),
|
||||
'excludes' => (string)($xml->deploy->excludes ?? ''),
|
||||
'dev-host' => (string)($xml->deploy->{"dev-host"} ?? ''),
|
||||
'demo-host' => (string)($xml->deploy->{"demo-host"} ?? ''),
|
||||
'manifest-file' => $manifestFile,
|
||||
];
|
||||
}
|
||||
|
||||
// Strip empty values for cleaner output
|
||||
$fields = array_filter($fields, fn($v) => $v !== '');
|
||||
|
||||
// -- Output --
|
||||
switch ($mode) {
|
||||
case 'field':
|
||||
if ($field === '') {
|
||||
$this->log('ERROR', "Usage: manifest_read.php --path <dir> --field <name>");
|
||||
$this->log('ERROR', " manifest_read.php --path <dir> --all");
|
||||
$this->log('ERROR', " manifest_read.php --path <dir> --json");
|
||||
$this->log('ERROR', " manifest_read.php --path <dir> --github-output");
|
||||
return 2;
|
||||
}
|
||||
echo ($fields[$field] ?? '') . "\n";
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
foreach ($fields as $k => $v) {
|
||||
echo "{$k}={$v}\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
echo json_encode($fields, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
break;
|
||||
|
||||
case 'github-output':
|
||||
$outputFile = getenv('GITHUB_OUTPUT');
|
||||
if ($outputFile === false || $outputFile === '') {
|
||||
$this->log('ERROR', 'GITHUB_OUTPUT not set — printing to stdout instead');
|
||||
foreach ($fields as $k => $v) {
|
||||
// Convert field-name to FIELD_NAME for env var style
|
||||
$envKey = str_replace('-', '_', $k);
|
||||
echo "{$envKey}={$v}\n";
|
||||
}
|
||||
} else {
|
||||
$fh = fopen($outputFile, 'a');
|
||||
foreach ($fields as $k => $v) {
|
||||
$envKey = str_replace('-', '_', $k);
|
||||
fwrite($fh, "{$envKey}={$v}\n");
|
||||
}
|
||||
fclose($fh);
|
||||
$this->log('INFO', "Wrote " . count($fields) . " fields to GITHUB_OUTPUT");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestReadCli();
|
||||
exit($app->execute());
|
||||
// Backward-compatibility wrapper — manifest_* renamed to metadata_*
|
||||
require __DIR__ . '/metadata_read.php';
|
||||
|
||||
@@ -0,0 +1,749 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_detect.php
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Auto-detect manifest fields from source files and optionally push to API
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\{CliFramework, SourceResolver};
|
||||
|
||||
class ManifestDetectCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Auto-detect manifest fields from source files');
|
||||
$this->addArgument('--path', 'Repository root path', '.');
|
||||
$this->addArgument('--json', 'Output as JSON', false);
|
||||
$this->addArgument('--diff', 'Show diff against current manifest API values', false);
|
||||
$this->addArgument('--update', 'Push detected fields to manifest API', false);
|
||||
$this->addArgument('--token', 'Gitea API token (or GITEA_TOKEN env)', '');
|
||||
$this->addArgument('--api-base', 'Gitea API base URL', 'https://git.mokoconsulting.tech/api/v1');
|
||||
$this->addArgument('--org', 'Gitea org', 'MokoConsulting');
|
||||
$this->addArgument('--repo', 'Gitea repo name (auto-detected from remote if empty)', '');
|
||||
$this->addArgument('--github-output', 'Append fields to $GITHUB_OUTPUT', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$jsonMode = (bool) $this->getArgument('--json');
|
||||
$diffMode = (bool) $this->getArgument('--diff');
|
||||
$updateMode = (bool) $this->getArgument('--update');
|
||||
$ghOutput = (bool) $this->getArgument('--github-output');
|
||||
$token = $this->getArgument('--token') ?: getenv('GITEA_TOKEN') ?: '';
|
||||
$apiBase = rtrim($this->getArgument('--api-base'), '/');
|
||||
$org = $this->getArgument('--org');
|
||||
$repoName = $this->getArgument('--repo');
|
||||
|
||||
$root = realpath($path) ?: $path;
|
||||
|
||||
if (!is_dir($root)) {
|
||||
$this->log('ERROR', "Path does not exist: {$path}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Auto-detect repo name from git remote
|
||||
if ($repoName === '') {
|
||||
$repoName = $this->detectRepoName($root);
|
||||
}
|
||||
|
||||
// ── Detect all fields ───────────────────────────────────────
|
||||
$detected = $this->detectAll($root, $repoName);
|
||||
|
||||
// ── Warn about missing fields ────────────────────────────────
|
||||
$expected = ['platform', 'name', 'version', 'package_type', 'language', 'entry_point'];
|
||||
foreach ($expected as $field) {
|
||||
if (!isset($detected[$field]) || $detected[$field] === '') {
|
||||
$this->log('WARN', "Could not detect: {$field}");
|
||||
}
|
||||
}
|
||||
|
||||
// ── Output ──────────────────────────────────────────────────
|
||||
if ($diffMode || $updateMode) {
|
||||
if ($token === '') {
|
||||
$this->log('ERROR', 'API token required for --diff/--update (use --token or GITEA_TOKEN env)');
|
||||
return 1;
|
||||
}
|
||||
if ($repoName === '') {
|
||||
$this->log('ERROR', 'Could not determine repo name (use --repo)');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$current = $this->fetchManifest($apiBase, $org, $repoName, $token);
|
||||
if ($current === null) {
|
||||
$this->log('ERROR', 'Failed to fetch current manifest from API');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$changes = $this->computeDiff($current, $detected);
|
||||
|
||||
if ($diffMode) {
|
||||
if (empty($changes)) {
|
||||
$this->log('INFO', 'No differences — manifest matches source');
|
||||
} else {
|
||||
$this->sectionHeader('Manifest Drift');
|
||||
foreach ($changes as $field => $info) {
|
||||
$this->log('WARN', sprintf(
|
||||
'%-20s API: %-30s Detected: %s',
|
||||
$field,
|
||||
$info['current'] === '' ? '(empty)' : $info['current'],
|
||||
$info['detected']
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($updateMode) {
|
||||
if (empty($changes)) {
|
||||
$this->log('INFO', 'Nothing to update');
|
||||
} else {
|
||||
$update = array_map(fn($i) => $i['detected'], $changes);
|
||||
$ok = $this->pushManifest($apiBase, $org, $repoName, $token, $current, $update);
|
||||
if ($ok) {
|
||||
$this->log('OK', 'Updated ' . count($update) . ' field(s): ' . implode(', ', array_keys($update)));
|
||||
} else {
|
||||
$this->log('ERROR', 'Failed to push manifest update');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($ghOutput) {
|
||||
$outputFile = getenv('GITHUB_OUTPUT');
|
||||
$lines = [];
|
||||
foreach ($detected as $k => $v) {
|
||||
$envKey = str_replace('-', '_', $k);
|
||||
$lines[] = "{$envKey}={$v}";
|
||||
}
|
||||
if ($outputFile !== false && $outputFile !== '') {
|
||||
file_put_contents($outputFile, implode("\n", $lines) . "\n", FILE_APPEND);
|
||||
$this->log('INFO', 'Wrote ' . count($detected) . ' fields to GITHUB_OUTPUT');
|
||||
} else {
|
||||
$this->log('WARN', 'GITHUB_OUTPUT not set — printing to stdout instead');
|
||||
echo implode("\n", $lines) . "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($jsonMode) {
|
||||
echo json_encode($detected, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
foreach ($detected as $k => $v) {
|
||||
echo "{$k}={$v}\n";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Detection engine
|
||||
// =====================================================================
|
||||
|
||||
private function detectAll(string $root, string $repoName): array
|
||||
{
|
||||
$platform = $this->detectPlatform($root);
|
||||
|
||||
$fields = [
|
||||
'platform' => $platform,
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'version' => '',
|
||||
'element_name' => '',
|
||||
'package_type' => '',
|
||||
'language' => '',
|
||||
'entry_point' => '',
|
||||
'license_spdx' => '',
|
||||
'display_name' => '',
|
||||
'target_version' => '',
|
||||
'php_minimum' => '',
|
||||
];
|
||||
|
||||
switch ($platform) {
|
||||
case 'joomla':
|
||||
$this->detectJoomla($root, $repoName, $fields);
|
||||
break;
|
||||
case 'dolibarr':
|
||||
$this->detectDolibarr($root, $repoName, $fields);
|
||||
break;
|
||||
case 'go':
|
||||
$this->detectGo($root, $repoName, $fields);
|
||||
break;
|
||||
case 'mcp':
|
||||
$this->detectNode($root, $repoName, $fields);
|
||||
break;
|
||||
case 'node':
|
||||
$this->detectNode($root, $repoName, $fields);
|
||||
$fields['platform'] = 'node';
|
||||
break;
|
||||
default:
|
||||
$this->detectGeneric($root, $repoName, $fields);
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallbacks
|
||||
if ($fields['name'] === '') {
|
||||
$fields['name'] = $repoName ?: basename($root);
|
||||
}
|
||||
if ($fields['entry_point'] === '') {
|
||||
$fields['entry_point'] = $this->detectEntryPoint($root);
|
||||
}
|
||||
if ($fields['license_spdx'] === '') {
|
||||
$fields['license_spdx'] = $this->detectLicense($root);
|
||||
}
|
||||
// description: only from platform-specific source, never guessed
|
||||
|
||||
// Strip empty values
|
||||
return array_filter($fields, fn($v) => $v !== '');
|
||||
}
|
||||
|
||||
// ── Platform detection ──────────────────────────────────────────
|
||||
|
||||
private function detectPlatform(string $root): string
|
||||
{
|
||||
// Joomla: look for pkg_*.xml or extension XML in source dirs
|
||||
$joomlaXmls = array_merge(
|
||||
SourceResolver::globSource($root, 'pkg_*.xml'),
|
||||
glob("{$root}/pkg_*.xml") ?: []
|
||||
);
|
||||
if (!empty($joomlaXmls)) {
|
||||
return 'joomla';
|
||||
}
|
||||
|
||||
// Check source dirs for any Joomla extension XML
|
||||
foreach (SourceResolver::globSource($root, '*.xml') as $xmlFile) {
|
||||
$content = file_get_contents($xmlFile);
|
||||
if (strpos($content, '<extension') !== false) {
|
||||
return 'joomla';
|
||||
}
|
||||
}
|
||||
|
||||
// Dolibarr: mod*.class.php with DolibarrModules
|
||||
$modFiles = array_merge(
|
||||
SourceResolver::globSource($root, 'core/modules/mod*.class.php'),
|
||||
glob("{$root}/core/modules/mod*.class.php") ?: []
|
||||
);
|
||||
foreach ($modFiles as $file) {
|
||||
if (strpos(file_get_contents($file), 'DolibarrModules') !== false) {
|
||||
return 'dolibarr';
|
||||
}
|
||||
}
|
||||
|
||||
// Go
|
||||
if (file_exists("{$root}/go.mod")) {
|
||||
return 'go';
|
||||
}
|
||||
|
||||
// MCP: package.json with mcp-related content
|
||||
if (file_exists("{$root}/package.json")) {
|
||||
$pkg = json_decode(file_get_contents("{$root}/package.json"), true) ?? [];
|
||||
$deps = array_merge(
|
||||
array_keys($pkg['dependencies'] ?? []),
|
||||
array_keys($pkg['devDependencies'] ?? [])
|
||||
);
|
||||
foreach ($deps as $dep) {
|
||||
if (strpos($dep, '@modelcontextprotocol/') === 0 || $dep === '@anthropic/mcp-sdk') {
|
||||
return 'mcp';
|
||||
}
|
||||
}
|
||||
return 'node';
|
||||
}
|
||||
|
||||
// Python
|
||||
if (file_exists("{$root}/pyproject.toml") || file_exists("{$root}/setup.py")) {
|
||||
return 'python';
|
||||
}
|
||||
|
||||
return 'generic';
|
||||
}
|
||||
|
||||
// ── Joomla ──────────────────────────────────────────────────────
|
||||
|
||||
private function detectJoomla(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['language'] = 'PHP';
|
||||
|
||||
// Find the primary extension manifest XML
|
||||
$extManifest = $this->findJoomlaManifest($root);
|
||||
if ($extManifest === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xml = file_get_contents($extManifest);
|
||||
|
||||
// Type
|
||||
$extType = '';
|
||||
if (preg_match('/type="([^"]*)"/', $xml, $m)) {
|
||||
$extType = $m[1];
|
||||
}
|
||||
$fields['package_type'] = $extType;
|
||||
|
||||
// Element name
|
||||
$element = '';
|
||||
if (preg_match('/<element>([^<]+)<\/element>/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($element === '' && preg_match('/module="([^"]*)"/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($element === '' && preg_match('/plugin="([^"]*)"/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($extType === 'package' && preg_match('/<packagename>([^<]+)<\/packagename>/', $xml, $m)) {
|
||||
$element = $m[1];
|
||||
}
|
||||
if ($element === '') {
|
||||
$element = strtolower(basename($extManifest, '.xml'));
|
||||
}
|
||||
|
||||
// Ensure element has type prefix (API stores full element_name like pkg_mokosuiteclient)
|
||||
$prefixMap = [
|
||||
'package' => 'pkg_', 'component' => 'com_', 'module' => 'mod_',
|
||||
'template' => 'tpl_', 'library' => 'lib_', 'file' => 'file_',
|
||||
];
|
||||
if (isset($prefixMap[$extType])) {
|
||||
$prefix = $prefixMap[$extType];
|
||||
// Only add prefix if not already present (check all known prefixes)
|
||||
$hasPrefix = false;
|
||||
foreach ($prefixMap as $p) {
|
||||
if (strpos($element, $p) === 0) { $hasPrefix = true; break; }
|
||||
}
|
||||
if (strpos($element, 'plg_') === 0) { $hasPrefix = true; }
|
||||
if (!$hasPrefix) {
|
||||
$element = $prefix . $element;
|
||||
}
|
||||
} elseif ($extType === 'plugin') {
|
||||
$folder = '';
|
||||
if (preg_match('/group="([^"]*)"/', $xml, $gm)) {
|
||||
$folder = $gm[1];
|
||||
}
|
||||
if ($folder !== '' && strpos($element, 'plg_') !== 0) {
|
||||
$element = "plg_{$folder}_" . $element;
|
||||
}
|
||||
}
|
||||
$fields['element_name'] = $element;
|
||||
|
||||
// Name
|
||||
if (preg_match('/<name>([^<]+)<\/name>/', $xml, $m)) {
|
||||
$fields['name'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// Version
|
||||
if (preg_match('/<version>([^<]+)<\/version>/', $xml, $m)) {
|
||||
$fields['version'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// Description
|
||||
if (preg_match('/<description>([^<]+)<\/description>/', $xml, $m)) {
|
||||
$desc = trim($m[1]);
|
||||
// Skip language string keys like COM_MOKOSUITE_DESCRIPTION
|
||||
if (strpos($desc, '_') === false || strlen($desc) > 60) {
|
||||
$fields['description'] = $desc;
|
||||
}
|
||||
}
|
||||
|
||||
// Display name for update feeds
|
||||
if (!empty($fields['name'])) {
|
||||
$name = $fields['name'];
|
||||
// If name already has "Type - " prefix, use as-is
|
||||
if (preg_match('/^(Package|Component|Module|Plugin|Template|Library)\s*-\s*/i', $name)) {
|
||||
$fields['display_name'] = $name;
|
||||
} elseif (!empty($extType)) {
|
||||
$fields['display_name'] = ucfirst($extType) . ' - ' . $name;
|
||||
}
|
||||
}
|
||||
|
||||
// Target Joomla version
|
||||
if (preg_match('/<targetplatform\s[^>]*version="([^"]+)"/', $xml, $m)) {
|
||||
$fields['target_version'] = trim($m[1]);
|
||||
} else {
|
||||
// Default for Joomla 5/6
|
||||
$fields['target_version'] = '(5|6)\..*';
|
||||
}
|
||||
|
||||
// PHP minimum
|
||||
if (preg_match('/<php_minimum>([^<]+)<\/php_minimum>/', $xml, $m)) {
|
||||
$fields['php_minimum'] = trim($m[1]);
|
||||
}
|
||||
|
||||
// License
|
||||
if (preg_match('/<license>([^<]+)<\/license>/', $xml, $m)) {
|
||||
$fields['license_spdx'] = $this->normalizeLicense(trim($m[1]));
|
||||
}
|
||||
}
|
||||
|
||||
private function findJoomlaManifest(string $root): ?string
|
||||
{
|
||||
// Priority: pkg_*.xml (package manifest)
|
||||
$pkgXmls = array_merge(
|
||||
SourceResolver::globSource($root, 'pkg_*.xml'),
|
||||
glob("{$root}/pkg_*.xml") ?: []
|
||||
);
|
||||
if (!empty($pkgXmls)) {
|
||||
return $pkgXmls[0];
|
||||
}
|
||||
|
||||
// Any extension XML in source dir
|
||||
foreach (SourceResolver::globSource($root, '*.xml') as $file) {
|
||||
$content = file_get_contents($file);
|
||||
if (strpos($content, '<extension') !== false) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Root level
|
||||
foreach (glob("{$root}/*.xml") ?: [] as $file) {
|
||||
$content = file_get_contents($file);
|
||||
if (strpos($content, '<extension') !== false) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Dolibarr ────────────────────────────────────────────────────
|
||||
|
||||
private function detectDolibarr(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['language'] = 'PHP';
|
||||
$fields['package_type'] = 'dolibarr-module';
|
||||
|
||||
$modFile = $this->findDolibarrModule($root);
|
||||
if ($modFile === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = file_get_contents($modFile);
|
||||
|
||||
// Element name from class file
|
||||
$modBasename = basename($modFile, '.class.php');
|
||||
$fields['element_name'] = strtolower(preg_replace('/^mod/', '', $modBasename));
|
||||
|
||||
// Name
|
||||
if (preg_match('/\$this->name\s*=\s*[\'"]([^\'"]+)[\'"]/', $content, $m)) {
|
||||
$fields['name'] = $m[1];
|
||||
}
|
||||
|
||||
// Version
|
||||
if (preg_match('/\$this->version\s*=\s*[\'"]([^\'"]+)[\'"]/', $content, $m)) {
|
||||
$fields['version'] = $m[1];
|
||||
}
|
||||
|
||||
// Description
|
||||
if (preg_match('/\$this->description\s*=\s*[\'"]([^\'"]+)[\'"]/', $content, $m)) {
|
||||
$desc = $m[1];
|
||||
if (strpos($desc, '$') === false) {
|
||||
$fields['description'] = $desc;
|
||||
}
|
||||
}
|
||||
|
||||
// License
|
||||
if (preg_match('/SPDX-License-Identifier:\s*(\S+)/', $content, $m)) {
|
||||
$fields['license_spdx'] = $m[1];
|
||||
}
|
||||
}
|
||||
|
||||
private function findDolibarrModule(string $root): ?string
|
||||
{
|
||||
$candidates = array_merge(
|
||||
SourceResolver::globSource($root, 'core/modules/mod*.class.php'),
|
||||
glob("{$root}/core/modules/mod*.class.php") ?: []
|
||||
);
|
||||
foreach ($candidates as $file) {
|
||||
if (strpos(file_get_contents($file), 'DolibarrModules') !== false) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Go ──────────────────────────────────────────────────────────
|
||||
|
||||
private function detectGo(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['language'] = 'Go';
|
||||
$fields['package_type'] = 'application';
|
||||
$fields['entry_point'] = './';
|
||||
|
||||
$goMod = "{$root}/go.mod";
|
||||
if (!file_exists($goMod)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = file_get_contents($goMod);
|
||||
|
||||
// Module path → name
|
||||
if (preg_match('/^module\s+(\S+)/m', $content, $m)) {
|
||||
$modulePath = $m[1];
|
||||
$parts = explode('/', $modulePath);
|
||||
$fields['name'] = end($parts);
|
||||
}
|
||||
|
||||
// Go version
|
||||
if (preg_match('/^go\s+(\S+)/m', $content, $m)) {
|
||||
// This is Go language version, not the project version
|
||||
// Project version comes from git tags or source files
|
||||
}
|
||||
|
||||
// License
|
||||
$fields['license_spdx'] = $this->detectLicense($root);
|
||||
}
|
||||
|
||||
// ── Node / MCP ──────────────────────────────────────────────────
|
||||
|
||||
private function detectNode(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$pkgFile = "{$root}/package.json";
|
||||
if (!file_exists($pkgFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pkg = json_decode(file_get_contents($pkgFile), true) ?? [];
|
||||
|
||||
$fields['name'] = $pkg['name'] ?? '';
|
||||
// Strip npm scope
|
||||
if (strpos($fields['name'], '/') !== false) {
|
||||
$fields['name'] = explode('/', $fields['name'])[1];
|
||||
}
|
||||
|
||||
$fields['version'] = $pkg['version'] ?? '';
|
||||
$fields['description'] = $pkg['description'] ?? '';
|
||||
$fields['license_spdx'] = $pkg['license'] ?? '';
|
||||
|
||||
// Language detection
|
||||
if (file_exists("{$root}/tsconfig.json")) {
|
||||
$fields['language'] = 'TypeScript';
|
||||
} else {
|
||||
$fields['language'] = 'JavaScript';
|
||||
}
|
||||
|
||||
// Package type
|
||||
$deps = array_merge(
|
||||
array_keys($pkg['dependencies'] ?? []),
|
||||
array_keys($pkg['devDependencies'] ?? [])
|
||||
);
|
||||
$isMcp = false;
|
||||
foreach ($deps as $dep) {
|
||||
if (strpos($dep, '@modelcontextprotocol/') === 0 || $dep === '@anthropic/mcp-sdk') {
|
||||
$isMcp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fields['package_type'] = $isMcp ? 'mcp-server' : 'application';
|
||||
|
||||
// Entry point
|
||||
if (file_exists("{$root}/dist")) {
|
||||
$fields['entry_point'] = 'dist/';
|
||||
} elseif (file_exists("{$root}/src")) {
|
||||
$fields['entry_point'] = 'src/';
|
||||
} else {
|
||||
$fields['entry_point'] = './';
|
||||
}
|
||||
}
|
||||
|
||||
// ── Generic ─────────────────────────────────────────────────────
|
||||
|
||||
private function detectGeneric(string $root, string $repoName, array &$fields): void
|
||||
{
|
||||
$fields['package_type'] = 'generic';
|
||||
|
||||
// Try to detect language from file extensions
|
||||
$fields['language'] = $this->detectLanguageFromFiles($root);
|
||||
$fields['license_spdx'] = $this->detectLicense($root);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Shared detection helpers
|
||||
// =====================================================================
|
||||
|
||||
private function detectEntryPoint(string $root): string
|
||||
{
|
||||
$abs = SourceResolver::resolveAbsolute($root);
|
||||
if ($abs !== null) {
|
||||
return basename($abs) . '/';
|
||||
}
|
||||
if (is_dir("{$root}/dist")) return 'dist/';
|
||||
if (is_dir("{$root}/src")) return 'src/';
|
||||
return './';
|
||||
}
|
||||
|
||||
private function detectLicense(string $root): string
|
||||
{
|
||||
// Check LICENSE file
|
||||
foreach (['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'COPYING'] as $name) {
|
||||
$file = "{$root}/{$name}";
|
||||
if (!file_exists($file)) continue;
|
||||
$content = file_get_contents($file);
|
||||
|
||||
// SPDX header
|
||||
if (preg_match('/SPDX-License-Identifier:\s*(\S+)/', $content, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
// Common license patterns
|
||||
if (strpos($content, 'GNU GENERAL PUBLIC LICENSE') !== false) {
|
||||
if (strpos($content, 'Version 3') !== false) return 'GPL-3.0-or-later';
|
||||
if (strpos($content, 'Version 2') !== false) return 'GPL-2.0-or-later';
|
||||
}
|
||||
if (strpos($content, 'MIT License') !== false) return 'MIT';
|
||||
if (strpos($content, 'Apache License') !== false && strpos($content, 'Version 2.0') !== false) return 'Apache-2.0';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
private function detectLanguageFromFiles(string $root): string
|
||||
{
|
||||
$counts = ['PHP' => 0, 'Go' => 0, 'TypeScript' => 0, 'JavaScript' => 0, 'Python' => 0, 'Shell' => 0];
|
||||
|
||||
$extensions = [
|
||||
'php' => 'PHP', 'go' => 'Go', 'ts' => 'TypeScript',
|
||||
'js' => 'JavaScript', 'py' => 'Python', 'sh' => 'Shell',
|
||||
];
|
||||
|
||||
// Quick scan: only check top two levels
|
||||
foreach (glob("{$root}/*") ?: [] as $item) {
|
||||
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||
if (isset($extensions[$ext])) {
|
||||
$counts[$extensions[$ext]]++;
|
||||
}
|
||||
if (is_dir($item) && basename($item)[0] !== '.') {
|
||||
foreach (glob("{$item}/*") ?: [] as $subItem) {
|
||||
$ext = pathinfo($subItem, PATHINFO_EXTENSION);
|
||||
if (isset($extensions[$ext])) {
|
||||
$counts[$extensions[$ext]]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arsort($counts);
|
||||
$top = key($counts);
|
||||
return $counts[$top] > 0 ? $top : '';
|
||||
}
|
||||
|
||||
private function normalizeLicense(string $license): string
|
||||
{
|
||||
$lower = strtolower($license);
|
||||
$isGpl = strpos($lower, 'gpl') !== false || strpos($lower, 'general public license') !== false;
|
||||
if ($isGpl && strpos($lower, '3') !== false) return 'GPL-3.0-or-later';
|
||||
if ($isGpl && strpos($lower, '2') !== false) return 'GPL-2.0-or-later';
|
||||
if ($lower === 'mit' || strpos($lower, 'mit license') !== false) return 'MIT';
|
||||
if (strpos($lower, 'apache') !== false) return 'Apache-2.0';
|
||||
return $license;
|
||||
}
|
||||
|
||||
private function detectRepoName(string $root): string
|
||||
{
|
||||
$gitConfig = "{$root}/.git/config";
|
||||
if (!file_exists($gitConfig)) {
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
$content = file_get_contents($gitConfig);
|
||||
if (preg_match('/url\s*=\s*.*\/([^\/\s]+?)(?:\.git)?\s*$/m', $content, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// API interaction
|
||||
// =====================================================================
|
||||
|
||||
private function fetchManifest(string $apiBase, string $org, string $repo, string $token): ?array
|
||||
{
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) return null;
|
||||
|
||||
return json_decode($body, true);
|
||||
}
|
||||
|
||||
private function computeDiff(array $current, array $detected): array
|
||||
{
|
||||
// Map detected keys to API keys (underscores match)
|
||||
$changes = [];
|
||||
|
||||
foreach ($detected as $key => $value) {
|
||||
$apiKey = $key;
|
||||
$currentVal = $current[$apiKey] ?? '';
|
||||
|
||||
// Only flag as changed if detected value is non-empty and differs
|
||||
if ($value !== '' && $value !== $currentVal) {
|
||||
// Don't overwrite a non-empty API value with a detected value
|
||||
// unless the API value is actually empty
|
||||
if ($currentVal === '' || $this->shouldOverride($key, $currentVal, $value)) {
|
||||
$changes[$key] = [
|
||||
'current' => $currentVal,
|
||||
'detected' => $value,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $changes;
|
||||
}
|
||||
|
||||
private function shouldOverride(string $field, string $current, string $detected): bool
|
||||
{
|
||||
// Version: detected from source is authoritative
|
||||
if ($field === 'version') return true;
|
||||
|
||||
// These fields: source files are authoritative
|
||||
if (in_array($field, ['element_name', 'package_type', 'language', 'entry_point'], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// For other fields, only fill empty — don't overwrite manual edits
|
||||
return false;
|
||||
}
|
||||
|
||||
private function pushManifest(string $apiBase, string $org, string $repo, string $token, array $current, array $update): bool
|
||||
{
|
||||
$merged = array_merge($current, $update);
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$payload = json_encode($merged);
|
||||
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'PUT',
|
||||
'header' => "Authorization: token {$token}\r\nContent-Type: application/json\r\nAccept: application/json\r\n",
|
||||
'content' => $payload,
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
return $body !== false;
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestDetectCli();
|
||||
exit($app->execute());
|
||||
@@ -0,0 +1,191 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_element.php
|
||||
* BRIEF: Extract element name, type, type prefix, and ZIP name from manifest
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\{CliFramework, SourceResolver};
|
||||
|
||||
class ManifestElementCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Extract element name, type, type prefix, and ZIP name from manifest');
|
||||
$this->addArgument('--path', 'Repository root', '.');
|
||||
$this->addArgument('--version', 'Version string', null);
|
||||
$this->addArgument('--stability', 'Stability level', 'stable');
|
||||
$this->addArgument('--repo', 'Repository name', '');
|
||||
$this->addArgument('--github-output', 'Export results to $GITHUB_OUTPUT', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$version = $this->getArgument('--version');
|
||||
$stability = $this->getArgument('--stability');
|
||||
$repoName = $this->getArgument('--repo');
|
||||
$githubOutput = (bool) $this->getArgument('--github-output');
|
||||
$root = realpath($path) ?: $path;
|
||||
$platform = 'generic';
|
||||
$manifestXml = "{$root}/.mokogitea/manifest.xml";
|
||||
if (file_exists($manifestXml)) {
|
||||
$content = file_get_contents($manifestXml);
|
||||
if (preg_match('/<platform>([^<]+)<\/platform>/', $content, $pm)) {
|
||||
$platform = trim($pm[1]);
|
||||
}
|
||||
}
|
||||
$extManifest = null;
|
||||
$manifestFiles = array_merge(SourceResolver::globSource($root, 'pkg_*.xml'), SourceResolver::globSource($root, '*.xml'), glob("{$root}/*.xml") ?: []);
|
||||
foreach ($manifestFiles as $file) {
|
||||
$c = file_get_contents($file);
|
||||
if (strpos($c, '<extension') !== false) {
|
||||
$extManifest = $file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$modFile = null;
|
||||
$modFiles = array_merge(
|
||||
SourceResolver::globSource($root, 'core/modules/mod*.class.php'),
|
||||
glob("{$root}/core/modules/mod*.class.php") ?: []
|
||||
);
|
||||
foreach ($modFiles as $file) {
|
||||
$c = file_get_contents($file);
|
||||
if (strpos($c, 'extends DolibarrModules') !== false) {
|
||||
$modFile = $file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$extElement = '';
|
||||
$extType = '';
|
||||
$extFolder = '';
|
||||
$extName = '';
|
||||
switch (true) {
|
||||
case in_array($platform, ['joomla', 'waas-component'], true) && $extManifest !== null:
|
||||
$xml = file_get_contents($extManifest);
|
||||
if (preg_match('/type="([^"]*)"/', $xml, $tm)) {
|
||||
$extType = $tm[1];
|
||||
}
|
||||
if (preg_match('/group="([^"]*)"/', $xml, $gm)) {
|
||||
$extFolder = $gm[1];
|
||||
}
|
||||
if (preg_match('/<element>([^<]+)<\/element>/', $xml, $em)) {
|
||||
$extElement = $em[1];
|
||||
}
|
||||
if (empty($extElement) && preg_match('/module="([^"]*)"/', $xml, $mm)) {
|
||||
$extElement = $mm[1];
|
||||
}
|
||||
if (empty($extElement) && preg_match('/plugin="([^"]*)"/', $xml, $pm2)) {
|
||||
$extElement = $pm2[1];
|
||||
}
|
||||
if ($extType === 'package' && preg_match('/<packagename>([^<]+)<\/packagename>/', $xml, $pn)) {
|
||||
$extElement = $pn[1];
|
||||
}
|
||||
if (empty($extElement)) {
|
||||
$extElement = strtolower(basename($extManifest, '.xml'));
|
||||
if (in_array($extElement, ['templatedetails', 'manifest'], true)) {
|
||||
$extElement = strtolower(str_replace([' ', '-'], '', $repoName ?: basename($root)));
|
||||
}
|
||||
}
|
||||
if (preg_match('/<name>([^<]+)<\/name>/', $xml, $nm)) {
|
||||
$extName = trim($nm[1]);
|
||||
}
|
||||
break;
|
||||
case in_array($platform, ['dolibarr', 'crm-module'], true) && $modFile !== null:
|
||||
$extType = 'dolibarr-module';
|
||||
$modBasename = basename($modFile, '.class.php');
|
||||
$extElement = strtolower(preg_replace('/^mod/', '', $modBasename));
|
||||
$modContent = file_get_contents($modFile);
|
||||
if (preg_match('/\$this->name\s*=\s*[\'"]([^\'"]+)[\'"]/', $modContent, $nm)) {
|
||||
$extName = $nm[1];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$extElement = strtolower(str_replace([' ', '-'], '', $repoName ?: basename($root)));
|
||||
$extType = 'generic';
|
||||
break;
|
||||
}
|
||||
$extElement = preg_replace('/^(pkg_|com_|mod_|plg_[a-z]+_|tpl_|lib_)/', '', $extElement);
|
||||
$typePrefix = '';
|
||||
switch ($extType) {
|
||||
case 'plugin':
|
||||
$typePrefix = "plg_{$extFolder}_";
|
||||
break;
|
||||
case 'module':
|
||||
$typePrefix = 'mod_';
|
||||
break;
|
||||
case 'component':
|
||||
$typePrefix = 'com_';
|
||||
break;
|
||||
case 'template':
|
||||
$typePrefix = 'tpl_';
|
||||
break;
|
||||
case 'library':
|
||||
$typePrefix = 'lib_';
|
||||
break;
|
||||
case 'package':
|
||||
$typePrefix = 'pkg_';
|
||||
break;
|
||||
}
|
||||
$suffixMap = [
|
||||
'development' => '-dev',
|
||||
'dev' => '-dev',
|
||||
'alpha' => '-alpha',
|
||||
'beta' => '-beta',
|
||||
'rc' => '-rc',
|
||||
'release-candidate' => '-rc',
|
||||
'stable' => '',
|
||||
];
|
||||
$suffix = $suffixMap[$stability] ?? '';
|
||||
$zipName = '';
|
||||
if ($version !== null) {
|
||||
$zipName = "{$typePrefix}{$extElement}-{$version}{$suffix}.zip";
|
||||
}
|
||||
if (empty($extName)) {
|
||||
$extName = $repoName ?: basename($root);
|
||||
}
|
||||
$outputs = [
|
||||
'platform' => $platform,
|
||||
'ext_element' => $extElement,
|
||||
'ext_type' => $extType,
|
||||
'ext_folder' => $extFolder,
|
||||
'ext_name' => $extName,
|
||||
'type_prefix' => $typePrefix,
|
||||
'zip_name' => $zipName,
|
||||
];
|
||||
if ($githubOutput) {
|
||||
$ghOutput = getenv('GITHUB_OUTPUT');
|
||||
$lines = [];
|
||||
foreach ($outputs as $key => $value) {
|
||||
$lines[] = "{$key}={$value}";
|
||||
}
|
||||
if ($ghOutput) {
|
||||
file_put_contents($ghOutput, implode("\n", $lines) . "\n", FILE_APPEND);
|
||||
} else {
|
||||
foreach ($outputs as $key => $value) {
|
||||
echo "::set-output name={$key}::{$value}\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($outputs as $key => $value) {
|
||||
echo "{$key}={$value}\n";
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestElementCli();
|
||||
exit($app->execute());
|
||||
@@ -0,0 +1,564 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_integrity.php
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Cross-check manifest API fields against repo contents across the org
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
class ManifestIntegrityCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Cross-check manifest fields against repo contents across the org');
|
||||
$this->addArgument('--path', 'Single repo path (local mode)', '');
|
||||
$this->addArgument('--org', 'Gitea org (bulk mode)', 'MokoConsulting');
|
||||
$this->addArgument('--repo', 'Single repo name (remote mode)', '');
|
||||
$this->addArgument('--token', 'Gitea API token (or GITEA_TOKEN env)', '');
|
||||
$this->addArgument('--api-base', 'Gitea API base URL', 'https://git.mokoconsulting.tech/api/v1');
|
||||
$this->addArgument('--fix', 'Push fixes for detected drift', false);
|
||||
$this->addArgument('--json', 'Output as JSON', false);
|
||||
$this->addArgument('--quiet', 'Only show repos with issues', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$org = $this->getArgument('--org');
|
||||
$repoName = $this->getArgument('--repo');
|
||||
$token = $this->getArgument('--token') ?: getenv('GITEA_TOKEN') ?: '';
|
||||
$apiBase = rtrim($this->getArgument('--api-base'), '/');
|
||||
$fixMode = (bool) $this->getArgument('--fix');
|
||||
$jsonMode = (bool) $this->getArgument('--json');
|
||||
$quiet = (bool) $this->getArgument('--quiet');
|
||||
|
||||
if ($token === '') {
|
||||
$this->log('ERROR', 'API token required (use --token or GITEA_TOKEN env)');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ── Mode selection ──────────────────────────────────────────
|
||||
if ($path !== '') {
|
||||
// Local mode: detect from source + compare to API
|
||||
return $this->checkLocal($path, $org, $repoName, $token, $apiBase, $fixMode, $jsonMode);
|
||||
}
|
||||
|
||||
if ($repoName !== '') {
|
||||
// Single remote repo
|
||||
return $this->checkRemoteRepo($org, $repoName, $token, $apiBase, $fixMode, $jsonMode);
|
||||
}
|
||||
|
||||
// Bulk mode: all repos in org
|
||||
return $this->checkOrg($org, $token, $apiBase, $fixMode, $jsonMode, $quiet);
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Local mode — detect from source, compare to API
|
||||
// =====================================================================
|
||||
|
||||
private function checkLocal(string $path, string $org, string $repoName, string $token, string $apiBase, bool $fix, bool $json): int
|
||||
{
|
||||
$root = realpath($path) ?: $path;
|
||||
if (!is_dir($root)) {
|
||||
$this->log('ERROR', "Path does not exist: {$path}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($repoName === '') {
|
||||
$repoName = $this->detectRepoName($root);
|
||||
}
|
||||
|
||||
// Run manifest_detect logic
|
||||
$detected = $this->runDetect($root, $repoName);
|
||||
$current = $this->fetchManifest($apiBase, $org, $repoName, $token);
|
||||
|
||||
if ($current === null) {
|
||||
$this->log('ERROR', "Failed to fetch manifest for {$org}/{$repoName}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$issues = $this->validate($current, $detected, $repoName);
|
||||
|
||||
if ($json) {
|
||||
echo json_encode(['repo' => $repoName, 'issues' => $issues], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
$this->printIssues($repoName, $issues);
|
||||
}
|
||||
|
||||
if ($fix && !empty($issues)) {
|
||||
return $this->applyFixes($apiBase, $org, $repoName, $token, $current, $issues);
|
||||
}
|
||||
|
||||
return empty($issues) ? 0 : 1;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Remote single repo mode — fetch source files via API
|
||||
// =====================================================================
|
||||
|
||||
private function checkRemoteRepo(string $org, string $repoName, string $token, string $apiBase, bool $fix, bool $json): int
|
||||
{
|
||||
$current = $this->fetchManifest($apiBase, $org, $repoName, $token);
|
||||
if ($current === null) {
|
||||
$this->log('ERROR', "Failed to fetch manifest for {$org}/{$repoName}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$issues = $this->validateManifestOnly($current, $repoName);
|
||||
|
||||
if ($json) {
|
||||
echo json_encode(['repo' => $repoName, 'issues' => $issues], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
$this->printIssues($repoName, $issues);
|
||||
}
|
||||
|
||||
if ($fix && !empty($issues)) {
|
||||
return $this->applyFixes($apiBase, $org, $repoName, $token, $current, $issues);
|
||||
}
|
||||
|
||||
return empty($issues) ? 0 : 1;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Bulk org mode — check all repos
|
||||
// =====================================================================
|
||||
|
||||
private function checkOrg(string $org, string $token, string $apiBase, bool $fix, bool $json, bool $quiet): int
|
||||
{
|
||||
$repos = $this->fetchOrgRepos($apiBase, $org, $token);
|
||||
if ($repos === null) {
|
||||
$this->log('ERROR', "Failed to fetch repos for org {$org}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Manifest Integrity Check — {$org} (" . count($repos) . " repos)");
|
||||
|
||||
$allResults = [];
|
||||
$totalIssues = 0;
|
||||
$reposWithIssues = 0;
|
||||
|
||||
foreach ($repos as $repo) {
|
||||
$name = $repo['name'];
|
||||
$manifest = $this->fetchManifest($apiBase, $org, $name, $token);
|
||||
|
||||
if ($manifest === null) {
|
||||
if (!$quiet) {
|
||||
$this->log('WARN', "{$name}: no manifest");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$issues = $this->validateManifestOnly($manifest, $name);
|
||||
|
||||
if (!empty($issues)) {
|
||||
$reposWithIssues++;
|
||||
$totalIssues += count($issues);
|
||||
|
||||
if ($json) {
|
||||
$allResults[] = ['repo' => $name, 'issues' => $issues];
|
||||
} else {
|
||||
$this->printIssues($name, $issues);
|
||||
}
|
||||
|
||||
if ($fix) {
|
||||
$this->applyFixes($apiBase, $org, $name, $token, $manifest, $issues);
|
||||
}
|
||||
} elseif (!$quiet && !$json) {
|
||||
$this->log('OK', "{$name}: clean");
|
||||
}
|
||||
}
|
||||
|
||||
if ($json) {
|
||||
echo json_encode($allResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
} else {
|
||||
echo "\n";
|
||||
$level = $reposWithIssues > 0 ? 'WARN' : 'OK';
|
||||
$this->log($level, sprintf(
|
||||
'Summary: %d repos checked, %d with issues (%d total issues)',
|
||||
count($repos),
|
||||
$reposWithIssues,
|
||||
$totalIssues
|
||||
));
|
||||
}
|
||||
|
||||
return $reposWithIssues > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Validation rules
|
||||
// =====================================================================
|
||||
|
||||
/**
|
||||
* Full validation: compare API manifest against locally-detected fields.
|
||||
*/
|
||||
private function validate(array $current, array $detected, string $repoName): array
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
// Required fields that should never be empty
|
||||
$required = ['platform', 'name', 'version', 'package_type', 'language', 'entry_point'];
|
||||
foreach ($required as $field) {
|
||||
if (empty($current[$field])) {
|
||||
$fix = $detected[$field] ?? null;
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'error',
|
||||
'message' => 'Missing required field',
|
||||
'current' => '',
|
||||
'fix' => $fix,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Drift detection: detected value differs from API
|
||||
foreach ($detected as $field => $detectedValue) {
|
||||
$currentValue = $current[$field] ?? '';
|
||||
if ($detectedValue !== '' && $currentValue !== '' && $detectedValue !== $currentValue) {
|
||||
// Version drift is expected on dev branches (suffix)
|
||||
if ($field === 'version' && strpos($detectedValue, $currentValue) === 0) {
|
||||
continue; // e.g., detected "02.34.50-dev" vs API "02.34.50"
|
||||
}
|
||||
if ($field === 'version' && strpos($currentValue, $detectedValue) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'warn',
|
||||
'message' => 'Drift: source differs from manifest',
|
||||
'current' => $currentValue,
|
||||
'fix' => $detectedValue,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Platform-specific structure validation
|
||||
$platform = $current['platform'] ?? '';
|
||||
$issues = array_merge($issues, $this->validatePlatformStructure($platform, $current, $repoName));
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
/**
|
||||
* API-only validation: check manifest fields for completeness and consistency
|
||||
* without access to source files.
|
||||
*/
|
||||
private function validateManifestOnly(array $manifest, string $repoName): array
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
// Required fields
|
||||
$required = ['platform', 'name', 'version', 'language'];
|
||||
foreach ($required as $field) {
|
||||
if (empty($manifest[$field])) {
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'error',
|
||||
'message' => 'Missing required field',
|
||||
'current' => '',
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Recommended fields
|
||||
$recommended = ['package_type', 'entry_point', 'license_spdx', 'description'];
|
||||
foreach ($recommended as $field) {
|
||||
if (empty($manifest[$field])) {
|
||||
$issues[] = [
|
||||
'field' => $field,
|
||||
'severity' => 'info',
|
||||
'message' => 'Recommended field is empty',
|
||||
'current' => '',
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Platform-specific checks
|
||||
$platform = $manifest['platform'] ?? '';
|
||||
$issues = array_merge($issues, $this->validatePlatformStructure($platform, $manifest, $repoName));
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform-specific validation rules.
|
||||
*/
|
||||
private function validatePlatformStructure(string $platform, array $manifest, string $repoName): array
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
switch ($platform) {
|
||||
case 'joomla':
|
||||
case 'waas-component':
|
||||
// Joomla repos must have element_name
|
||||
if (empty($manifest['element_name'])) {
|
||||
$issues[] = [
|
||||
'field' => 'element_name',
|
||||
'severity' => 'error',
|
||||
'message' => 'Joomla repos require element_name',
|
||||
'current' => '',
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
// Language should be PHP
|
||||
if (!empty($manifest['language']) && $manifest['language'] !== 'PHP') {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'Joomla repos should have language=PHP',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => 'PHP',
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'dolibarr':
|
||||
case 'crm-module':
|
||||
if (!empty($manifest['language']) && $manifest['language'] !== 'PHP') {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'Dolibarr repos should have language=PHP',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => 'PHP',
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'go':
|
||||
if (!empty($manifest['language']) && $manifest['language'] !== 'Go') {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'Go repos should have language=Go',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => 'Go',
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mcp':
|
||||
if (!empty($manifest['language']) && !in_array($manifest['language'], ['TypeScript', 'JavaScript'], true)) {
|
||||
$issues[] = [
|
||||
'field' => 'language',
|
||||
'severity' => 'warn',
|
||||
'message' => 'MCP repos should have language=TypeScript or JavaScript',
|
||||
'current' => $manifest['language'],
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Version format check: should be XX.YY.ZZ
|
||||
$version = $manifest['version'] ?? '';
|
||||
if ($version !== '' && !preg_match('/^\d{2}\.\d{2}\.\d{2}/', $version)) {
|
||||
// Allow semver for node/go repos
|
||||
if (!in_array($platform, ['mcp', 'node', 'go'], true)) {
|
||||
$issues[] = [
|
||||
'field' => 'version',
|
||||
'severity' => 'info',
|
||||
'message' => 'Version does not match XX.YY.ZZ format',
|
||||
'current' => $version,
|
||||
'fix' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Output
|
||||
// =====================================================================
|
||||
|
||||
private function printIssues(string $repoName, array $issues): void
|
||||
{
|
||||
if (empty($issues)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$errors = count(array_filter($issues, fn($i) => $i['severity'] === 'error'));
|
||||
$warns = count(array_filter($issues, fn($i) => $i['severity'] === 'warn'));
|
||||
$infos = count($issues) - $errors - $warns;
|
||||
|
||||
echo "\n";
|
||||
$summary = [];
|
||||
if ($errors > 0) $summary[] = "{$errors} error(s)";
|
||||
if ($warns > 0) $summary[] = "{$warns} warning(s)";
|
||||
if ($infos > 0) $summary[] = "{$infos} info";
|
||||
$this->log($errors > 0 ? 'ERROR' : 'WARN', "{$repoName} — " . implode(', ', $summary));
|
||||
|
||||
foreach ($issues as $issue) {
|
||||
$icon = match ($issue['severity']) {
|
||||
'error' => 'ERROR',
|
||||
'warn' => 'WARN',
|
||||
default => 'INFO',
|
||||
};
|
||||
$msg = sprintf(' %-18s %s', $issue['field'], $issue['message']);
|
||||
if ($issue['current'] !== '') {
|
||||
$msg .= " (current: {$issue['current']})";
|
||||
}
|
||||
if ($issue['fix'] !== null) {
|
||||
$msg .= " → fix: {$issue['fix']}";
|
||||
}
|
||||
$this->log($icon, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Fix application
|
||||
// =====================================================================
|
||||
|
||||
private function applyFixes(string $apiBase, string $org, string $repo, string $token, array $current, array $issues): int
|
||||
{
|
||||
$fixes = [];
|
||||
foreach ($issues as $issue) {
|
||||
if ($issue['fix'] !== null && $issue['fix'] !== '') {
|
||||
$fixes[$issue['field']] = $issue['fix'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($fixes)) {
|
||||
$this->log('INFO', "{$repo}: no auto-fixable issues");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$merged = array_merge($current, $fixes);
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$payload = json_encode($merged);
|
||||
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'PUT',
|
||||
'header' => "Authorization: token {$token}\r\nContent-Type: application/json\r\nAccept: application/json\r\n",
|
||||
'content' => $payload,
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) {
|
||||
$this->log('ERROR', "{$repo}: failed to push fixes");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('OK', "{$repo}: fixed " . implode(', ', array_keys($fixes)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// API helpers
|
||||
// =====================================================================
|
||||
|
||||
private function fetchManifest(string $apiBase, string $org, string $repo, string $token): ?array
|
||||
{
|
||||
$url = "{$apiBase}/repos/{$org}/{$repo}/manifest";
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
|
||||
'timeout' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) return null;
|
||||
|
||||
$data = json_decode($body, true);
|
||||
return is_array($data) ? $data : null;
|
||||
}
|
||||
|
||||
private function fetchOrgRepos(string $apiBase, string $org, string $token): ?array
|
||||
{
|
||||
$allRepos = [];
|
||||
$page = 1;
|
||||
$limit = 50;
|
||||
|
||||
while (true) {
|
||||
$url = "{$apiBase}/orgs/{$org}/repos?page={$page}&limit={$limit}";
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Authorization: token {$token}\r\nAccept: application/json\r\n",
|
||||
'timeout' => 15,
|
||||
],
|
||||
]);
|
||||
|
||||
$body = @file_get_contents($url, false, $ctx);
|
||||
if ($body === false) return null;
|
||||
|
||||
$repos = json_decode($body, true);
|
||||
if (!is_array($repos) || empty($repos)) break;
|
||||
|
||||
$allRepos = array_merge($allRepos, $repos);
|
||||
|
||||
if (count($repos) < $limit) break;
|
||||
$page++;
|
||||
}
|
||||
|
||||
// Filter out archived and empty repos
|
||||
return array_filter($allRepos, fn($r) => !($r['archived'] ?? false) && !($r['empty'] ?? false));
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// Detection (delegates to manifest_detect logic)
|
||||
// =====================================================================
|
||||
|
||||
private function runDetect(string $root, string $repoName): array
|
||||
{
|
||||
$script = __DIR__ . '/manifest_detect.php';
|
||||
$redirect = PHP_OS_FAMILY === 'Windows' ? '2>NUL' : '2>/dev/null';
|
||||
$cmd = sprintf(
|
||||
'php %s --path %s --repo %s --json --quiet %s',
|
||||
escapeshellarg($script),
|
||||
escapeshellarg($root),
|
||||
escapeshellarg($repoName),
|
||||
$redirect
|
||||
);
|
||||
|
||||
$output = shell_exec($cmd) ?? '';
|
||||
|
||||
// Extract JSON object from output (skip banner/log lines)
|
||||
if (preg_match('/\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}/s', $output, $m)) {
|
||||
$data = json_decode($m[0], true);
|
||||
if (is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function detectRepoName(string $root): string
|
||||
{
|
||||
$gitConfig = "{$root}/.git/config";
|
||||
if (!file_exists($gitConfig)) {
|
||||
return basename($root);
|
||||
}
|
||||
|
||||
$content = file_get_contents($gitConfig);
|
||||
if (preg_match('/url\s*=\s*.*\/([^\/\s]+?)(?:\.git)?\s*$/m', $content, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return basename($root);
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestIntegrityCli();
|
||||
exit($app->execute());
|
||||
@@ -0,0 +1,280 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/manifest_licensing.php
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Ensure licensing tags (updateservers, dlid) in Joomla extension manifests
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\{CliFramework, SourceResolver};
|
||||
|
||||
/**
|
||||
* Reads the <licensing> block from .mokogitea/manifest.xml and ensures that the
|
||||
* Joomla extension manifest contains the correct <updateservers> and <dlid> tags.
|
||||
*
|
||||
* manifest.xml licensing block example:
|
||||
*
|
||||
* <licensing>
|
||||
* <enabled>true</enabled>
|
||||
* <dlid>true</dlid>
|
||||
* <update-server>https://git.mokoconsulting.tech/{org}/{repo}/updates.xml</update-server>
|
||||
* <update-server-name>MyExtension Updates</update-server-name>
|
||||
* </licensing>
|
||||
*
|
||||
* Supports {org} and {repo} placeholders in update-server URL, resolved from
|
||||
* the manifest's <identity> block or git remote.
|
||||
*/
|
||||
class ManifestLicensingCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Ensure licensing tags (updateservers, dlid) in Joomla extension manifests');
|
||||
$this->addArgument('--path', 'Repository root path', '.');
|
||||
$this->addArgument('--fix', 'Apply fixes (default: dry-run check only)', false);
|
||||
$this->addArgument('--github-output', 'Write results to $GITHUB_OUTPUT', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$root = realpath($this->getArgument('--path')) ?: $this->getArgument('--path');
|
||||
$fix = (bool) $this->getArgument('--fix');
|
||||
$ghOutput = (bool) $this->getArgument('--github-output');
|
||||
|
||||
// ── 1. Read manifest.xml ──────────────────────────────────────────
|
||||
$manifestFile = "{$root}/.mokogitea/manifest.xml";
|
||||
|
||||
if (!file_exists($manifestFile)) {
|
||||
$this->log('WARN', "No manifest.xml found at {$manifestFile}");
|
||||
$this->outputResult($ghOutput, 'skipped', 'No manifest.xml');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$xml = @simplexml_load_file($manifestFile);
|
||||
|
||||
if ($xml === false) {
|
||||
$this->log('ERROR', "Failed to parse {$manifestFile}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ── 2. Check if licensing is enabled ──────────────────────────────
|
||||
if (!isset($xml->licensing) || (string) ($xml->licensing->enabled ?? '') !== 'true') {
|
||||
$this->log('INFO', 'Licensing not enabled in manifest.xml — skipping');
|
||||
$this->outputResult($ghOutput, 'skipped', 'Licensing not enabled');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$licensingNode = $xml->licensing;
|
||||
$dlidEnabled = ((string) ($licensingNode->dlid ?? 'true')) === 'true';
|
||||
$updateServerUrl = (string) ($licensingNode->{'update-server'} ?? '');
|
||||
$updateServerName = (string) ($licensingNode->{'update-server-name'} ?? '');
|
||||
|
||||
// ── 3. Resolve placeholders ───────────────────────────────────────
|
||||
$org = (string) ($xml->identity->org ?? '');
|
||||
$repo = (string) ($xml->identity->name ?? '');
|
||||
|
||||
// Fallback to git remote if manifest doesn't have org/name
|
||||
if (empty($org) || empty($repo)) {
|
||||
$remote = trim((string) @shell_exec("cd " . escapeshellarg($root) . " && git remote get-url origin 2>/dev/null"));
|
||||
|
||||
if (preg_match('#[/:]([^/]+)/([^/.]+?)(?:\.git)?$#', $remote, $m)) {
|
||||
if (empty($org)) {
|
||||
$org = $m[1];
|
||||
}
|
||||
if (empty($repo)) {
|
||||
$repo = $m[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Default update server URL if not specified
|
||||
if (empty($updateServerUrl) && !empty($org) && !empty($repo)) {
|
||||
$updateServerUrl = "https://git.mokoconsulting.tech/{$org}/{$repo}/updates.xml";
|
||||
}
|
||||
|
||||
// Resolve {org} and {repo} placeholders
|
||||
$updateServerUrl = str_replace(['{org}', '{repo}'], [$org, $repo], $updateServerUrl);
|
||||
|
||||
// Default server name from display-name or repo name
|
||||
if (empty($updateServerName)) {
|
||||
$displayName = (string) ($xml->identity->{'display-name'} ?? $repo);
|
||||
$updateServerName = $displayName . ' Updates';
|
||||
}
|
||||
|
||||
if (empty($updateServerUrl)) {
|
||||
$this->log('ERROR', 'Cannot determine update server URL — set <update-server> in manifest.xml or ensure org/repo are available');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Licensing enabled — org={$org}, repo={$repo}");
|
||||
$this->log('INFO', "Update server: {$updateServerUrl}");
|
||||
$this->log('INFO', "DLID required: " . ($dlidEnabled ? 'yes' : 'no'));
|
||||
|
||||
// ── 4. Find Joomla extension manifests ────────────────────────────
|
||||
$xmlFiles = array_merge(
|
||||
SourceResolver::globSource($root, '*.xml'),
|
||||
SourceResolver::globSource($root, 'packages/*/*.xml'),
|
||||
glob("{$root}/*.xml") ?: []
|
||||
);
|
||||
|
||||
$packageManifest = null;
|
||||
|
||||
foreach ($xmlFiles as $file) {
|
||||
$content = file_get_contents($file);
|
||||
|
||||
if (!str_contains($content, '<extension')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find the package manifest (type="package") or the main extension manifest
|
||||
if (str_contains($content, 'type="package"')) {
|
||||
$packageManifest = $file;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fallback: first extension manifest found
|
||||
if ($packageManifest === null) {
|
||||
$packageManifest = $file;
|
||||
}
|
||||
}
|
||||
|
||||
if ($packageManifest === null) {
|
||||
$this->log('WARN', 'No Joomla extension manifest found');
|
||||
$this->outputResult($ghOutput, 'skipped', 'No extension manifest');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$relPath = str_replace($root . '/', '', str_replace('\\', '/', $packageManifest));
|
||||
$this->log('INFO', "Package manifest: {$relPath}");
|
||||
|
||||
// ── 5. Check and fix the manifest ─────────────────────────────────
|
||||
$content = file_get_contents($packageManifest);
|
||||
$original = $content;
|
||||
$changes = [];
|
||||
|
||||
// --- 5a. Ensure <updateservers> block with correct URL ---
|
||||
if (preg_match('#<updateservers>\s*</updateservers>#s', $content)) {
|
||||
// Empty updateservers block — inject the server
|
||||
$replacement = "<updateservers>\n"
|
||||
. " <server type=\"extension\" name=\"{$updateServerName}\">{$updateServerUrl}</server>\n"
|
||||
. " </updateservers>";
|
||||
$content = preg_replace('#<updateservers>\s*</updateservers>#s', $replacement, $content);
|
||||
$changes[] = 'Added update server URL to empty <updateservers>';
|
||||
} elseif (!str_contains($content, '<updateservers>')) {
|
||||
// No updateservers at all — add before </extension>
|
||||
$serverBlock = "\n <updateservers>\n"
|
||||
. " <server type=\"extension\" name=\"{$updateServerName}\">{$updateServerUrl}</server>\n"
|
||||
. " </updateservers>\n";
|
||||
$content = str_replace('</extension>', $serverBlock . '</extension>', $content);
|
||||
$changes[] = 'Added <updateservers> block';
|
||||
} else {
|
||||
// updateservers exists — verify URL is correct
|
||||
if (preg_match('#<server[^>]*>([^<]+)</server>#', $content, $m)) {
|
||||
if ($m[1] !== $updateServerUrl) {
|
||||
$content = preg_replace(
|
||||
'#(<server[^>]*>)[^<]+(</server>)#',
|
||||
"\${1}{$updateServerUrl}\${2}",
|
||||
$content
|
||||
);
|
||||
$changes[] = "Updated server URL: {$m[1]} → {$updateServerUrl}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- 5b. Ensure <dlid> tag if required ---
|
||||
if ($dlidEnabled) {
|
||||
if (!str_contains($content, '<dlid')) {
|
||||
// Add before <updateservers> if present, otherwise before </extension>
|
||||
$dlidTag = ' <dlid prefix="dlid=" suffix=""/>' . "\n";
|
||||
|
||||
if (str_contains($content, '<updateservers>')) {
|
||||
$content = str_replace('<updateservers>', $dlidTag . "\n <updateservers>", $content);
|
||||
} else {
|
||||
$content = str_replace('</extension>', $dlidTag . '</extension>', $content);
|
||||
}
|
||||
|
||||
$changes[] = 'Added <dlid> tag';
|
||||
}
|
||||
}
|
||||
|
||||
// --- 5c. Ensure <blockChildUninstall> for packages ---
|
||||
if (str_contains($content, 'type="package"') && !str_contains($content, '<blockChildUninstall>')) {
|
||||
$blockTag = ' <blockChildUninstall>true</blockChildUninstall>' . "\n";
|
||||
|
||||
if (str_contains($content, '<dlid')) {
|
||||
// Add after <dlid>
|
||||
$content = preg_replace(
|
||||
'#(<dlid[^/]*/>\s*\n)#',
|
||||
"\${1}{$blockTag}",
|
||||
$content
|
||||
);
|
||||
} elseif (str_contains($content, '<updateservers>')) {
|
||||
$content = str_replace('<updateservers>', $blockTag . "\n <updateservers>", $content);
|
||||
} else {
|
||||
$content = str_replace('</extension>', $blockTag . '</extension>', $content);
|
||||
}
|
||||
|
||||
$changes[] = 'Added <blockChildUninstall>true</blockChildUninstall>';
|
||||
}
|
||||
|
||||
// ── 6. Report and apply ───────────────────────────────────────────
|
||||
if (empty($changes)) {
|
||||
$this->log('INFO', 'All licensing tags are correct — no changes needed');
|
||||
$this->outputResult($ghOutput, 'ok', 'No changes needed');
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($changes as $change) {
|
||||
$this->log($fix ? 'INFO' : 'WARN', ($fix ? 'Fixed: ' : 'Needs fix: ') . $change);
|
||||
}
|
||||
|
||||
if ($fix) {
|
||||
file_put_contents($packageManifest, $content);
|
||||
$this->log('INFO', "Wrote {$relPath} with " . count($changes) . " change(s)");
|
||||
$this->outputResult($ghOutput, 'fixed', implode('; ', $changes));
|
||||
} else {
|
||||
$this->log('WARN', 'Run with --fix to apply changes');
|
||||
$this->outputResult($ghOutput, 'needs-fix', implode('; ', $changes));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write result to $GITHUB_OUTPUT if requested.
|
||||
*/
|
||||
private function outputResult(bool $ghOutput, string $status, string $detail): void
|
||||
{
|
||||
if (!$ghOutput) {
|
||||
return;
|
||||
}
|
||||
|
||||
$outputFile = getenv('GITHUB_OUTPUT');
|
||||
|
||||
if ($outputFile === false || $outputFile === '') {
|
||||
echo "licensing_status={$status}\n";
|
||||
echo "licensing_detail={$detail}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$fh = fopen($outputFile, 'a');
|
||||
fwrite($fh, "licensing_status={$status}\n");
|
||||
fwrite($fh, "licensing_detail={$detail}\n");
|
||||
fclose($fh);
|
||||
}
|
||||
}
|
||||
|
||||
$app = new ManifestLicensingCli();
|
||||
exit($app->execute());
|
||||
@@ -0,0 +1,317 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/metadata_read.php
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Read and set metadata fields in .mokogitea/metadata.xml (or manifest.xml)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
||||
|
||||
use MokoEnterprise\CliFramework;
|
||||
|
||||
/** Field name → XPath mapping into the metadata XML */
|
||||
const FIELD_MAP = [
|
||||
// identity
|
||||
'name' => 'identity/name',
|
||||
'display-name' => 'identity/display-name',
|
||||
'org' => 'identity/org',
|
||||
'description' => 'identity/description',
|
||||
'license' => 'identity/license',
|
||||
'version' => 'identity/version',
|
||||
// governance
|
||||
'platform' => 'governance/platform',
|
||||
'standards-version' => 'governance/standards-version',
|
||||
'standards-source' => 'governance/standards-source',
|
||||
// build
|
||||
'language' => 'build/language',
|
||||
'package-type' => 'build/package-type',
|
||||
'entry-point' => 'build/entry-point',
|
||||
// deploy
|
||||
'source-dir' => 'deploy/source-dir',
|
||||
'remote-subdir' => 'deploy/remote-subdir',
|
||||
'excludes' => 'deploy/excludes',
|
||||
'dev-host' => 'deploy/dev-host',
|
||||
'demo-host' => 'deploy/demo-host',
|
||||
];
|
||||
|
||||
class MetadataReadCli extends CliFramework
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Read or set metadata fields in .mokogitea/metadata.xml');
|
||||
$this->addArgument('--path', 'Repository root path', '.');
|
||||
$this->addArgument('--field', 'Single field name to read', '');
|
||||
$this->addArgument('--set', 'Set field value (field=value), repeatable', '');
|
||||
$this->addArgument('--all', 'Print all fields as KEY=VALUE lines', false);
|
||||
$this->addArgument('--github-output', 'Append all fields to $GITHUB_OUTPUT', false);
|
||||
$this->addArgument('--json', 'Output all fields as JSON', false);
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$path = $this->getArgument('--path');
|
||||
$field = $this->getArgument('--field');
|
||||
$setValue = $this->getArgument('--set');
|
||||
$showAll = $this->getArgument('--all');
|
||||
$ghOutput = $this->getArgument('--github-output');
|
||||
$jsonMode = $this->getArgument('--json');
|
||||
|
||||
$root = realpath($path) ?: $path;
|
||||
|
||||
// -- Locate metadata file --
|
||||
$metadataFile = $this->findMetadataFile($root);
|
||||
|
||||
if ($metadataFile === null) {
|
||||
$this->log('ERROR', "No metadata file found in {$root}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// -- Auto-migrate manifest.xml → metadata.xml --
|
||||
$metadataFile = $this->migrateIfNeeded($metadataFile, $root);
|
||||
|
||||
// -- Set mode --
|
||||
if ($setValue !== '') {
|
||||
return $this->handleSet($metadataFile, $setValue);
|
||||
}
|
||||
|
||||
// -- Read mode --
|
||||
$xml = @simplexml_load_file($metadataFile);
|
||||
|
||||
if ($xml === false) {
|
||||
// Fallback: legacy YAML format (.mokoplatform)
|
||||
$fields = $this->parseLegacy($metadataFile);
|
||||
} else {
|
||||
$fields = $this->parseXml($xml, $metadataFile);
|
||||
}
|
||||
|
||||
$fields = array_filter($fields, fn($v) => $v !== '');
|
||||
|
||||
return $this->outputFields($fields, $field, $showAll, $ghOutput, $jsonMode);
|
||||
}
|
||||
|
||||
private function findMetadataFile(string $root): ?string
|
||||
{
|
||||
$candidates = [
|
||||
"{$root}/.mokogitea/metadata.xml",
|
||||
"{$root}/.mokogitea/manifest.xml",
|
||||
"{$root}/.mokogitea/.manifest.xml",
|
||||
"{$root}/.mokogitea/.mokoplatform",
|
||||
];
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
if (file_exists($candidate)) {
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function migrateIfNeeded(string $metadataFile, string $root): string
|
||||
{
|
||||
$newPath = "{$root}/.mokogitea/metadata.xml";
|
||||
|
||||
// Already at the new location
|
||||
if ($metadataFile === $newPath) {
|
||||
return $metadataFile;
|
||||
}
|
||||
|
||||
// Legacy file found — migrate
|
||||
if (str_ends_with($metadataFile, '.mokoplatform')) {
|
||||
// YAML legacy — can't auto-migrate, just warn
|
||||
$this->log('WARN', "Legacy .mokoplatform format detected — migrate to metadata.xml manually");
|
||||
return $metadataFile;
|
||||
}
|
||||
|
||||
// manifest.xml or .manifest.xml → metadata.xml
|
||||
copy($metadataFile, $newPath);
|
||||
unlink($metadataFile);
|
||||
$this->log('INFO', "Migrated " . basename($metadataFile) . " → metadata.xml");
|
||||
return $newPath;
|
||||
}
|
||||
|
||||
private function parseXml(\SimpleXMLElement $xml, string $filePath): array
|
||||
{
|
||||
$fields = [];
|
||||
foreach (FIELD_MAP as $name => $xpath) {
|
||||
$parts = explode('/', $xpath);
|
||||
$node = $xml;
|
||||
foreach ($parts as $part) {
|
||||
$node = $node->{$part} ?? null;
|
||||
if ($node === null) break;
|
||||
}
|
||||
if ($name === 'license' && $node !== null) {
|
||||
// Also extract spdx attribute
|
||||
$fields['license'] = (string)$node;
|
||||
$fields['license-spdx'] = (string)($node['spdx'] ?? '');
|
||||
} else {
|
||||
$fields[$name] = $node !== null ? (string)$node : '';
|
||||
}
|
||||
}
|
||||
$fields['metadata-file'] = $filePath;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
private function parseLegacy(string $filePath): array
|
||||
{
|
||||
$content = file_get_contents($filePath);
|
||||
$fields = [];
|
||||
if (preg_match('/^platform:\s*(.+)/m', $content, $m)) {
|
||||
$fields['platform'] = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
if (preg_match('/^standards_version:\s*(.+)/m', $content, $m)) {
|
||||
$fields['standards-version'] = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
if (preg_match('/^governed_repo:\s*(.+)/m', $content, $m)) {
|
||||
$fields['name'] = trim($m[1], " \t\n\r\"'");
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
private function handleSet(string $metadataFile, string $setValue): int
|
||||
{
|
||||
// Parse field=value pairs (comma-separated or from repeated --set)
|
||||
$pairs = [];
|
||||
foreach (explode(',', $setValue) as $pair) {
|
||||
$pair = trim($pair);
|
||||
if ($pair === '') continue;
|
||||
$eq = strpos($pair, '=');
|
||||
if ($eq === false) {
|
||||
$this->log('ERROR', "Invalid set format: '{$pair}' — expected field=value");
|
||||
return 1;
|
||||
}
|
||||
$key = trim(substr($pair, 0, $eq));
|
||||
$val = trim(substr($pair, $eq + 1));
|
||||
$pairs[$key] = $val;
|
||||
}
|
||||
|
||||
if (empty($pairs)) {
|
||||
$this->log('ERROR', 'No field=value pairs provided');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Validate all fields exist in FIELD_MAP
|
||||
foreach ($pairs as $key => $val) {
|
||||
if (!isset(FIELD_MAP[$key])) {
|
||||
$this->log('ERROR', "Unknown field: '{$key}'");
|
||||
$this->log('INFO', 'Valid fields: ' . implode(', ', array_keys(FIELD_MAP)));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy files are read-only
|
||||
if (str_ends_with($metadataFile, '.mokoplatform')) {
|
||||
$this->log('ERROR', 'Cannot set fields on legacy .mokoplatform format — migrate to metadata.xml first');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Load XML
|
||||
$xml = @simplexml_load_file($metadataFile);
|
||||
if ($xml === false) {
|
||||
$this->log('ERROR', "Failed to parse XML: {$metadataFile}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Set each field
|
||||
foreach ($pairs as $key => $val) {
|
||||
$xpath = FIELD_MAP[$key];
|
||||
$parts = explode('/', $xpath);
|
||||
$section = $parts[0];
|
||||
$element = $parts[1];
|
||||
|
||||
if (!isset($xml->{$section})) {
|
||||
$this->log('ERROR', "Section <{$section}> not found in XML — cannot set '{$key}'");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!isset($xml->{$section}->{$element})) {
|
||||
$this->log('ERROR', "Element <{$element}> not found in <{$section}> — cannot set '{$key}'");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$old = (string)$xml->{$section}->{$element};
|
||||
$xml->{$section}->{$element} = $val;
|
||||
$this->log('INFO', "Set {$key}: '{$old}' → '{$val}'");
|
||||
}
|
||||
|
||||
// Write back with preserved formatting
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
$dom->loadXML($xml->asXML());
|
||||
$dom->save($metadataFile);
|
||||
|
||||
$this->log('INFO', "Updated {$metadataFile}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function outputFields(array $fields, string $field, $showAll, $ghOutput, $jsonMode): int
|
||||
{
|
||||
if ($ghOutput) {
|
||||
$mode = 'github-output';
|
||||
} elseif ($showAll) {
|
||||
$mode = 'all';
|
||||
} elseif ($jsonMode) {
|
||||
$mode = 'json';
|
||||
} else {
|
||||
$mode = 'field';
|
||||
}
|
||||
|
||||
switch ($mode) {
|
||||
case 'field':
|
||||
if ($field === '') {
|
||||
$this->log('ERROR', "Usage: metadata_read.php --path <dir> --field <name>");
|
||||
$this->log('ERROR', " metadata_read.php --path <dir> --all");
|
||||
$this->log('ERROR', " metadata_read.php --path <dir> --json");
|
||||
$this->log('ERROR', " metadata_read.php --path <dir> --set field=value");
|
||||
return 2;
|
||||
}
|
||||
echo ($fields[$field] ?? '') . "\n";
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
foreach ($fields as $k => $v) {
|
||||
echo "{$k}={$v}\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
echo json_encode($fields, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
break;
|
||||
|
||||
case 'github-output':
|
||||
$outputFile = getenv('GITHUB_OUTPUT');
|
||||
if ($outputFile === false || $outputFile === '') {
|
||||
$this->log('ERROR', 'GITHUB_OUTPUT not set — printing to stdout instead');
|
||||
foreach ($fields as $k => $v) {
|
||||
$envKey = str_replace('-', '_', $k);
|
||||
echo "{$envKey}={$v}\n";
|
||||
}
|
||||
} else {
|
||||
$fh = fopen($outputFile, 'a');
|
||||
foreach ($fields as $k => $v) {
|
||||
$envKey = str_replace('-', '_', $k);
|
||||
fwrite($fh, "{$envKey}={$v}\n");
|
||||
}
|
||||
fclose($fh);
|
||||
$this->log('INFO', "Wrote " . count($fields) . " fields to GITHUB_OUTPUT");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$app = new MetadataReadCli();
|
||||
exit($app->execute());
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/platform_detect.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Auto-detect repository platform type and optionally update manifest
|
||||
*/
|
||||
|
||||
@@ -82,7 +82,7 @@ class PlatformDetectCli extends CliFramework
|
||||
$giteaUrl,
|
||||
$token,
|
||||
'PATCH',
|
||||
"/api/v1/repos/{$owner}/{$repo}/metadata",
|
||||
"/api/v1/repos/{$owner}/{$repo}/manifest",
|
||||
json_encode(['platform' => $platform])
|
||||
);
|
||||
|
||||
|
||||
+8
-313
@@ -6,12 +6,12 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: mokocli.CLI
|
||||
* INGROUP: mokocli
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli
|
||||
* DEFGROUP: mokoplatform.CLI
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/release_cascade.php
|
||||
* VERSION: 10.00.00
|
||||
* BRIEF: Cascade release zip to all lower stability channels
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: DEPRECATED — cascade behavior removed. Each release stream is independent.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
@@ -22,320 +22,15 @@ use MokoEnterprise\CliFramework;
|
||||
|
||||
class ReleaseCascadeCli extends CliFramework
|
||||
{
|
||||
/** Channel hierarchy: highest stability first. */
|
||||
private const CHANNELS = ['stable', 'release-candidate', 'beta', 'alpha', 'development'];
|
||||
|
||||
/** Map stability input names to canonical tag names. */
|
||||
private const TAG_MAP = [
|
||||
'stable' => 'stable',
|
||||
'release-candidate' => 'release-candidate',
|
||||
'rc' => 'release-candidate',
|
||||
'beta' => 'beta',
|
||||
'alpha' => 'alpha',
|
||||
'development' => 'development',
|
||||
'dev' => 'development',
|
||||
];
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Cascade release zip to all lower stability channels');
|
||||
$this->addArgument('--stability', 'Source stability channel (required)', '');
|
||||
$this->addArgument('--token', 'Gitea API token (required)', '');
|
||||
$this->addArgument('--api-base', 'Gitea API base URL for the repo (required)', '');
|
||||
$this->setDescription('DEPRECATED — cascade behavior removed');
|
||||
}
|
||||
|
||||
protected function run(): int
|
||||
{
|
||||
$stability = strtolower($this->getArgument('--stability'));
|
||||
$token = $this->getArgument('--token');
|
||||
$apiBase = rtrim($this->getArgument('--api-base'), '/');
|
||||
|
||||
if ($token === '') {
|
||||
$envToken = getenv('MOKOGITEA_TOKEN');
|
||||
if ($envToken === false || $envToken === '') {
|
||||
$envToken = getenv('GITEA_TOKEN');
|
||||
}
|
||||
if ($envToken !== false && $envToken !== '') {
|
||||
$token = $envToken;
|
||||
}
|
||||
}
|
||||
|
||||
if ($stability === '' || $token === '' || $apiBase === '') {
|
||||
$this->log('ERROR', 'Usage: release_cascade.php --stability CHANNEL --token TOKEN --api-base URL');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$sourceTag = self::TAG_MAP[$stability] ?? null;
|
||||
if ($sourceTag === null) {
|
||||
$this->log('ERROR', "Unknown stability: {$stability}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Find lower channels to cascade to
|
||||
$lowerChannels = $this->getLowerChannels($sourceTag);
|
||||
if (count($lowerChannels) === 0) {
|
||||
$this->log('INFO', "No lower channels for '{$stability}' — nothing to cascade.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Cascading from '{$sourceTag}' to: " . implode(', ', $lowerChannels));
|
||||
|
||||
if ($this->dryRun) {
|
||||
$this->log('INFO', '[DRY RUN] No changes will be made.');
|
||||
}
|
||||
|
||||
// 1. Get source release
|
||||
$sourceRelease = $this->giteaApi("{$apiBase}/releases/tags/{$sourceTag}", $token);
|
||||
if ($sourceRelease === null) {
|
||||
$this->log('WARN', "No release found at tag '{$sourceTag}' — nothing to cascade.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$sourceVersion = $sourceRelease['name'] ?? $sourceTag;
|
||||
$sourceBody = $sourceRelease['body'] ?? '';
|
||||
$sourceAssets = $sourceRelease['assets'] ?? [];
|
||||
|
||||
// Find zip assets (exclude .sha256 sidecars)
|
||||
$zipAssets = array_filter($sourceAssets, function (array $asset): bool {
|
||||
$name = strtolower($asset['name'] ?? '');
|
||||
return str_ends_with($name, '.zip') && !str_ends_with($name, '.sha256');
|
||||
});
|
||||
|
||||
// Also grab sha256 sidecars
|
||||
$sha256Assets = array_filter($sourceAssets, function (array $asset): bool {
|
||||
return str_ends_with(strtolower($asset['name'] ?? ''), '.zip.sha256');
|
||||
});
|
||||
|
||||
if (count($zipAssets) === 0) {
|
||||
$this->log('WARN', "Source release '{$sourceTag}' has no zip assets — nothing to cascade.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->log('INFO', "Source: {$sourceVersion} — " . count($zipAssets) . " zip(s)");
|
||||
echo "\n";
|
||||
|
||||
// 2. Download source assets to temp files
|
||||
$downloads = [];
|
||||
foreach (array_merge($zipAssets, $sha256Assets) as $asset) {
|
||||
$url = $asset['browser_download_url'] ?? '';
|
||||
if ($url === '') {
|
||||
continue;
|
||||
}
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'cascade_');
|
||||
if ($this->downloadFile($url, $token, $tmpFile)) {
|
||||
$downloads[] = ['name' => $asset['name'], 'path' => $tmpFile];
|
||||
$this->log('INFO', "Downloaded: {$asset['name']}");
|
||||
} else {
|
||||
$this->log('ERROR', "Failed to download: {$asset['name']}");
|
||||
}
|
||||
}
|
||||
|
||||
if (count($downloads) === 0) {
|
||||
$this->log('ERROR', 'Could not download any source assets.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 3. Cascade to each lower channel
|
||||
$errors = 0;
|
||||
foreach ($lowerChannels as $targetTag) {
|
||||
echo "\n";
|
||||
$result = $this->cascadeToChannel(
|
||||
$apiBase, $token, $targetTag,
|
||||
$sourceVersion, $sourceBody, $downloads
|
||||
);
|
||||
if (!$result) {
|
||||
$errors++;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Cleanup temp files
|
||||
foreach ($downloads as $dl) {
|
||||
@unlink($dl['path']);
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
$this->log('INFO', "Cascade complete. " . (count($lowerChannels) - $errors)
|
||||
. "/" . count($lowerChannels) . " channels updated.");
|
||||
|
||||
return $errors > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cascade assets to a single target channel.
|
||||
*/
|
||||
private function cascadeToChannel(
|
||||
string $apiBase,
|
||||
string $token,
|
||||
string $targetTag,
|
||||
string $sourceVersion,
|
||||
string $sourceBody,
|
||||
array $downloads
|
||||
): bool {
|
||||
$this->log('INFO', "→ {$targetTag}");
|
||||
|
||||
if ($this->dryRun) {
|
||||
$this->log('INFO', " [DRY RUN] Would cascade to {$targetTag}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Find existing release at target tag
|
||||
$existing = $this->giteaApi("{$apiBase}/releases/tags/{$targetTag}", $token);
|
||||
|
||||
if ($existing !== null && !empty($existing['id'])) {
|
||||
$releaseId = (int) $existing['id'];
|
||||
|
||||
// Delete existing assets
|
||||
$existingAssets = $existing['assets'] ?? [];
|
||||
foreach ($existingAssets as $asset) {
|
||||
$assetId = $asset['id'] ?? 0;
|
||||
if ($assetId > 0) {
|
||||
$this->giteaApi(
|
||||
"{$apiBase}/releases/{$releaseId}/assets/{$assetId}",
|
||||
$token, 'DELETE'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Update release metadata
|
||||
$updatePayload = json_encode([
|
||||
'name' => $sourceVersion,
|
||||
'body' => $sourceBody,
|
||||
]);
|
||||
$this->giteaApi(
|
||||
"{$apiBase}/releases/{$releaseId}",
|
||||
$token, 'PATCH', $updatePayload
|
||||
);
|
||||
|
||||
$this->log('INFO', " Updated release metadata (id: {$releaseId})");
|
||||
} else {
|
||||
// Create new release at target tag
|
||||
// Use the source release's target commitish so the tag points to the same commit
|
||||
$createPayload = json_encode([
|
||||
'tag_name' => $targetTag,
|
||||
'target_commitish' => 'main',
|
||||
'name' => $sourceVersion,
|
||||
'body' => $sourceBody,
|
||||
'prerelease' => ($targetTag !== 'stable'),
|
||||
]);
|
||||
$newRelease = $this->giteaApi("{$apiBase}/releases", $token, 'POST', $createPayload);
|
||||
if ($newRelease === null || empty($newRelease['id'])) {
|
||||
$this->log('ERROR', " Failed to create release at tag '{$targetTag}'");
|
||||
return false;
|
||||
}
|
||||
$releaseId = (int) $newRelease['id'];
|
||||
$this->log('INFO', " Created release (id: {$releaseId})");
|
||||
}
|
||||
|
||||
// Upload assets
|
||||
foreach ($downloads as $dl) {
|
||||
$uploadUrl = "{$apiBase}/releases/{$releaseId}/assets?name=" . rawurlencode($dl['name']);
|
||||
$success = $this->uploadAsset($uploadUrl, $token, $dl['path'], $dl['name']);
|
||||
if ($success) {
|
||||
$this->log('INFO', " Uploaded: {$dl['name']}");
|
||||
} else {
|
||||
$this->log('ERROR', " Failed to upload: {$dl['name']}");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all channels below the given source channel.
|
||||
*/
|
||||
private function getLowerChannels(string $sourceTag): array
|
||||
{
|
||||
$idx = array_search($sourceTag, self::CHANNELS, true);
|
||||
if ($idx === false) {
|
||||
return [];
|
||||
}
|
||||
return array_slice(self::CHANNELS, $idx + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file via HTTP.
|
||||
*/
|
||||
private function downloadFile(string $url, string $token, string $destPath): bool
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
if ($ch === false) {
|
||||
return false;
|
||||
}
|
||||
$fp = fopen($destPath, 'wb');
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_FILE => $fp,
|
||||
CURLOPT_HTTPHEADER => ["Authorization: token {$token}"],
|
||||
CURLOPT_TIMEOUT => 120,
|
||||
]);
|
||||
curl_exec($ch);
|
||||
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
return $code >= 200 && $code < 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a file as a release asset via multipart form.
|
||||
*/
|
||||
private function uploadAsset(string $url, string $token, string $filePath, string $fileName): bool
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
if ($ch === false) {
|
||||
return false;
|
||||
}
|
||||
$cfile = new CURLFile($filePath, 'application/octet-stream', $fileName);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => ['attachment' => $cfile],
|
||||
CURLOPT_HTTPHEADER => ["Authorization: token {$token}"],
|
||||
CURLOPT_TIMEOUT => 120,
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
return $code >= 200 && $code < 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an HTTP request to the Gitea API.
|
||||
*/
|
||||
private function giteaApi(
|
||||
string $url,
|
||||
string $token,
|
||||
string $method = 'GET',
|
||||
?string $body = null
|
||||
): ?array {
|
||||
$ch = curl_init($url);
|
||||
if ($ch === false) {
|
||||
return null;
|
||||
}
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Authorization: token {$token}",
|
||||
'Content-Type: application/json',
|
||||
],
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_CUSTOMREQUEST => $method,
|
||||
]);
|
||||
if ($body !== null) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
}
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode < 200 || $httpCode >= 300 || empty($response) || !is_string($response)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$decoded = json_decode($response, true);
|
||||
return is_array($decoded) ? $decoded : null;
|
||||
$this->log('INFO', 'No-op (cascade behavior removed — each stream is independent)');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/release_publish.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Publish a release and create copies for all lesser stability streams.
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/scaffold_client.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Scaffold a new client-waas repo from Template-Client-WaaS with pre-configured settings
|
||||
*/
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/updates_xml_sync.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Sync updates.xml to target branches via Gitea API
|
||||
* NOTE: Called by pre-release and auto-release workflows after updates.xml
|
||||
* is modified on the current branch. Pushes the file to other branches
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/version_auto_bump.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Auto patch-bump, set stability suffix, and commit — single CLI replacing inline workflow bash
|
||||
*/
|
||||
|
||||
|
||||
+1
-17
@@ -232,25 +232,9 @@ class VersionBumpCli extends CliFramework
|
||||
$pkgContent
|
||||
);
|
||||
}
|
||||
if ($updatedPkg !== $pkgContent && $updatedPkg !== null) {
|
||||
if ($updatedPkg !== $pkgContent) {
|
||||
file_put_contents($packageJsonFile, $updatedPkg);
|
||||
fwrite(STDERR, "Updated package.json\n");
|
||||
} elseif (preg_match('/("version"\s*:\s*")(\d+)\.(\d+)\.(\d+)(")/m', $pkgContent, $semM)) {
|
||||
// Semver fallback: bump standard x.y.z version when XX.YY.ZZ pattern didn't match
|
||||
$sMajor = (int)$semM[2];
|
||||
$sMinor = (int)$semM[3];
|
||||
$sPatch = (int)$semM[4];
|
||||
switch ($type) {
|
||||
case 'major': $sMajor++; $sMinor = 0; $sPatch = 0; break;
|
||||
case 'minor': $sMinor++; $sPatch = 0; break;
|
||||
default: $sPatch++; break;
|
||||
}
|
||||
$semNew = "{$sMajor}.{$sMinor}.{$sPatch}";
|
||||
$semUpdated = preg_replace('/("version"\s*:\s*")\d+\.\d+\.\d+(")/m', '${1}' . $semNew . '${2}', $pkgContent);
|
||||
if ($semUpdated !== $pkgContent) {
|
||||
file_put_contents($packageJsonFile, $semUpdated);
|
||||
fwrite(STDERR, "Updated package.json (semver: {$semM[2]}.{$semM[3]}.{$semM[4]} -> $semNew)\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
$pyprojectFile = "{$root}/pyproject.toml";
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/version_check.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Validate version consistency across README, manifests, and sub-packages
|
||||
*/
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* INGROUP: mokoplatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /cli/wiki_sync.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Sync select wiki pages from mokoplatform to all template repos
|
||||
*/
|
||||
|
||||
|
||||
+646
-762
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@
|
||||
* INGROUP: MokoPlatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /deploy/backup-before-deploy.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Snapshot Joomla directories before deployment for rollback capability
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: MokoPlatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /deploy/deploy-dolibarr.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Deploy Dolibarr module files to a remote server via SFTP/rsync
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: MokoPlatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /deploy/health-check.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Post-deploy health check — verify a Joomla site is responding correctly
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: MokoPlatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /deploy/rollback-joomla.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Rollback a Joomla deployment by restoring from a pre-deploy snapshot
|
||||
*/
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* INGROUP: MokoPlatform
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
|
||||
* PATH: /deploy/sync-joomla.php
|
||||
* VERSION: 09.29.01
|
||||
* VERSION: 09.26.02
|
||||
* BRIEF: Sync Joomla site directories between two servers via rsync over SSH
|
||||
*/
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ src/
|
||||
├── config.ts # Loads ~/.mcp_mokobackup.json, resolves targets
|
||||
├── client.ts # Backup execution logic
|
||||
├── akeeba.ts # Akeeba Backup API integration (Joomla sites)
|
||||
├── mokobackup.ts # MokoSuite Backup REST API integration
|
||||
├── mokobackup.ts # MokoJoomBackup REST API integration
|
||||
└── types.ts # BackupConfig, BackupTarget types
|
||||
```
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { BackupTarget, BackupResult, AkeebaBackupRecord } from './types.js'
|
||||
const TIMEOUT_MS = 300_000; // 5 min for backup operations
|
||||
|
||||
/**
|
||||
* MokoSuite Backup client using Joomla Web Services API
|
||||
* MokoJoomBackup client using Joomla Web Services API
|
||||
* Endpoint: /api/index.php/v1/mokobackup/*
|
||||
* Auth: Bearer token (Joomla API token)
|
||||
*
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
DEFGROUP: dolibarr-api-mcp.Documentation
|
||||
INGROUP: dolibarr-api-mcp
|
||||
REPO: https://git.mokoconsulting.tech/MokoConsulting/dolibarr-api-mcp
|
||||
VERSION: 09.29.01
|
||||
VERSION: 09.26.02
|
||||
PATH: ./CONTRIBUTING.md
|
||||
BRIEF: Contribution guidelines for the project
|
||||
-->
|
||||
|
||||
@@ -10,7 +10,7 @@ DEFGROUP: dolibarr-api-mcp.Documentation
|
||||
INGROUP: dolibarr-api-mcp
|
||||
REPO: https://git.mokoconsulting.tech/MokoConsulting/dolibarr-api-mcp
|
||||
PATH: /SECURITY.md
|
||||
VERSION: 09.29.01
|
||||
VERSION: 09.26.02
|
||||
BRIEF: Security vulnerability reporting and handling policy
|
||||
-->
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ jobs:
|
||||
- name: Check actor permission (admin only)
|
||||
id: perm
|
||||
env:
|
||||
TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
ACTOR: ${{ github.actor }}
|
||||
run: |
|
||||
|
||||
@@ -85,7 +85,7 @@ jobs:
|
||||
- name: Check actor permission (admin only)
|
||||
id: perm
|
||||
env:
|
||||
TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
ACTOR: ${{ github.actor }}
|
||||
run: |
|
||||
|
||||
@@ -32,7 +32,7 @@ jobs:
|
||||
steps:
|
||||
- name: Assign unassigned issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
ASSIGNEE="jmiller"
|
||||
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
steps:
|
||||
- name: Create tracking issue and sub-issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
# For manual dispatch, use input; for auto, use event ref
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
|
||||
@@ -55,14 +55,14 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
token: ${{ secrets.GA_TOKEN }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT }}"}}'
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN }}"}}'
|
||||
run: |
|
||||
# Ensure PHP + Composer are available
|
||||
if ! command -v composer &> /dev/null; then
|
||||
@@ -287,7 +287,7 @@ jobs:
|
||||
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
|
||||
git config --local user.name "gitea-actions[bot]"
|
||||
# Set push URL with token for branch-protected repos
|
||||
git remote set-url origin "https://jmiller:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git add -A
|
||||
git commit -m "chore(release): build ${VERSION} [skip ci]" \
|
||||
--author="gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>"
|
||||
@@ -350,20 +350,20 @@ jobs:
|
||||
RELEASE_NAME="${EXT_NAME} ${VERSION} (${TYPE_PREFIX}${EXT_ELEMENT}-${VERSION})"
|
||||
|
||||
# Delete existing release if present (overwrite, not append)
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/tags/${RELEASE_TAG}" 2>/dev/null || true)
|
||||
EXISTING_ID=$(echo "$EXISTING" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$EXISTING_ID" ]; then
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/${EXISTING_ID}" 2>/dev/null || true
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/tags/${RELEASE_TAG}" 2>/dev/null || true
|
||||
echo "Deleted previous stable release (id: ${EXISTING_ID})"
|
||||
fi
|
||||
|
||||
# Create fresh release
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${API_BASE}/releases" \
|
||||
-d "$(python3 -c "import json; print(json.dumps({
|
||||
@@ -385,7 +385,7 @@ jobs:
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
|
||||
# All ZIPs upload to the major release tag (vXX)
|
||||
RELEASE_JSON=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
RELEASE_JSON=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/tags/${RELEASE_TAG}" 2>/dev/null || true)
|
||||
RELEASE_ID=$(echo "$RELEASE_JSON" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
@@ -444,7 +444,7 @@ jobs:
|
||||
SHA256_TAR=$(sha256sum "/tmp/${TAR_NAME}" | cut -d' ' -f1)
|
||||
|
||||
# -- Delete existing assets with same name before uploading ------
|
||||
ASSETS=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
ASSETS=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets" 2>/dev/null || echo "[]")
|
||||
for ASSET_NAME in "$ZIP_NAME" "$TAR_NAME"; do
|
||||
ASSET_ID=$(echo "$ASSETS" | python3 -c "
|
||||
@@ -455,18 +455,18 @@ jobs:
|
||||
print(a['id']); break
|
||||
" 2>/dev/null || true)
|
||||
if [ -n "$ASSET_ID" ]; then
|
||||
curl -sf -X DELETE -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X DELETE -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets/${ASSET_ID}" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
# -- Upload both to release tag ----------------------------------
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"/tmp/${ZIP_NAME}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets?name=${ZIP_NAME}" > /dev/null 2>&1 || true
|
||||
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"/tmp/${TAR_NAME}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets?name=${TAR_NAME}" > /dev/null 2>&1 || true
|
||||
@@ -523,7 +523,7 @@ jobs:
|
||||
git push || true
|
||||
|
||||
# Sync updates.xml to main via direct API (always runs — may be on version/XX branch)
|
||||
GA_TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
GA_TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
API="${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}"
|
||||
|
||||
FILE_SHA=$(curl -sf -H "Authorization: token ${GA_TOKEN}" \
|
||||
@@ -605,7 +605,7 @@ jobs:
|
||||
[ -n "$SHA256_TAR" ] && BODY="${BODY}| \`${TAR_NAME}\` | \`${SHA256_TAR}\` |\n"
|
||||
|
||||
# Get release ID and update body
|
||||
RELEASE_ID=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
RELEASE_ID=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/tags/${RELEASE_TAG}" 2>/dev/null | \
|
||||
python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
|
||||
|
||||
@@ -617,7 +617,7 @@ jobs:
|
||||
req = urllib.request.Request(
|
||||
'${API_BASE}/releases/${RELEASE_ID}',
|
||||
data=data,
|
||||
headers={'Authorization': 'token ${{ secrets.MOKOGITEA_TOKEN }}', 'Content-Type': 'application/json'},
|
||||
headers={'Authorization': 'token ${{ secrets.GA_TOKEN }}', 'Content-Type': 'application/json'},
|
||||
method='PATCH'
|
||||
)
|
||||
urllib.request.urlopen(req)
|
||||
@@ -629,10 +629,10 @@ jobs:
|
||||
if: >-
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
steps.version.outputs.stability == 'stable' &&
|
||||
secrets.GH_PAT != ''
|
||||
secrets.GH_TOKEN != ''
|
||||
continue-on-error: true
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
run: |
|
||||
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
|
||||
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
|
||||
@@ -644,7 +644,7 @@ jobs:
|
||||
[ -z "$NOTES" ] && NOTES="Release ${VERSION}"
|
||||
echo "$NOTES" > /tmp/release_notes.md
|
||||
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".tag_name // empty" || true)
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".tag_name // empty" || true)
|
||||
|
||||
if [ -z "$EXISTING" ]; then
|
||||
gh release create "$RELEASE_TAG" \
|
||||
@@ -661,8 +661,8 @@ jobs:
|
||||
# Upload assets to GitHub mirror
|
||||
for PKG in /tmp/${EXT_ELEMENT:-pkg}-${VERSION}.*; do
|
||||
if [ -f "$PKG" ]; then
|
||||
_RELID=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".id // empty")
|
||||
[ -n "$_RELID" ] && curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" -H "Content-Type: application/octet-stream" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/${_RELID}/assets?name=$(basename $PKG)" --data-binary "@$PKG" > /dev/null 2>&1 || true
|
||||
_RELID=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".id // empty")
|
||||
[ -n "$_RELID" ] && curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" -H "Content-Type: application/octet-stream" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/${_RELID}/assets?name=$(basename $PKG)" --data-binary "@$PKG" > /dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
echo "GitHub mirror updated: ${GH_REPO} ${RELEASE_TAG}" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -671,14 +671,14 @@ jobs:
|
||||
- name: "Step 10: Push main to GitHub mirror"
|
||||
if: >-
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
secrets.GH_PAT != ''
|
||||
secrets.GH_TOKEN != ''
|
||||
continue-on-error: true
|
||||
run: |
|
||||
GH_REPO="${{ vars.GH_MIRROR_REPO || github.repository }}"
|
||||
GH_ORG=$(echo "$GH_REPO" | cut -d/ -f1)
|
||||
GH_NAME=$(echo "$GH_REPO" | cut -d/ -f2)
|
||||
git remote add github "https://x-access-token:${{ secrets.GH_PAT }}@github.com/${GH_ORG}/${GH_NAME}.git" 2>/dev/null || \
|
||||
git remote set-url github "https://x-access-token:${{ secrets.GH_PAT }}@github.com/${GH_ORG}/${GH_NAME}.git"
|
||||
git remote add github "https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git" 2>/dev/null || \
|
||||
git remote set-url github "https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git"
|
||||
git fetch origin main --depth=1
|
||||
git push github origin/main:refs/heads/main --force 2>/dev/null \
|
||||
&& echo "main branch pushed to GitHub mirror" \
|
||||
@@ -691,7 +691,7 @@ jobs:
|
||||
run: |
|
||||
php /tmp/mokoplatform-api/cli/release_cascade.php \
|
||||
--stability stable \
|
||||
--token "${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
--token "${{ secrets.GA_TOKEN }}" \
|
||||
--org "${GITEA_ORG}" --repo "${GITEA_REPO}" \
|
||||
--gitea-url "${GITEA_URL}" 2>/dev/null || true
|
||||
|
||||
@@ -700,7 +700,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
|
||||
# Delete dev branch
|
||||
curl -sf -X DELETE -H "Authorization: token ${TOKEN}" \
|
||||
@@ -724,7 +724,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
MOD_FILE="${{ steps.platform.outputs.mod_file }}"
|
||||
ENCODED_PATH=$(echo "$MOD_FILE" | sed 's|^\./||' | python3 -c "import sys,urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip()))")
|
||||
FILE_RESP=$(curl -sf -H "Authorization: token ${TOKEN}" "${API_BASE}/contents/${ENCODED_PATH}?ref=dev" 2>/dev/null || true)
|
||||
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
- name: Discover target branches
|
||||
id: branches
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
|
||||
@@ -93,7 +93,7 @@ jobs:
|
||||
- name: Cascade to all target branches
|
||||
if: steps.branches.outputs.targets != ''
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
SHORT_SHA="${GITHUB_SHA:0:7}"
|
||||
|
||||
@@ -33,11 +33,11 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
token: ${{ secrets.GA_TOKEN }}
|
||||
|
||||
- name: Delete merged branches
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
echo "=== Merged Branch Cleanup ==="
|
||||
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
|
||||
@@ -66,7 +66,7 @@ jobs:
|
||||
|
||||
- name: Clean old workflow runs
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
echo "=== Workflow Run Cleanup ==="
|
||||
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
|
||||
|
||||
@@ -42,10 +42,10 @@ jobs:
|
||||
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
MOKO_CLONE_HOST: ${{ secrets.MOKOGITEA_TOKEN && 'git.mokoconsulting.tech/MokoConsulting' || 'github.com/mokoconsulting-tech' }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.MOKOGITEA_TOKEN || github.token }}"}}'
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
MOKO_CLONE_HOST: ${{ secrets.GA_TOKEN && 'git.mokoconsulting.tech/MokoConsulting' || 'github.com/mokoconsulting-tech' }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GA_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch main --quiet \
|
||||
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokoplatform.git" \
|
||||
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
# ── Build ────────────────────────────────────────────────────────
|
||||
@@ -89,8 +89,8 @@ jobs:
|
||||
# ── Version ──────────────────────────────────────────────────────
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -212,7 +212,7 @@ jobs:
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
steps.check.outputs.tag_exists != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
|
||||
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
token: ${{ secrets.GA_TOKEN }}
|
||||
|
||||
- name: Setup PHP
|
||||
run: |
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
|
||||
run: |
|
||||
git clone --depth 1 --branch main --quiet "https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokoplatform.git" /tmp/mokoplatform-api
|
||||
@@ -89,7 +89,7 @@ jobs:
|
||||
# Commit version bump
|
||||
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
|
||||
git config --local user.name "gitea-actions[bot]"
|
||||
git remote set-url origin "https://jmiller:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git add -A
|
||||
git diff --cached --quiet || {
|
||||
git commit -m "chore(version): bump to ${VERSION} [skip ci]"
|
||||
@@ -154,7 +154,7 @@ jobs:
|
||||
SHA256="${{ steps.zip.outputs.sha256 }}"
|
||||
ZIP_NAME="${{ steps.zip.outputs.zip_name }}"
|
||||
EXT_ELEMENT="${{ steps.meta.outputs.ext_element }}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
BRANCH=$(git branch --show-current)
|
||||
|
||||
@@ -212,13 +212,13 @@ jobs:
|
||||
- name: "Sync updates.xml to all branches"
|
||||
if: steps.platform.outputs.platform == 'joomla'
|
||||
run: |
|
||||
php /tmp/mokoplatform-api/cli/updates_xml_sync.php --path . --current "${{ github.ref_name }}" --branches main,dev --version "${{ steps.meta.outputs.version }}" --token "${{ secrets.MOKOGITEA_TOKEN }}" --org "${GITEA_ORG}" --repo "${GITEA_REPO}" --gitea-url "${GITEA_URL}"
|
||||
php /tmp/mokoplatform-api/cli/updates_xml_sync.php --path . --current "${{ github.ref_name }}" --branches main,dev --version "${{ steps.meta.outputs.version }}" --token "${{ secrets.GA_TOKEN }}" --org "${GITEA_ORG}" --repo "${GITEA_REPO}" --gitea-url "${GITEA_URL}"
|
||||
|
||||
- name: "Delete lesser pre-release channels (cascade)"
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
STABILITY="${{ steps.meta.outputs.stability }}"
|
||||
|
||||
# Cascade: rc → beta,alpha,dev | beta → alpha,dev | alpha → dev | dev → nothing
|
||||
|
||||
@@ -81,7 +81,7 @@ jobs:
|
||||
- name: Check actor permission (admin only)
|
||||
id: perm
|
||||
env:
|
||||
TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
ACTOR: ${{ github.actor }}
|
||||
run: |
|
||||
|
||||
@@ -67,12 +67,12 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check actor permission
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
ACTOR="${{ github.actor }}"
|
||||
# Schedule triggers use github-actions[bot]
|
||||
@@ -185,7 +185,7 @@ jobs:
|
||||
- name: Reset labels to standard set
|
||||
if: steps.tasks.outputs.reset_labels == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
echo "## 🏷️ Label Reset" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -267,7 +267,7 @@ jobs:
|
||||
- name: Delete old sync branches
|
||||
if: steps.tasks.outputs.clean_branches == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CURRENT="chore/sync-mokostandards-v04.05"
|
||||
@@ -295,7 +295,7 @@ jobs:
|
||||
- name: Clean up workflow runs
|
||||
if: steps.tasks.outputs.clean_workflows == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
echo "## 🔄 Workflow Run Cleanup" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -317,7 +317,7 @@ jobs:
|
||||
- name: Delete old workflow run logs
|
||||
if: steps.tasks.outputs.clean_logs == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CUTOFF=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-30d +%Y-%m-%dT%H:%M:%SZ)
|
||||
@@ -494,7 +494,7 @@ jobs:
|
||||
- name: Delete old closed issues
|
||||
if: steps.tasks.outputs.delete_closed_issues == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CUTOFF=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-30d +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
@@ -506,8 +506,8 @@ jobs:
|
||||
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -1970,8 +1970,8 @@ jobs:
|
||||
|
||||
- name: Install API Package
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
if [ -f "composer.json" ]; then
|
||||
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
|
||||
@@ -2042,8 +2042,8 @@ jobs:
|
||||
|
||||
- name: Install API Package
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
if [ -f "composer.json" ]; then
|
||||
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
|
||||
@@ -2537,7 +2537,7 @@ jobs:
|
||||
- name: Create or reopen tracking issue for standards violations
|
||||
if: failure()
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
RUN_URL="${{ github.server_url }}/${REPO}/actions/runs/${{ github.run_id }}"
|
||||
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up PHP
|
||||
@@ -55,8 +55,8 @@ jobs:
|
||||
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
--create-issue \
|
||||
--repo "${{ github.repository }}"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
|
||||
- name: Commit updated files
|
||||
if: ${{ steps.readme_version.outputs.skip != 'true' && inputs.dry_run != true }}
|
||||
|
||||
@@ -32,7 +32,7 @@ jobs:
|
||||
steps:
|
||||
- name: Assign unassigned issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
ASSIGNEE="jmiller"
|
||||
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
steps:
|
||||
- name: Create tracking issue and sub-issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
# For manual dispatch, use input; for auto, use event ref
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
|
||||
@@ -59,13 +59,13 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -275,7 +275,7 @@ jobs:
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
steps.check.outputs.tag_exists != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
|
||||
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
- name: Discover target branches
|
||||
id: branches
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
|
||||
@@ -93,7 +93,7 @@ jobs:
|
||||
- name: Cascade to all target branches
|
||||
if: steps.branches.outputs.targets != ''
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
SHORT_SHA="${GITHUB_SHA:0:7}"
|
||||
|
||||
@@ -84,7 +84,7 @@ jobs:
|
||||
# Prefer the org-scoped GH_TOKEN secret (needed for the org membership
|
||||
# fallback). Falls back to the built-in github.token so the collaborator
|
||||
# endpoint still works even if GH_TOKEN is not configured.
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
ACTOR="${{ github.actor }}"
|
||||
REPO="${{ github.repository }}"
|
||||
@@ -421,8 +421,8 @@ jobs:
|
||||
- name: Setup MokoStandards deploy tools
|
||||
if: steps.source.outputs.skip == 'false' && steps.remote.outputs.skip != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -647,7 +647,7 @@ jobs:
|
||||
- name: Create or update failure issue
|
||||
if: failure() && steps.remote.outputs.skip != 'true' && steps.conn.outputs.skip != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
RUN_URL="${{ github.server_url }}/${REPO}/actions/runs/${{ github.run_id }}"
|
||||
|
||||
@@ -89,7 +89,7 @@ jobs:
|
||||
# Prefer the org-scoped GH_TOKEN secret (needed for the org membership
|
||||
# fallback). Falls back to the built-in github.token so the collaborator
|
||||
# endpoint still works even if GH_TOKEN is not configured.
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
ACTOR="${{ github.actor }}"
|
||||
REPO="${{ github.repository }}"
|
||||
@@ -421,8 +421,8 @@ jobs:
|
||||
- name: Setup MokoStandards deploy tools
|
||||
if: steps.source.outputs.skip == 'false' && steps.remote.outputs.skip != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
# ── Build ────────────────────────────────────────────────────────
|
||||
@@ -89,8 +89,8 @@ jobs:
|
||||
# ── Version ──────────────────────────────────────────────────────
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -212,7 +212,7 @@ jobs:
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
steps.check.outputs.tag_exists != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
|
||||
|
||||
@@ -67,12 +67,12 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check actor permission
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
ACTOR="${{ github.actor }}"
|
||||
# Schedule triggers use github-actions[bot]
|
||||
@@ -185,7 +185,7 @@ jobs:
|
||||
- name: Reset labels to standard set
|
||||
if: steps.tasks.outputs.reset_labels == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
echo "## 🏷️ Label Reset" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -267,7 +267,7 @@ jobs:
|
||||
- name: Delete old sync branches
|
||||
if: steps.tasks.outputs.clean_branches == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CURRENT="chore/sync-mokostandards-v04.05"
|
||||
@@ -295,7 +295,7 @@ jobs:
|
||||
- name: Clean up workflow runs
|
||||
if: steps.tasks.outputs.clean_workflows == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
echo "## 🔄 Workflow Run Cleanup" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -317,7 +317,7 @@ jobs:
|
||||
- name: Delete old workflow run logs
|
||||
if: steps.tasks.outputs.clean_logs == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CUTOFF=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-30d +%Y-%m-%dT%H:%M:%SZ)
|
||||
@@ -494,7 +494,7 @@ jobs:
|
||||
- name: Delete old closed issues
|
||||
if: steps.tasks.outputs.delete_closed_issues == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CUTOFF=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-30d +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
@@ -506,8 +506,8 @@ jobs:
|
||||
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -1970,8 +1970,8 @@ jobs:
|
||||
|
||||
- name: Install API Package
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
if [ -f "composer.json" ]; then
|
||||
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
|
||||
@@ -2042,8 +2042,8 @@ jobs:
|
||||
|
||||
- name: Install API Package
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
if [ -f "composer.json" ]; then
|
||||
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
|
||||
@@ -2537,7 +2537,7 @@ jobs:
|
||||
- name: Create or reopen tracking issue for standards violations
|
||||
if: failure()
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
RUN_URL="${{ github.server_url }}/${REPO}/actions/runs/${{ github.run_id }}"
|
||||
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up PHP
|
||||
@@ -55,8 +55,8 @@ jobs:
|
||||
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
--create-issue \
|
||||
--repo "${{ github.repository }}"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
|
||||
- name: Commit updated files
|
||||
if: ${{ steps.readme_version.outputs.skip != 'true' && inputs.dry_run != true }}
|
||||
|
||||
@@ -32,7 +32,7 @@ jobs:
|
||||
steps:
|
||||
- name: Assign unassigned issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
ASSIGNEE="jmiller"
|
||||
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
steps:
|
||||
- name: Create tracking issue and sub-issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
# For manual dispatch, use input; for auto, use event ref
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
|
||||
@@ -55,14 +55,14 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
token: ${{ secrets.GA_TOKEN }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT }}"}}'
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN }}"}}'
|
||||
run: |
|
||||
# Ensure PHP + Composer are available
|
||||
if ! command -v composer &> /dev/null; then
|
||||
@@ -287,7 +287,7 @@ jobs:
|
||||
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
|
||||
git config --local user.name "gitea-actions[bot]"
|
||||
# Set push URL with token for branch-protected repos
|
||||
git remote set-url origin "https://jmiller:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git add -A
|
||||
git commit -m "chore(release): build ${VERSION} [skip ci]" \
|
||||
--author="gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>"
|
||||
@@ -350,20 +350,20 @@ jobs:
|
||||
RELEASE_NAME="${EXT_NAME} ${VERSION} (${TYPE_PREFIX}${EXT_ELEMENT}-${VERSION})"
|
||||
|
||||
# Delete existing release if present (overwrite, not append)
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/tags/${RELEASE_TAG}" 2>/dev/null || true)
|
||||
EXISTING_ID=$(echo "$EXISTING" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$EXISTING_ID" ]; then
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/${EXISTING_ID}" 2>/dev/null || true
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sS -X DELETE -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/tags/${RELEASE_TAG}" 2>/dev/null || true
|
||||
echo "Deleted previous stable release (id: ${EXISTING_ID})"
|
||||
fi
|
||||
|
||||
# Create fresh release
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${API_BASE}/releases" \
|
||||
-d "$(python3 -c "import json; print(json.dumps({
|
||||
@@ -385,7 +385,7 @@ jobs:
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
|
||||
# All ZIPs upload to the major release tag (vXX)
|
||||
RELEASE_JSON=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
RELEASE_JSON=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/tags/${RELEASE_TAG}" 2>/dev/null || true)
|
||||
RELEASE_ID=$(echo "$RELEASE_JSON" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
@@ -444,7 +444,7 @@ jobs:
|
||||
SHA256_TAR=$(sha256sum "/tmp/${TAR_NAME}" | cut -d' ' -f1)
|
||||
|
||||
# -- Delete existing assets with same name before uploading ------
|
||||
ASSETS=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
ASSETS=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets" 2>/dev/null || echo "[]")
|
||||
for ASSET_NAME in "$ZIP_NAME" "$TAR_NAME"; do
|
||||
ASSET_ID=$(echo "$ASSETS" | python3 -c "
|
||||
@@ -455,18 +455,18 @@ jobs:
|
||||
print(a['id']); break
|
||||
" 2>/dev/null || true)
|
||||
if [ -n "$ASSET_ID" ]; then
|
||||
curl -sf -X DELETE -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X DELETE -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets/${ASSET_ID}" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
# -- Upload both to release tag ----------------------------------
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"/tmp/${ZIP_NAME}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets?name=${ZIP_NAME}" > /dev/null 2>&1 || true
|
||||
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"/tmp/${TAR_NAME}" \
|
||||
"${API_BASE}/releases/${RELEASE_ID}/assets?name=${TAR_NAME}" > /dev/null 2>&1 || true
|
||||
@@ -523,7 +523,7 @@ jobs:
|
||||
git push || true
|
||||
|
||||
# Sync updates.xml to main via direct API (always runs — may be on version/XX branch)
|
||||
GA_TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
GA_TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
API="${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}"
|
||||
|
||||
FILE_SHA=$(curl -sf -H "Authorization: token ${GA_TOKEN}" \
|
||||
@@ -605,7 +605,7 @@ jobs:
|
||||
[ -n "$SHA256_TAR" ] && BODY="${BODY}| \`${TAR_NAME}\` | \`${SHA256_TAR}\` |\n"
|
||||
|
||||
# Get release ID and update body
|
||||
RELEASE_ID=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
RELEASE_ID=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
|
||||
"${API_BASE}/releases/tags/${RELEASE_TAG}" 2>/dev/null | \
|
||||
python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true)
|
||||
|
||||
@@ -617,7 +617,7 @@ jobs:
|
||||
req = urllib.request.Request(
|
||||
'${API_BASE}/releases/${RELEASE_ID}',
|
||||
data=data,
|
||||
headers={'Authorization': 'token ${{ secrets.MOKOGITEA_TOKEN }}', 'Content-Type': 'application/json'},
|
||||
headers={'Authorization': 'token ${{ secrets.GA_TOKEN }}', 'Content-Type': 'application/json'},
|
||||
method='PATCH'
|
||||
)
|
||||
urllib.request.urlopen(req)
|
||||
@@ -629,10 +629,10 @@ jobs:
|
||||
if: >-
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
steps.version.outputs.stability == 'stable' &&
|
||||
secrets.GH_PAT != ''
|
||||
secrets.GH_TOKEN != ''
|
||||
continue-on-error: true
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
run: |
|
||||
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
|
||||
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
|
||||
@@ -644,7 +644,7 @@ jobs:
|
||||
[ -z "$NOTES" ] && NOTES="Release ${VERSION}"
|
||||
echo "$NOTES" > /tmp/release_notes.md
|
||||
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".tag_name // empty" || true)
|
||||
EXISTING=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".tag_name // empty" || true)
|
||||
|
||||
if [ -z "$EXISTING" ]; then
|
||||
gh release create "$RELEASE_TAG" \
|
||||
@@ -661,8 +661,8 @@ jobs:
|
||||
# Upload assets to GitHub mirror
|
||||
for PKG in /tmp/${EXT_ELEMENT:-pkg}-${VERSION}.*; do
|
||||
if [ -f "$PKG" ]; then
|
||||
_RELID=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".id // empty")
|
||||
[ -n "$_RELID" ] && curl -sf -X POST -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" -H "Content-Type: application/octet-stream" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/${_RELID}/assets?name=$(basename $PKG)" --data-binary "@$PKG" > /dev/null 2>&1 || true
|
||||
_RELID=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" 2>/dev/null | jq -r ".id // empty")
|
||||
[ -n "$_RELID" ] && curl -sf -X POST -H "Authorization: token ${{ secrets.GA_TOKEN }}" -H "Content-Type: application/octet-stream" "${GITEA_URL:-https://git.mokoconsulting.tech}/api/v1/repos/${{ github.repository }}/releases/${_RELID}/assets?name=$(basename $PKG)" --data-binary "@$PKG" > /dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
echo "GitHub mirror updated: ${GH_REPO} ${RELEASE_TAG}" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -671,14 +671,14 @@ jobs:
|
||||
- name: "Step 10: Push main to GitHub mirror"
|
||||
if: >-
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
secrets.GH_PAT != ''
|
||||
secrets.GH_TOKEN != ''
|
||||
continue-on-error: true
|
||||
run: |
|
||||
GH_REPO="${{ vars.GH_MIRROR_REPO || github.repository }}"
|
||||
GH_ORG=$(echo "$GH_REPO" | cut -d/ -f1)
|
||||
GH_NAME=$(echo "$GH_REPO" | cut -d/ -f2)
|
||||
git remote add github "https://x-access-token:${{ secrets.GH_PAT }}@github.com/${GH_ORG}/${GH_NAME}.git" 2>/dev/null || \
|
||||
git remote set-url github "https://x-access-token:${{ secrets.GH_PAT }}@github.com/${GH_ORG}/${GH_NAME}.git"
|
||||
git remote add github "https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git" 2>/dev/null || \
|
||||
git remote set-url github "https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git"
|
||||
git fetch origin main --depth=1
|
||||
git push github origin/main:refs/heads/main --force 2>/dev/null \
|
||||
&& echo "main branch pushed to GitHub mirror" \
|
||||
@@ -691,7 +691,7 @@ jobs:
|
||||
run: |
|
||||
php /tmp/mokoplatform-api/cli/release_cascade.php \
|
||||
--stability stable \
|
||||
--token "${{ secrets.MOKOGITEA_TOKEN }}" \
|
||||
--token "${{ secrets.GA_TOKEN }}" \
|
||||
--org "${GITEA_ORG}" --repo "${GITEA_REPO}" \
|
||||
--gitea-url "${GITEA_URL}" 2>/dev/null || true
|
||||
|
||||
@@ -700,7 +700,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
|
||||
# Delete dev branch
|
||||
curl -sf -X DELETE -H "Authorization: token ${TOKEN}" \
|
||||
@@ -724,7 +724,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
MOD_FILE="${{ steps.platform.outputs.mod_file }}"
|
||||
ENCODED_PATH=$(echo "$MOD_FILE" | sed 's|^\./||' | python3 -c "import sys,urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip()))")
|
||||
FILE_RESP=$(curl -sf -H "Authorization: token ${TOKEN}" "${API_BASE}/contents/${ENCODED_PATH}?ref=dev" 2>/dev/null || true)
|
||||
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
- name: Discover target branches
|
||||
id: branches
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
|
||||
@@ -93,7 +93,7 @@ jobs:
|
||||
- name: Cascade to all target branches
|
||||
if: steps.branches.outputs.targets != ''
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
SHORT_SHA="${GITHUB_SHA:0:7}"
|
||||
|
||||
@@ -33,11 +33,11 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
token: ${{ secrets.GA_TOKEN }}
|
||||
|
||||
- name: Delete merged branches
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
echo "=== Merged Branch Cleanup ==="
|
||||
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
|
||||
@@ -66,7 +66,7 @@ jobs:
|
||||
|
||||
- name: Clean old workflow runs
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
run: |
|
||||
echo "=== Workflow Run Cleanup ==="
|
||||
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
|
||||
|
||||
@@ -42,10 +42,10 @@ jobs:
|
||||
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
MOKO_CLONE_HOST: ${{ secrets.MOKOGITEA_TOKEN && 'git.mokoconsulting.tech/MokoConsulting' || 'github.com/mokoconsulting-tech' }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.MOKOGITEA_TOKEN || github.token }}"}}'
|
||||
GA_TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
MOKO_CLONE_HOST: ${{ secrets.GA_TOKEN && 'git.mokoconsulting.tech/MokoConsulting' || 'github.com/mokoconsulting-tech' }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GA_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch main --quiet \
|
||||
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokoplatform.git" \
|
||||
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
# ── Build ────────────────────────────────────────────────────────
|
||||
@@ -89,8 +89,8 @@ jobs:
|
||||
# ── Version ──────────────────────────────────────────────────────
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -212,7 +212,7 @@ jobs:
|
||||
steps.version.outputs.skip != 'true' &&
|
||||
steps.check.outputs.tag_exists != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
|
||||
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
token: ${{ secrets.GA_TOKEN }}
|
||||
|
||||
- name: Setup PHP
|
||||
run: |
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
|
||||
- name: Setup mokoplatform tools
|
||||
env:
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
|
||||
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
|
||||
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
|
||||
run: |
|
||||
git clone --depth 1 --branch main --quiet "https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/mokoplatform.git" /tmp/mokoplatform-api
|
||||
@@ -89,7 +89,7 @@ jobs:
|
||||
# Commit version bump
|
||||
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
|
||||
git config --local user.name "gitea-actions[bot]"
|
||||
git remote set-url origin "https://jmiller:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
|
||||
git add -A
|
||||
git diff --cached --quiet || {
|
||||
git commit -m "chore(version): bump to ${VERSION} [skip ci]"
|
||||
@@ -154,7 +154,7 @@ jobs:
|
||||
SHA256="${{ steps.zip.outputs.sha256 }}"
|
||||
ZIP_NAME="${{ steps.zip.outputs.zip_name }}"
|
||||
EXT_ELEMENT="${{ steps.meta.outputs.ext_element }}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
BRANCH=$(git branch --show-current)
|
||||
|
||||
@@ -212,13 +212,13 @@ jobs:
|
||||
- name: "Sync updates.xml to all branches"
|
||||
if: steps.platform.outputs.platform == 'joomla'
|
||||
run: |
|
||||
php /tmp/mokoplatform-api/cli/updates_xml_sync.php --path . --current "${{ github.ref_name }}" --branches main,dev --version "${{ steps.meta.outputs.version }}" --token "${{ secrets.MOKOGITEA_TOKEN }}" --org "${GITEA_ORG}" --repo "${GITEA_REPO}" --gitea-url "${GITEA_URL}"
|
||||
php /tmp/mokoplatform-api/cli/updates_xml_sync.php --path . --current "${{ github.ref_name }}" --branches main,dev --version "${{ steps.meta.outputs.version }}" --token "${{ secrets.GA_TOKEN }}" --org "${GITEA_ORG}" --repo "${GITEA_REPO}" --gitea-url "${GITEA_URL}"
|
||||
|
||||
- name: "Delete lesser pre-release channels (cascade)"
|
||||
continue-on-error: true
|
||||
run: |
|
||||
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
|
||||
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
|
||||
TOKEN="${{ secrets.GA_TOKEN }}"
|
||||
STABILITY="${{ steps.meta.outputs.stability }}"
|
||||
|
||||
# Cascade: rc → beta,alpha,dev | beta → alpha,dev | alpha → dev | dev → nothing
|
||||
|
||||
@@ -81,7 +81,7 @@ jobs:
|
||||
- name: Check actor permission (admin only)
|
||||
id: perm
|
||||
env:
|
||||
TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
|
||||
TOKEN: ${{ secrets.GA_TOKEN || secrets.GA_TOKEN || github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
ACTOR: ${{ github.actor }}
|
||||
run: |
|
||||
|
||||
@@ -67,12 +67,12 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check actor permission
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
ACTOR="${{ github.actor }}"
|
||||
# Schedule triggers use github-actions[bot]
|
||||
@@ -185,7 +185,7 @@ jobs:
|
||||
- name: Reset labels to standard set
|
||||
if: steps.tasks.outputs.reset_labels == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
echo "## 🏷️ Label Reset" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -267,7 +267,7 @@ jobs:
|
||||
- name: Delete old sync branches
|
||||
if: steps.tasks.outputs.clean_branches == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CURRENT="chore/sync-mokostandards-v04.05"
|
||||
@@ -295,7 +295,7 @@ jobs:
|
||||
- name: Clean up workflow runs
|
||||
if: steps.tasks.outputs.clean_workflows == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
echo "## 🔄 Workflow Run Cleanup" >> $GITHUB_STEP_SUMMARY
|
||||
@@ -317,7 +317,7 @@ jobs:
|
||||
- name: Delete old workflow run logs
|
||||
if: steps.tasks.outputs.clean_logs == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CUTOFF=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-30d +%Y-%m-%dT%H:%M:%SZ)
|
||||
@@ -494,7 +494,7 @@ jobs:
|
||||
- name: Delete old closed issues
|
||||
if: steps.tasks.outputs.delete_closed_issues == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
CUTOFF=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-30d +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
@@ -506,8 +506,8 @@ jobs:
|
||||
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -1970,8 +1970,8 @@ jobs:
|
||||
|
||||
- name: Install API Package
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
if [ -f "composer.json" ]; then
|
||||
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
|
||||
@@ -2042,8 +2042,8 @@ jobs:
|
||||
|
||||
- name: Install API Package
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
if [ -f "composer.json" ]; then
|
||||
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
|
||||
@@ -2537,7 +2537,7 @@ jobs:
|
||||
- name: Create or reopen tracking issue for standards violations
|
||||
if: failure()
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
RUN_URL="${{ github.server_url }}/${REPO}/actions/runs/${{ github.run_id }}"
|
||||
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT || github.token }}
|
||||
token: ${{ secrets.GH_TOKEN || github.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up PHP
|
||||
@@ -55,8 +55,8 @@ jobs:
|
||||
|
||||
- name: Setup MokoStandards tools
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_PAT || github.token }}"}}'
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN || github.token }}"}}'
|
||||
run: |
|
||||
git clone --depth 1 --branch version/04 --quiet \
|
||||
"https://x-access-token:${GH_TOKEN}@github.com/mokoconsulting-tech/MokoStandards.git" \
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
--create-issue \
|
||||
--repo "${{ github.repository }}"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
|
||||
- name: Commit updated files
|
||||
if: ${{ steps.readme_version.outputs.skip != 'true' && inputs.dry_run != true }}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
DEFGROUP:
|
||||
INGROUP: Project.Documentation
|
||||
REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoStandards-Template-Generic
|
||||
VERSION: 09.29.01
|
||||
VERSION: 09.26.02
|
||||
PATH: ./CONTRIBUTING.md
|
||||
BRIEF: Contribution guidelines for the project
|
||||
-->
|
||||
|
||||
@@ -73,7 +73,7 @@ joomla-api-mcp wraps the entire Joomla Web Services REST API into MCP tools that
|
||||
| Repo | Purpose |
|
||||
|------|---------|
|
||||
| [backup-mcp](https://git.mokoconsulting.tech/MokoConsulting/backup-mcp/wiki) | Backup MCP (uses Joomla API for Akeeba) |
|
||||
| [MokoSuite](https://git.mokoconsulting.tech/MokoConsulting/MokoSuite/wiki) | Joomla Suite system plugin |
|
||||
| [MokoSuiteClient](https://git.mokoconsulting.tech/MokoConsulting/MokoSuiteClient/wiki) | Joomla Suite client tracker |
|
||||
| [Template-Client-Suite](https://git.mokoconsulting.tech/MokoConsulting/Template-Client-Suite/wiki) | Client site template |
|
||||
| [MokoOnyx](https://git.mokoconsulting.tech/MokoConsulting/MokoOnyx/wiki) | Joomla admin template |
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ DEFGROUP: [PROJECT_NAME]
|
||||
INGROUP: [PROJECT_NAME].Documentation
|
||||
REPO: [REPOSITORY_URL]
|
||||
PATH: /SECURITY.md
|
||||
VERSION: 09.29.01
|
||||
VERSION: 09.26.02
|
||||
BRIEF: Security vulnerability reporting and handling policy
|
||||
-->
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ jobs:
|
||||
steps:
|
||||
- name: Assign unassigned issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
REPO="${{ github.repository }}"
|
||||
ASSIGNEE="jmiller"
|
||||
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
steps:
|
||||
- name: Create tracking issue and sub-issues
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || github.token }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
|
||||
run: |
|
||||
# For manual dispatch, use input; for auto, use event ref
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user