From 87906b96a745b29a5f0bc7cf220cedb65d1cbb42 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Wed, 30 Oct 2024 16:42:03 -0400 Subject: [PATCH] Add job to update PR description with docker run command (#4550) Co-authored-by: openhands --- .github/workflows/ghcr-build.yml | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index 24e4ef5ac7..6906538a6a 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -399,3 +399,49 @@ jobs: run: | echo "Some runtime tests failed or were cancelled" exit 1 + update_pr_description: + name: Update PR Description + if: github.event_name == 'pull_request' + needs: [ghcr_build_runtime] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get short SHA + id: short_sha + run: echo "SHORT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT + + - name: Update PR Description + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + REPO: ${{ github.repository }} + SHORT_SHA: ${{ steps.short_sha.outputs.SHORT_SHA }} + run: | + echo "updating PR description" + DOCKER_RUN_COMMAND="docker run -it --rm \ + -p 3000:3000 \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --add-host host.docker.internal:host-gateway \ + -e SANDBOX_RUNTIME_CONTAINER_IMAGE=ghcr.io/all-hands-ai/runtime:$SHORT_SHA-nikolaik \ + --name openhands-app-$SHORT_SHA \ + ghcr.io/all-hands-ai/runtime:$SHORT_SHA" + + PR_BODY=$(gh pr view $PR_NUMBER --json body --jq .body) + + if echo "$PR_BODY" | grep -q "To run this PR locally, use the following command:"; then + UPDATED_PR_BODY=$(echo "${PR_BODY}" | sed -E "s|docker run -it --rm.*|$DOCKER_RUN_COMMAND|") + else + UPDATED_PR_BODY="${PR_BODY} + + --- + + To run this PR locally, use the following command: + \`\`\` + $DOCKER_RUN_COMMAND + \`\`\`" + fi + + echo "updated body: $UPDATED_PR_BODY" + gh pr edit $PR_NUMBER --body "$UPDATED_PR_BODY"