Skip to content

Commit 97f8724

Browse files
committed
feat(github-action): use Docker for gptme execution
- Replace local Python setup with Docker image for gptme execution - Add GitHub Container Registry login and Docker image pull steps - Update gptme execution to use Docker run command - Remove unnecessary steps for Python and poetry setup - Adjust error reporting and environment variable handling - Add TODO for version identification in non-gptme repos
1 parent d2c4879 commit 97f8724

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

.github/actions/bot/action.yml

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,22 @@ runs:
8282
if: steps.detect_command.outputs.gptme_command
8383
uses: actions/checkout@v3
8484

85-
- name: Install ctags
86-
if: steps.detect_command.outputs.gptme_command
87-
run: sudo apt install universal-ctags
88-
shell: bash
85+
- name: Log in to GitHub Container Registry
86+
uses: docker/login-action@v3
87+
with:
88+
registry: ghcr.io
89+
username: ${{ github.actor }}
90+
password: ${{ secrets.GITHUB_TOKEN }}
91+
92+
- name: Pull Docker image
93+
run: docker pull ghcr.io/erikbjare/gptme:latest
8994

9095
- name: Checkout PR branch if comment is on a PR
91-
if: steps.detect_command.outputs.gptme_command
9296
id: checkout_branch
97+
if: steps.detect_command.outputs.gptme_command
98+
env:
99+
GITHUB_TOKEN: ${{ inputs.github_token }}
100+
shell: bash
93101
run: |
94102
# Fetch details about the "issue" the comment is on
95103
DATA=$(gh api /repos/${{ github.repository }}/issues/${{ inputs.issue_number }})
@@ -112,65 +120,66 @@ runs:
112120
git checkout -b $BRANCH_NAME
113121
fi
114122
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
115-
shell: bash
116-
env:
117-
GITHUB_TOKEN: ${{ inputs.github_token }}
118-
119-
- name: Install poetry
120-
if: steps.detect_command.outputs.gptme_command
121-
run: pipx install poetry
122-
shell: bash
123-
124-
- name: Set up Python
125-
uses: actions/setup-python@v4
126-
if: steps.detect_command.outputs.gptme_command
127-
with:
128-
python-version: ${{ inputs.python_version }}
129-
cache: 'poetry'
130-
131-
- name: Install dependencies
132-
if: steps.detect_command.outputs.gptme_command
133-
run: |
134-
make build
135-
poetry install -E datascience
136-
shell: bash
137123
138124
- name: Run gptme
139125
if: steps.detect_command.outputs.gptme_command
126+
env:
127+
GITHUB_TOKEN: ${{ inputs.github_token }}
128+
GPTME_COMMAND: ${{ steps.detect_command.outputs.gptme_command }}
129+
ISSUE_NUMBER: ${{ inputs.issue_number }}
130+
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
131+
shell: bash
140132
run: |
141133
gh issue view ${{ inputs.issue_number }} > issue.md
142134
gh issue view ${{ inputs.issue_number }} -c > comments.md
143135
144136
# strip long <details>...</details> from issue.md and comments.md
137+
# TODO: upload logs elsewhere and link instead of dumping
145138
perl -0777 -i -pe 's/\n<details>.*?<\/details>//sg' issue.md
146139
perl -0777 -i -pe 's/\n<details>.*?<\/details>//sg' comments.md
147140
148-
# install a shim that makes `git commit` a no-op (in case it would get that idea prematurely)
149-
source scripts/git-shim.sh
150-
151-
# Run gptme with the extracted command and save logs
152-
poetry run gptme --non-interactive "$GPTME_COMMAND" issue.md comments.md
141+
# run gptme with the extracted command and save logs
142+
docker run --rm \
143+
-v $(pwd):/workspace \
144+
-w /workspace \
145+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
146+
ghcr.io/erikbjare/gptme:latest \
147+
--non-interactive \
148+
"$GPTME_COMMAND" issue.md comments.md
153149
154150
# remove tmp files so that they do not get committed
155151
rm issue.md comments.md
156152
157153
# stage changes
158154
git add -A
159-
shell: bash
160-
env:
161-
GITHUB_TOKEN: ${{ inputs.github_token }}
162-
GPTME_COMMAND: ${{ steps.detect_command.outputs.gptme_command }}
163-
ISSUE_NUMBER: ${{ inputs.issue_number }}
164155
165156
- name: Generate commit message
166157
if: steps.detect_command.outputs.gptme_command
158+
shell: bash
159+
env:
160+
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
167161
run: |
168162
# generate commit message
169-
poetry run gptme --non-interactive "Run `git diff --staged`, then write a commit message for it to message.txt, following conventional commits. Don't commit."
170-
shell: bash
163+
docker run --rm \
164+
-v $(pwd):/workspace \
165+
-w /workspace \
166+
-e OPENAI_API_KEY=$OPENAI_API_KEY \
167+
ghcr.io/erikbjare/gptme:latest \
168+
--non-interactive \
169+
"Run 'git diff --staged' to inspect what has changed." "-" "Write a commit message for it to 'message.txt'. Use the 'conventional commits' style."
171170
172171
- name: Commit, push, comment
173172
if: steps.detect_command.outputs.gptme_command
173+
env:
174+
GITHUB_TOKEN: ${{ inputs.github_token }}
175+
GPTME_COMMAND: ${{ steps.detect_command.outputs.gptme_command }}
176+
ISSUE_NUMBER: ${{ inputs.issue_number }}
177+
ISSUE_TYPE: ${{ github.event.issue.pull_request && 'pull_request' || 'issue' }}
178+
REPO_NAME: ${{ inputs.repo_name }}
179+
USER_NAME: ${{ inputs.user_name }}
180+
BRANCH_NAME: ${{ steps.checkout_branch.outputs.branch_name }}
181+
BRANCH_BASE: ${{ inputs.branch_base }}
182+
shell: bash
174183
run: |
175184
# Read and format log
176185
./scripts/format_log.sh ~/.local/share/gptme/logs/*/conversation.jsonl > log.txt
@@ -220,19 +229,15 @@ runs:
220229
# Comment on the issue with the PR link
221230
echo "A pull request has been created for this issue: $PR_URL" | gh issue comment $ISSUE_NUMBER -R $USER_NAME/$REPO_NAME --body-file=-
222231
fi
223-
shell: bash
232+
233+
- name: Report error
234+
if: failure()
224235
env:
225236
GITHUB_TOKEN: ${{ inputs.github_token }}
226-
GPTME_COMMAND: ${{ steps.detect_command.outputs.gptme_command }}
227237
ISSUE_NUMBER: ${{ inputs.issue_number }}
228-
ISSUE_TYPE: ${{ github.event.issue.pull_request && 'pull_request' || 'issue' }}
229238
REPO_NAME: ${{ inputs.repo_name }}
230239
USER_NAME: ${{ inputs.user_name }}
231-
BRANCH_NAME: ${{ steps.checkout_branch.outputs.branch_name }}
232-
BRANCH_BASE: ${{ inputs.branch_base }}
233-
234-
- name: Report error
235-
if: failure()
240+
shell: bash
236241
run: |
237242
# reply to the comment that we could not fulfill the request
238243
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
@@ -245,9 +250,3 @@ runs:
245250
</details>"
246251
fi
247252
echo "$MESSAGE" | gh issue comment $ISSUE_NUMBER -R $USER_NAME/$REPO_NAME --body-file=-
248-
shell: bash
249-
env:
250-
GITHUB_TOKEN: ${{ inputs.github_token }}
251-
ISSUE_NUMBER: ${{ inputs.issue_number }}
252-
REPO_NAME: ${{ inputs.repo_name }}
253-
USER_NAME: ${{ inputs.user_name }}

gptme/eval/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def read_results_from_csv(filename: str) -> dict[str, list[ExecResult]]:
414414
def write_results_to_csv(model_results: dict[str, list[ExecResult]]):
415415
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
416416
# get current commit hash and dirty status, like: a8b2ef0-dirty
417+
# TODO: don't assume we are in the gptme repo, use other version identifiers if available
417418
commit_hash = subprocess.run(
418419
["git", "describe", "--always", "--dirty", "--exclude", "'*'"],
419420
text=True,

0 commit comments

Comments
 (0)