77 - ' release/*'
88 tags :
99 - ' v*.*'
10+ pull_request :
11+ paths :
12+ - " .github/workflows/docker.yml"
13+ - " tools/config_editor/requirements.txt"
14+ - " tools/docker/Dockerfile"
15+ - " tools/docker/entrypoint.sh"
1016
1117env :
1218 # Build the image for amd64 and arm64
1622jobs :
1723 docker :
1824 # Disable the job in forks
19- if : ${{ github.repository_owner == 'espressif' }}
20-
25+ if : ${{ github.event_name == 'pull_request' || github. repository_owner == 'espressif' }}
26+ name : Build docker image and push if needed
2127 runs-on : ubuntu-latest
2228 steps :
2329 # Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile
@@ -29,50 +35,65 @@ jobs:
2935 run : |
3036 echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
3137 echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV
38+ echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
39+
3240 - name : Set variables (release branches)
3341 if : ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }}
3442 run : |
3543 echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
3644 echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV
45+ echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
46+
3747 - name : Set variables (main branch)
3848 if : ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
3949 run : |
4050 echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV
4151 echo "TAG_NAME=latest" >> $GITHUB_ENV
52+ echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
53+
54+ - name : Set variables (pull requests)
55+ if : ${{ github.event_name == 'pull_request' }}
56+ run : |
57+ echo "CLONE_BRANCH_OR_TAG=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
58+ echo "TAG_NAME=PR_${{ github.event.number }}" >> $GITHUB_ENV
59+ echo "URL=${{ github.server_url }}/${{ github.event.pull_request.head.repo.full_name }}.git" >> $GITHUB_ENV
4260
4361 # Display the variables set above, just in case.
4462 - name : Check variables
4563 run : |
4664 echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG"
47- echo "CHECKOUT_REF: $CHECKOUT_REF"
4865 echo "TAG_NAME: $TAG_NAME"
66+ echo "URL: $URL"
4967
50- # The following steps are the standard boilerplate from
51- # https://github.com/marketplace/actions/build-and-push-docker-images
5268 - name : Checkout
5369 uses : actions/checkout@v4
70+
5471 - name : Login to Docker Hub
72+ if : ${{ github.event_name == 'push' }}
5573 uses : docker/login-action@v3
5674 with :
5775 username : ${{ secrets.DOCKERHUB_USERNAME }}
5876 password : ${{ secrets.DOCKERHUB_TOKEN }}
77+
5978 - name : Set up QEMU for multiarch builds
6079 uses : docker/setup-qemu-action@v3
80+
6181 - name : Set up Docker Buildx
6282 uses : docker/setup-buildx-action@v3
83+
6384 - name : Build and push
6485 uses : docker/build-push-action@v5
6586 with :
6687 context : tools/docker
67- push : true
88+ push : ${{ github.event_name == 'push' }}
6889 tags : ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }}
6990 platforms : ${{ env.BUILD_PLATFORMS }}
7091 build-args : |
71- LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git
92+ LIBBUILDER_CLONE_URL=${{ env.URL }}
7293 LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }}
7394
7495 - name : Update Docker Hub repository description (master branch)
75- if : ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
96+ if : ${{ github.event_name == 'push' && github. ref_type == 'branch' && github.ref_name == 'master' }}
7697 uses : peter-evans/dockerhub-description@v4
7798 with :
7899 username : ${{ secrets.DOCKERHUB_USERNAME }}
0 commit comments