Skip to content

Skill Request

Skill Request #47

Workflow file for this run

name: Skill Request
on:
issues:
types:
- opened
- reopened
permissions:
issues: write
contents: read
jobs:
generate-skill:
if: contains(github.event.issue.labels.*.name, 'skill-request')
runs-on: ubuntu-latest
env:
APP_ID: 3744672
APP_SLUG: cortex-ai-devkit-bot
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Parse issue body
id: parse
uses: stefanbuck/github-issue-parser@v3
with:
template-path: .github/ISSUE_TEMPLATE/skill-request.yml
- name: Resolve inputs
id: inputs
env:
CONTEXT: ${{ steps.parse.outputs.issueparser_context }}
ACTION: ${{ steps.parse.outputs.issueparser_action }}
TARGET: ${{ steps.parse.outputs.issueparser_target }}
SKILL_DESCRIPTION: ${{ steps.parse.outputs.issueparser_skill_description }}
SKILL_TOOLS: ${{ steps.parse.outputs.issueparser_skill_tools }}
SKILL_AUTHORS: ${{ steps.parse.outputs.issueparser_skill_authors }}
TARGET_ORG: ${{ steps.parse.outputs.issueparser_target_organization }}
run: |
set -euo pipefail
CONTEXT_TRIM="$(echo "$CONTEXT" | xargs | tr '[:upper:]' '[:lower:]')"
ACTION_TRIM="$(echo "$ACTION" | xargs | tr '[:upper:]' '[:lower:]')"
TARGET_TRIM="$(echo "$TARGET" | xargs | tr '[:upper:]' '[:lower:]')"
TARGET_ORG_TRIM="$(echo "${TARGET_ORG:-}" | xargs)"
[ -z "$TARGET_ORG_TRIM" ] && \
TARGET_ORG_TRIM="CortexAIDevKit"
TOOLS_JSON="$(
echo "$SKILL_TOOLS" \
| sed 's/^[[:space:]]*-[[:space:]]*//' \
| tr ',' '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
| grep -v '^$' \
| jq -R . \
| jq -s -c .
)"
AUTHORS_JSON="$(
echo "$SKILL_AUTHORS" \
| tr ',' '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
| grep -v '^$' \
| jq -R . \
| jq -s -c .
)"
{
echo "context=$CONTEXT_TRIM"
echo "action=$ACTION_TRIM"
echo "target=$TARGET_TRIM"
echo "skill_description=$(echo "$SKILL_DESCRIPTION" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g;s/^ //;s/ $//')"
echo "skill_tools=$TOOLS_JSON"
echo "skill_authors=$AUTHORS_JSON"
echo "target_organization=$TARGET_ORG_TRIM"
echo "project_name=${CONTEXT_TRIM}-${ACTION_TRIM}-${TARGET_TRIM}"
} >> "$GITHUB_OUTPUT"
- name: Preflight 1 - Verify GitHub App installation
id: app-installed
uses: actions/github-script@v8
env:
TARGET_ORG: ${{ steps.inputs.outputs.target_organization }}
APP_ID: ${{ env.APP_ID }}
PRIVATE_KEY: ${{ secrets.CORTEX_AI_DEVKIT_BOT_APP_PRIVATE_KEY }}
with:
script: |
const script = require('./.github/workflows/scripts/verify-app-installation.js');
await script({ core });
- name: Comment if app missing
if: failure() && steps.app-installed.outcome == 'failure'
env:
GH_TOKEN: ${{ github.token }}
TARGET_ORG: ${{ steps.inputs.outputs.target_organization }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
GH_REPO: ${{ github.repository }}
APP_SLUG: ${{ env.APP_SLUG }}
APP_ID: ${{ env.APP_ID }}
run: |
gh issue comment "$ISSUE_NUMBER" \
--repo "$GH_REPO" \
--body \
"❌ Preflight failed.
[Install GitHub App: **\`${APP_SLUG}\`**](https://github.com/apps/cortex-ai-devkit-bot/installations/new) on organization \`${TARGET_ORG}\`.
Please install the app on the organization and retry."
exit 1
- name: Generate app token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ env.APP_ID }}
private-key: ${{ secrets.CORTEX_AI_DEVKIT_BOT_APP_PRIVATE_KEY }}
owner: ${{ steps.inputs.outputs.target_organization }}
- name: Preflight 2 - Target repository must not already exist
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
TARGET_ORG: ${{ steps.inputs.outputs.target_organization }}
PROJECT_NAME: ${{ steps.inputs.outputs.project_name }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
GH_REPO: ${{ github.repository }}
run: .github/workflows/scripts/check-repo-available.sh "$TARGET_ORG" "$PROJECT_NAME"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install copier
run: |
pip install copier
- name: Generate project with copier
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
CONTEXT: ${{ steps.inputs.outputs.context }}
ACTION: ${{ steps.inputs.outputs.action }}
TARGET: ${{ steps.inputs.outputs.target }}
SKILL_DESCRIPTION: ${{ steps.inputs.outputs.skill_description }}
SKILL_TOOLS: ${{ steps.inputs.outputs.skill_tools }}
SKILL_AUTHORS: ${{ steps.inputs.outputs.skill_authors }}
run: |
set -euo pipefail
mkdir -p generated
cd generated
git config --global \
url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf \
"https://github.com/"
copier copy \
--defaults \
--trust \
-d "context=${CONTEXT}" \
-d "action=${ACTION}" \
-d "target=${TARGET}" \
-d "skill_description=${SKILL_DESCRIPTION}" \
-d "skill_tools=${SKILL_TOOLS}" \
-d "skill_authors=${SKILL_AUTHORS}" \
gh:CortexAIDevKit/template-github-copilot-skills \
"."
- name: Create repository, commit and push
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
TARGET_ORG: ${{ steps.inputs.outputs.target_organization }}
PROJECT_NAME: ${{ steps.inputs.outputs.project_name }}
SKILL_DESCRIPTION: ${{ steps.inputs.outputs.skill_description }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
SOURCE_REPO: ${{ github.repository }}
run: |
set -euo pipefail
REPO_FULL="${TARGET_ORG}/${PROJECT_NAME}"
gh repo create "$REPO_FULL" \
--public \
--description "$SKILL_DESCRIPTION"
gh repo edit "$REPO_FULL" \
--add-topic "copilot-skill"
.github/workflows/scripts/rewrite-repo-labels.sh \
"$REPO_FULL" \
".github/workflows/misc/labels.json"
cd generated/${PROJECT_NAME}
git init -b main
git config user.name \
"cortex-ai-devkit-bot[bot]"
git config user.email \
"cortex-ai-devkit-bot[bot]@users.noreply.github.com"
git remote add origin \
"https://x-access-token:${GH_TOKEN}@github.com/${REPO_FULL}.git"
git add .
git commit -m \
"chore: scaffold ${PROJECT_NAME} from copilot-skill-template (closes ${SOURCE_REPO}#${ISSUE_NUMBER})"
git push -u origin main
- name: Comment on issue
if: success()
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
GH_REPO: ${{ github.repository }}
TARGET_ORG: ${{ steps.inputs.outputs.target_organization }}
PROJECT_NAME: ${{ steps.inputs.outputs.project_name }}
run: |
gh issue comment "$ISSUE_NUMBER" \
--repo "$GH_REPO" \
--body \
"✅ Skill scaffolded successfully:
https://github.com/${TARGET_ORG}/${PROJECT_NAME}"