diff --git a/.github/workflows/ghcr-build.yml b/.github/workflows/ghcr-build.yml index 3b458de887..b1a13a84d8 100644 --- a/.github/workflows/ghcr-build.yml +++ b/.github/workflows/ghcr-build.yml @@ -27,6 +27,7 @@ on: env: BASE_IMAGE_FOR_HASH_EQUIVALENCE_TEST: nikolaik/python-nodejs:python3.12-nodejs22 + RELEVANT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} jobs: # Builds the OpenHands Docker images @@ -83,7 +84,7 @@ jobs: export REPO_OWNER=${{ github.repository_owner }} REPO_OWNER=$(echo $REPO_OWNER | tr '[:upper:]' '[:lower:]') # Run the build script in the app image - docker run -e SANDBOX_USER_ID=0 -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/${REPO_OWNER}/openhands:${{ github.sha }} /bin/bash -c "mkdir -p containers/runtime; python3 openhands/runtime/utils/runtime_build.py --base_image ${{ env.BASE_IMAGE_FOR_HASH_EQUIVALENCE_TEST }} --build_folder containers/runtime --force_rebuild" 2>&1 | tee docker-outputs.txt + docker run -e SANDBOX_USER_ID=0 -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/${REPO_OWNER}/openhands:$RELEVANT_SHA /bin/bash -c "mkdir -p containers/runtime; python3 openhands/runtime/utils/runtime_build.py --base_image ${{ env.BASE_IMAGE_FOR_HASH_EQUIVALENCE_TEST }} --build_folder containers/runtime --force_rebuild" 2>&1 | tee docker-outputs.txt # Get the hash from the build script hash_from_app_image=$(cat docker-outputs.txt | grep "Hash for docker build directory" | awk -F "): " '{print $2}' | uniq | head -n1) echo "hash_from_app_image=$hash_from_app_image" >> $GITHUB_OUTPUT @@ -160,7 +161,7 @@ jobs: if: github.event.pull_request.head.repo.fork uses: docker/build-push-action@v6 with: - tags: ghcr.io/all-hands-ai/runtime:${{ github.sha }}-${{ matrix.base_image.tag }} + tags: ghcr.io/all-hands-ai/runtime:$RELEVANT_SHA-${{ matrix.base_image.tag }} outputs: type=docker,dest=/tmp/runtime-${{ matrix.base_image.tag }}.tar context: containers/runtime - name: Upload runtime image for fork @@ -284,7 +285,7 @@ jobs: # Install to be able to retry on failures for flaky tests poetry run pip install pytest-rerunfailures - image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }} + image_name=ghcr.io/${{ github.repository_owner }}/runtime:$RELEVANT_SHA-${{ matrix.base_image }} image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]') SKIP_CONTAINER_LOGS=true \ @@ -362,7 +363,7 @@ jobs: # Install to be able to retry on failures for flaky tests poetry run pip install pytest-rerunfailures - image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }} + image_name=ghcr.io/${{ github.repository_owner }}/runtime:$RELEVANT_SHA-${{ matrix.base_image }} image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]') SKIP_CONTAINER_LOGS=true \ @@ -435,7 +436,7 @@ jobs: run: make install-python-dependencies - name: Run integration tests run: | - image_name=ghcr.io/${{ github.repository_owner }}/runtime:${{ github.sha }}-${{ matrix.base_image }} + image_name=ghcr.io/${{ github.repository_owner }}/runtime:$RELEVANT_SHA-${{ matrix.base_image }} image_name=$(echo $image_name | tr '[:upper:]' '[:lower:]') TEST_RUNTIME=eventstream \ diff --git a/containers/build.sh b/containers/build.sh index 5b518c4fad..a05fd266a2 100755 --- a/containers/build.sh +++ b/containers/build.sh @@ -44,10 +44,10 @@ OPENHANDS_BUILD_VERSION="dev" cache_tag_base="buildcache" cache_tag="$cache_tag_base" -if [[ -n $GITHUB_SHA ]]; then - git_hash=$(git rev-parse --short "$GITHUB_SHA") +if [[ -n $RELEVANT_SHA ]]; then + git_hash=$(git rev-parse --short "$RELEVANT_SHA") tags+=("$git_hash") - tags+=("$GITHUB_SHA") + tags+=("$RELEVANT_SHA") fi if [[ -n $GITHUB_REF_NAME ]]; then