code2docs-ai agent job #26
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 workflow | |
| 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: ubuntu-latest | |
| steps: | |
| - 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 | |
| - 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: | | |
| 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 |