Skip to content

code2docs-ai agent job #329

code2docs-ai agent job

code2docs-ai agent job #329

Workflow file for this run

name: code2docs-ai agent job
on:
workflow_dispatch:
inputs:
repoUrl:
description: 'The GitHub repository URL in HTTPS format'
required: true
branchName:
description: 'The branch name to use'
default: 'main'
repoVersionId:
description: 'The version id of the table'
serverEndPoint:
description: 'The server end point of the code2docs-api'
jobs:
create-repo:
runs-on: self-hosted
steps:
- name: Clean up working directory
run: |
rm -rf *
- name: Install jq
run: sudo apt-get install -y jq
- name: Print input parameters
run: |
echo "repoUrl: ${{ github.event.inputs.repoUrl }}"
echo "branchName: ${{ github.event.inputs.branchName }}"
echo "REPO_VERSION_ID=${{ github.event.inputs.repoVersionId }}" >> $GITHUB_ENV
echo "SERVER_ENDPOINT=${{ github.event.inputs.serverEndPoint }}" >> $GITHUB_ENV
- name: Validate repoUrl
run: |
if [[ "${{ github.event.inputs.repoUrl }}" != https://github.com/* ]]; then
echo "Error: repoUrl must be a GitHub.com address and a HTTPS address."
exit 1
fi
repo_status=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${{ secrets.MY_PAT }}" \
"${{ github.event.inputs.repoUrl }}")
if [[ "$repo_status" != "200" ]]; then
echo "Error: repoUrl does not exist on GitHub or is not publicly accessible."
exit 1
fi
- name: Extract orgName and repoName
id: extract
run: |
orgName=$(echo "${{ github.event.inputs.repoUrl }}" | cut -d'/' -f4)
repoName=$(echo "${{ github.event.inputs.repoUrl }}" | cut -d'/' -f5 | cut -d'.' -f1)
echo "orgName=$orgName" >> $GITHUB_ENV
echo "repoName=$repoName" >> $GITHUB_ENV
docs_repo_name="${orgName}_${repoName}"
echo "docs_repo_name=$docs_repo_name" >> $GITHUB_ENV
- name: Print extracted variables
run: |
echo "orgName is: ${{ env.orgName }}"
echo "repoName is: ${{ env.repoName }}"
echo "docs_repo_name is: ${{ env.docs_repo_name }}"
- name: Check if docs-repo exists
id: check-repo
run: |
repo_exists=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${{ secrets.MY_PAT }}" \
https://api.github.com/repos/code2docs-ai/${{ env.docs_repo_name }})
echo "repo_exists=$repo_exists" >> $GITHUB_ENV
- name: Delete existing docs-repo
if: env.repo_exists == '200'
run: |
curl -X DELETE -H "Authorization: token ${{ secrets.MY_PAT }}" \
https://api.github.com/repos/code2docs-ai/${{ env.docs_repo_name }}
- name: Create new docs-repo
run: |
curl --fail -X POST -H "Authorization: token ${{ secrets.MY_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/orgs/code2docs-ai/repos \
-d '{"name":"${{ env.docs_repo_name }}","private":false}' || exit 1
- name: Clone the newly created repo
run: |
if [ -d "${{ env.docs_repo_name }}" ]; then
rm -rf ${{ env.docs_repo_name }}
fi
git clone https://github.com/code2docs-ai/${{ env.docs_repo_name }}.git
cd ${{ env.docs_repo_name }}
echo "# Docs written by code2docs-ai agent" > README.md
git config --global user.email "[email protected]"
git config --global user.name "code2docs-ai agent"
git add README.md
git commit -m "Add README.md"
git push https://code2docs-ai:${{ secrets.MY_PAT }}@github.com/code2docs-ai/${{ env.docs_repo_name }}.git main
- name: Check if source_repo exists and delete it
run: |
if [ -d "${{ env.repoName }}" ]; then
rm -rf ${{ env.repoName }}
fi
- name: Clone the source and update repo versions
env:
SERVER_ENDPOINT: ${{ env.SERVER_ENDPOINT }}
REPO_VERSION_ID: ${{ env.REPO_VERSION_ID }}
WORKFLOW_ID: ${{ github.run_id }}
run: |
git clone ${{ github.event.inputs.repoUrl }} ${{ env.repoName }}
cd ${{ env.repoName }}
file_count=$(find . -type f | wc -l)
latest_commit_id=$(git rev-parse HEAD)
DATA=$(jq -n \
--arg id "$REPO_VERSION_ID" \
--arg workflow_id "$WORKFLOW_ID" \
--arg status "in_progress(parse-repo)" \
--argjson file_count "$(echo $file_count | sed 's/[^0-9]*//g')" \
--arg commit_id "$latest_commit_id" \
'{
id: $id,
workflow_id: $workflow_id,
status: $status,
file_count: $file_count,
current_commit_id: $commit_id
}') || { echo "Failed to generate JSON"; exit 1; }
echo "Generated JSON: $DATA"
curl_response=$(curl --fail -k -v -X POST -L "$SERVER_ENDPOINT/github/update/repo-versions" \
-H "Content-Type: application/json" \
-d "$DATA" 2>&1) || { echo "API call failed. Log: $curl_response"; exit 1; }
- name: Run aise-cli parse-repo
run: |
source /data/source/aise-cli/.venv/bin/activate
aise-cli version
aise-cli repo delete-repo ${{ env.repoName }}
aise-cli repo parse-repo --repo_path ./${{ env.repoName }}
- name: Send llm-explain-code status
env:
SERVER_ENDPOINT: ${{ env.SERVER_ENDPOINT }}
REPO_VERSION_ID: ${{ env.REPO_VERSION_ID }}
run: |
DATA=$(jq -n \
--arg id "$REPO_VERSION_ID" \
--arg status "in_progress(llm-explain-code)" \
'{
id: $id,
status: $status,
}')
echo "Sending: $DATA"
curl -v --fail -k -X POST "$SERVER_ENDPOINT/github/update/repo-versions" \
-H "Content-Type: application/json" \
-d "$DATA" \
&& echo "Update succeeded" \
|| { echo "Update failed"; exit 1; }
- name: Run aise-cli explain-code
run: |
source /data/source/aise-cli/.venv/bin/activate
aise-cli repo llm-explain-code --repo_name ${{ env.repoName }}
- name: Send llm-summary status
env:
SERVER_ENDPOINT: ${{ env.SERVER_ENDPOINT }}
REPO_VERSION_ID: ${{ env.REPO_VERSION_ID }}
run: |
DATA=$(jq -n \
--arg id "$REPO_VERSION_ID" \
--arg status "in_progress(llm-summary)" \
'{
id: $id,
status: $status,
}')
echo "Sending: $DATA"
curl -v --fail -k -X POST "$SERVER_ENDPOINT/github/update/repo-versions" \
-H "Content-Type: application/json" \
-d "$DATA" \
&& echo "Update succeeded" \
|| { echo "Update failed"; exit 1; }
- name: Run aise-cli summary repo
run: |
source /data/source/aise-cli/.venv/bin/activate
aise-cli repo llm-summary --repo_name ${{ env.repoName }}
- name: Send export-docs status
env:
SERVER_ENDPOINT: ${{ env.SERVER_ENDPOINT }}
REPO_VERSION_ID: ${{ env.REPO_VERSION_ID }}
run: |
DATA=$(jq -n \
--arg id "$REPO_VERSION_ID" \
--arg status "in_progress(export-docs)" \
'{
id: $id,
status: $status,
}')
echo "Sending: $DATA"
curl -v --fail -k -X POST "$SERVER_ENDPOINT/github/update/repo-versions" \
-H "Content-Type: application/json" \
-d "$DATA" \
&& echo "Update succeeded" \
|| { echo "Update failed"; exit 1; }
- name: Run aise-cli export-docs
run: |
source /data/source/aise-cli/.venv/bin/activate
cd ${{ env.docs_repo_name }}
REPO_DIR_ABS="$(cd .. && pwd)/${{ env.repoName }}"
aise-cli repo export-docs --repo_name ${{ env.repoName }} --repo_dic $REPO_DIR_ABS --output_path ./
mv -f ${{ env.repoName }}/* .
rmdir ${{ env.repoName }}
git add .
git commit -m "Generate document for ${{ env.repoName }}"
git push https://code2docs-ai:${{ secrets.MY_PAT }}@github.com/code2docs-ai/${{ env.docs_repo_name }}.git main
- name: Send final status
env:
SERVER_ENDPOINT: ${{ env.SERVER_ENDPOINT }}
REPO_VERSION_ID: ${{ env.REPO_VERSION_ID }}
if: always()
run: |
AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
if [[ "${{ job.status }}" == "success" ]]; then
STATUS="completed"
DOCS_URL="https://github.com/code2docs-ai/${{ env.docs_repo_name }}"
COMPLETED_AT="$AT"
else
STATUS="failed"
DOCS_URL="null"
COMPLETED_AT="null"
fi
UPDATE_AT="$AT"
UPDATE_BY="workflow_processing"
DATA=$(jq -n \
--arg id "$REPO_VERSION_ID" \
--arg status "$STATUS" \
--arg docs_url "$DOCS_URL" \
--arg completed_at "$COMPLETED_AT" \
--arg update_at "$UPDATE_AT" \
--arg update_by "$UPDATE_BY" \
'{
id: $id,
status: $status,
docs_url: (if $docs_url == "null" then null else $docs_url end),
completed_at: (if $completed_at == "null" then null else $completed_at end),
update_at: $update_at,
update_by: $update_by
}')
echo "Sending: $DATA"
curl -v --fail -k -X POST "$SERVER_ENDPOINT/github/update/repo-versions" \
-H "Content-Type: application/json" \
-d "$DATA" \
&& echo "Update succeeded" \
|| { echo "Update failed"; exit 1; }