solve-issue.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # Workflow that uses OpenHands to resolve a GitHub issue. Issue must be labeled 'solve-this'
  2. name: Use OpenHands to Resolve GitHub Issue
  3. on:
  4. issues:
  5. types: [labeled]
  6. permissions:
  7. contents: write
  8. pull-requests: write
  9. issues: write
  10. jobs:
  11. dogfood:
  12. if: github.event.label.name == 'solve-this'
  13. runs-on: ubuntu-latest
  14. container:
  15. image: ghcr.io/all-hands-ai/openhands
  16. volumes:
  17. - /var/run/docker.sock:/var/run/docker.sock
  18. steps:
  19. - name: install git, github cli
  20. run: apt-get install -y git gh
  21. - name: Set up Docker Buildx
  22. id: buildx
  23. uses: docker/setup-buildx-action@v3
  24. - name: Checkout Repository
  25. uses: actions/checkout@v4
  26. - name: Write Task File
  27. env:
  28. ISSUE_TITLE: ${{ github.event.issue.title }}
  29. ISSUE_BODY: ${{ github.event.issue.body }}
  30. run: |
  31. echo "TITLE:" > task.txt
  32. echo "${ISSUE_TITLE}" >> task.txt
  33. echo "" >> task.txt
  34. echo "BODY:" >> task.txt
  35. echo "${ISSUE_BODY}" >> task.txt
  36. - name: Set up environment
  37. run: |
  38. curl -sSL https://install.python-poetry.org | python3 -
  39. export PATH="/github/home/.local/bin:$PATH"
  40. poetry install --without evaluation,llama-index
  41. poetry run playwright install --with-deps chromium
  42. - name: Run OpenHands
  43. env:
  44. ISSUE_TITLE: ${{ github.event.issue.title }}
  45. ISSUE_BODY: ${{ github.event.issue.body }}
  46. LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }}
  47. OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
  48. run: |
  49. # Append path to launch poetry
  50. export PATH="/github/home/.local/bin:$PATH"
  51. # Append path to correctly import package, note: must set pwd at first
  52. export PYTHONPATH=$(pwd):$PYTHONPATH
  53. WORKSPACE_MOUNT_PATH=$GITHUB_WORKSPACE poetry run python ./openhands/core/main.py -i 50 -f task.txt -d $GITHUB_WORKSPACE
  54. rm task.txt
  55. - name: Setup Git, Create Branch, and Commit Changes
  56. run: |
  57. # Setup Git configuration
  58. git config --global --add safe.directory $PWD
  59. git config --global user.name 'OpenHands'
  60. git config --global user.email 'OpenHands@users.noreply.github.com'
  61. # Create a unique branch name with a timestamp
  62. BRANCH_NAME="fix/${{ github.event.issue.number }}-$(date +%Y%m%d%H%M%S)"
  63. # Checkout new branch
  64. git checkout -b $BRANCH_NAME
  65. # Add all changes to staging, except task.txt
  66. git add --all -- ':!task.txt'
  67. # Commit the changes, if any
  68. git commit -m "OpenHands: Resolve Issue #${{ github.event.issue.number }}"
  69. if [ $? -ne 0 ]; then
  70. echo "No changes to commit."
  71. exit 0
  72. fi
  73. # Push changes
  74. git push --set-upstream origin $BRANCH_NAME
  75. - name: Fetch Default Branch
  76. env:
  77. GH_TOKEN: ${{ github.token }}
  78. run: |
  79. # Fetch the default branch using gh cli
  80. DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)
  81. echo "Default branch is $DEFAULT_BRANCH"
  82. echo "DEFAULT_BRANCH=$DEFAULT_BRANCH" >> $GITHUB_ENV
  83. - name: Generate PR
  84. env:
  85. GH_TOKEN: ${{ github.token }}
  86. run: |
  87. # Create PR and capture URL
  88. PR_URL=$(gh pr create \
  89. --title "OpenHands: Resolve Issue #2" \
  90. --body "This PR was generated by OpenHands to resolve issue #2" \
  91. --repo "foragerr/OpenHands" \
  92. --head "${{ github.head_ref }}" \
  93. --base "${{ env.DEFAULT_BRANCH }}" \
  94. | grep -o 'https://github.com/[^ ]*')
  95. # Extract PR number from URL
  96. PR_NUMBER=$(echo "$PR_URL" | grep -o '[0-9]\+$')
  97. # Set environment vars
  98. echo "PR_URL=$PR_URL" >> $GITHUB_ENV
  99. echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
  100. - name: Post Comment
  101. env:
  102. GH_TOKEN: ${{ github.token }}
  103. run: |
  104. gh issue comment ${{ github.event.issue.number }} \
  105. -b "OpenHands raised [PR #${{ env.PR_NUMBER }}](${{ env.PR_URL }}) to resolve this issue."