1688-product-master/.forgejo/workflows/register-skill-release.yml

126 lines
4.6 KiB
YAML
Raw Normal View History

2026-03-11 23:36:59 +00:00
name: register-skill-release
on:
release:
types: [published]
workflow_dispatch:
inputs:
skill_slug:
description: Skill slug override (optional)
required: false
skill_subpath:
description: Skill folder path override (optional)
required: false
skill_doc_path:
description: Skill doc path override
required: false
default: SKILL.md
skill_version:
description: Version override (default tag name)
required: false
jobs:
register-skill-version:
runs-on: docker
2026-03-11 23:36:59 +00:00
env:
API_BASE: ${{ vars.API_BASE || secrets.API_BASE }}
CLIENT_KEY: ${{ secrets.CLIENT_KEY }}
SKILL_VERSION: ${{ github.event.inputs.skill_version || github.ref_name }}
SKILL_SUBPATH: ${{ github.event.inputs.skill_subpath || vars.SKILL_SUBPATH || secrets.SKILL_SUBPATH }}
SKILL_DOC_PATH: ${{ github.event.inputs.skill_doc_path || vars.SKILL_DOC_PATH || secrets.SKILL_DOC_PATH || 'SKILL.md' }}
SKILL_SLUG: ${{ github.event.inputs.skill_slug || vars.SKILL_SLUG || secrets.SKILL_SLUG }}
RELEASE_NOTE: ${{ github.event.release.body }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Load skill doc content
shell: bash
run: |
set -euo pipefail
DOC_ABS_PATH="${SKILL_SUBPATH:+$SKILL_SUBPATH/}${SKILL_DOC_PATH}"
if [ ! -f "$DOC_ABS_PATH" ]; then
if [ -f "${SKILL_SUBPATH:+$SKILL_SUBPATH/}README.md" ]; then
DOC_ABS_PATH="${SKILL_SUBPATH:+$SKILL_SUBPATH/}README.md"
export SKILL_DOC_PATH="README.md"
else
echo "skill doc not found: $DOC_ABS_PATH"
exit 1
fi
fi
jq -Rs . < "$DOC_ABS_PATH" > /tmp/skill_doc.json
- name: Register version to business system
shell: bash
run: |
set -euo pipefail
if [ -z "${API_BASE:-}" ]; then
echo "API_BASE is required (global/repo var or secret)."
exit 1
fi
if [ -z "${CLIENT_KEY:-}" ]; then
echo "CLIENT_KEY is required (secret)."
exit 1
fi
SKILL_BASE_DIR="${SKILL_SUBPATH:-.}"
if [ -z "${SKILL_SLUG:-}" ]; then
if [ -f "${SKILL_BASE_DIR}/package.json" ]; then
PKG_NAME=$(jq -r '.name // empty' "${SKILL_BASE_DIR}/package.json")
if [ -n "$PKG_NAME" ]; then
# Strip npm scope: @scope/skill-name -> skill-name
SKILL_SLUG="${PKG_NAME##*/}"
fi
fi
fi
if [ -z "${SKILL_SLUG:-}" ]; then
if [ -f "${SKILL_BASE_DIR}/pyproject.toml" ]; then
PYPROJECT_NAME=$(python3 -c "import sys,tomllib; p=sys.argv[1]; d=tomllib.load(open(p,'rb')); print((d.get('project',{}).get('name') or d.get('tool',{}).get('poetry',{}).get('name') or ''))" "${SKILL_BASE_DIR}/pyproject.toml" 2>/dev/null || true)
if [ -n "$PYPROJECT_NAME" ]; then
SKILL_SLUG="${PYPROJECT_NAME##*/}"
fi
fi
fi
if [ -z "${SKILL_SLUG:-}" ]; then
SKILL_SLUG="${GITHUB_REPOSITORY##*/}"
fi
SESSION_RES=$(curl -sS -X POST "${API_BASE}/auth/skill-credit/session" \
-H "Content-Type: application/json" \
-d "{\"clientKey\":\"${CLIENT_KEY}\"}")
ACCESS_TOKEN=$(printf '%s' "$SESSION_RES" | jq -r '.accessToken // empty')
if [ -z "$ACCESS_TOKEN" ]; then
echo "failed to exchange access token from client key"
echo "$SESSION_RES"
exit 1
fi
RUNTIME_META=$(jq -nc --arg entry "${SKILL_SUBPATH:+$SKILL_SUBPATH/}scripts" '{entry_hint:$entry, provider:"forgejo"}')
cat > /tmp/register_payload.json <<JSON
{
"skill_slug": "${SKILL_SLUG}",
"version": "${SKILL_VERSION}",
"release_note": $(printf '%s' "${RELEASE_NOTE:-}" | jq -Rs .),
"source_type": "git_ci",
"repo_url": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git",
"repo_subpath": "${SKILL_SUBPATH:-}",
"git_ref": "${GITHUB_REF_NAME}",
"commit_sha": "${GITHUB_SHA}",
"skill_doc_path": "${SKILL_DOC_PATH}",
"skill_doc_content": $(cat /tmp/skill_doc.json),
"runtime_meta": ${RUNTIME_META}
}
JSON
curl -sS -X POST "${API_BASE}/ecom/skills/register-by-slug" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d @/tmp/register_payload.json