code2docs-ai agent job #223
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | |
| jobs: | |
| create-repo: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Clean up working directory | |
| run: | | |
| rm -rf * | |
| - name: Print input parameters | |
| run: | | |
| echo "repoUrl: ${{ github.event.inputs.repoUrl }}" | |
| echo "branchName: ${{ github.event.inputs.branchName }}" | |
| - 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: Check if 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 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 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 current repository and store workflow run states | |
| run: | | |
| git clone https://github.com/${{ github.repository }}.git | |
| cd code2docs-ai-core | |
| if [ ! -f workflow_runs.json ]; then | |
| echo "[]" > workflow_runs.json | |
| fi | |
| workflow_run=$(jq -n --arg id "${{ github.run_id }}" --arg repoUrl "${{ github.event.inputs.repoUrl }}" --arg branchName "${{ github.event.inputs.branchName }}" --arg docs_repo_name "${{ env.docs_repo_name }}" --arg status "in_progress" --arg created_at "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" '{id: $id, repoUrl: $repoUrl, branchName: $branchName, docs_repo_name: $docs_repo_name, status: $status, created_at: $created_at}') | |
| jq ". = [$workflow_run] + ." workflow_runs.json > tmp.json && mv tmp.json workflow_runs.json | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "code2docs-ai agent" | |
| git add workflow_runs.json | |
| git commit -m "Update workflow_runs.json" | |
| git push https://code2docs-ai:${{ secrets.MY_PAT }}@github.com/${{ github.repository }}.git main | |
| - name: Clone the source from repoUrl | |
| 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) | |
| cd .. | |
| cd code2docs-ai-core | |
| workflow_run=$(jq --arg id "${{ github.run_id }}" --arg file_count "$file_count" --arg latest_commit_id "$latest_commit_id" 'map(if .id == $id then .file_count = $file_count | .latest_commit_id = $latest_commit_id else . end)' workflow_runs.json) | |
| echo "$workflow_run" > workflow_runs.json | |
| git add workflow_runs.json | |
| git commit -m "Update workflow_runs.json with file_count and latest_commit_id" | |
| git push https://code2docs-ai:${{ secrets.MY_PAT }}@github.com/${{ github.repository }}.git main | |
| - name: Run aise-cli | |
| run: | | |
| # source /data/source/aise-cli/.venv/bin/activate | |
| # aise-cli --config_file /data/source/_temp/aise_cli_config.json version | |
| # aise-cli --config_file /data/source/_temp/aise_cli_config.json repo delete-repo ${{ env.repoName }} | |
| # aise-cli --config_file /data/source/_temp/aise_cli_config.json repo parse-repo --repo_path ./${{ env.repoName }} | |
| 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 }} | |
| cd ${{ env.docs_repo_name }} | |
| mkdir docs | |
| cd docs | |
| mkdir ${{ env.repoName }} | |
| # aise-cli --config_file /data/source/_temp/aise_cli_config.json repo export-docs --repo_name ${{ env.repoName }} --output_path ./docs/${{ env.repoName }} | |
| aise-cli repo export-docs --repo_name ${{ env.repoName }} --output_path ./docs/${{ 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: Update workflow run state | |
| run: | | |
| cd code2docs-ai-core | |
| workflow_run=$(jq --arg id "${{ github.run_id }}" --arg status "completed" --arg completed_at "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" 'map(if .id == $id then .status = $status | .completed_at = $completed_at else . end)' workflow_runs.json) | |
| echo "$workflow_run" > workflow_runs.json | |
| git add workflow_runs.json | |
| git commit -m "Update workflow_runs.json with completed status" | |
| git push https://code2docs-ai:${{ secrets.MY_PAT }}@github.com/${{ github.repository }}.git main |