Skip to content

Commit b2518da

Browse files
authored
handle PRs gracefully for Docker image build (#4638)
fixes #4141
1 parent 9973a3c commit b2518da

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

.github/workflows/docker.yml

-2
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ jobs:
3838
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
3939
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
4040
OPENGROK_REPO_SLUG: ${{ github.repository }}
41-
OPENGROK_PULL_REQUEST: ${{ github.head_ref }}
4241
OPENGROK_REF: ${{ github.ref }}
4342
run: ./dev/docker.sh
4443
- name: Install Python pre-requisites
4544
run: python3 -m pip install requests
4645
- name: Optionally update README on Docker hub
4746
env:
4847
OPENGROK_REPO_SLUG: ${{ github.repository }}
49-
OPENGROK_PULL_REQUEST: ${{ github.head_ref }}
5048
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
5149
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
5250
run: ./dev/dockerhub_readme.py

dev/docker.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ docker run -d $IMAGE
6262
docker ps -a
6363

6464
# This can only work on home repository since it needs encrypted variables.
65-
if [[ -n "$OPENGROK_PULL_REQUEST" ]]; then
65+
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
6666
echo "Not pushing Docker image for pull requests"
6767
exit 0
6868
fi
@@ -75,12 +75,12 @@ fi
7575

7676
if [[ -z $DOCKER_USERNAME ]]; then
7777
echo "DOCKER_USERNAME is empty, exiting"
78-
exit 0
78+
exit 1
7979
fi
8080

8181
if [[ -z $DOCKER_PASSWORD ]]; then
8282
echo "DOCKER_PASSWORD is empty, exiting"
83-
exit 0
83+
exit 1
8484
fi
8585

8686
# Publish the image to Docker hub.

dev/dockerhub_readme.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def check_push_env():
8585
logger.info("Not updating Docker hub README for non main repo")
8686
sys.exit(0)
8787

88-
pull_request = os.environ.get("OPENGROK_PULL_REQUEST")
89-
if pull_request and len(pull_request) > 0:
88+
event_type = os.environ.get("GITHUB_EVENT_NAME")
89+
if event_type and event_type == "pull_request":
9090
logger.info("Not updating Docker hub README for pull requests")
9191
sys.exit(0)
9292

0 commit comments

Comments
 (0)