Skip to content

Commit 44160a8

Browse files
committed
Test docker build in PRs
1 parent f245824 commit 44160a8

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

.github/workflows/docker.yml

+28-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ on:
77
- 'release/*'
88
tags:
99
- 'v*.*'
10+
pull_request:
11+
paths:
12+
- ".github/workflows/docker.yml"
13+
- "tools/config_editor/**"
14+
- "tools/docker/**"
15+
- "!**.md"
1016

1117
env:
1218
# Build the image for amd64 and arm64
@@ -16,7 +22,7 @@ env:
1622
jobs:
1723
docker:
1824
# Disable the job in forks
19-
if: ${{ github.repository_owner == 'espressif' }}
25+
if: ${{ github.event_name == 'pull_request' || github.repository_owner == 'espressif' }}
2026

2127
runs-on: ubuntu-latest
2228
steps:
@@ -29,50 +35,66 @@ 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"
4765
echo "CHECKOUT_REF: $CHECKOUT_REF"
4866
echo "TAG_NAME: $TAG_NAME"
67+
echo "URL: $URL"
4968
50-
# The following steps are the standard boilerplate from
51-
# https://github.com/marketplace/actions/build-and-push-docker-images
5269
- name: Checkout
5370
uses: actions/checkout@v4
71+
5472
- name: Login to Docker Hub
73+
if: ${{ github.event_name == 'push' }}
5574
uses: docker/login-action@v3
5675
with:
5776
username: ${{ secrets.DOCKERHUB_USERNAME }}
5877
password: ${{ secrets.DOCKERHUB_TOKEN }}
78+
5979
- name: Set up QEMU for multiarch builds
6080
uses: docker/setup-qemu-action@v3
81+
6182
- name: Set up Docker Buildx
6283
uses: docker/setup-buildx-action@v3
84+
6385
- name: Build and push
6486
uses: docker/build-push-action@v5
6587
with:
6688
context: tools/docker
67-
push: true
89+
push: ${{ github.event_name == 'push' }}
6890
tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }}
6991
platforms: ${{ env.BUILD_PLATFORMS }}
7092
build-args: |
71-
LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git
93+
LIBBUILDER_CLONE_URL=${{ env.URL }}
7294
LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }}
7395
7496
- name: Update Docker Hub repository description (master branch)
75-
if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
97+
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }}
7698
uses: peter-evans/dockerhub-description@v4
7799
with:
78100
username: ${{ secrets.DOCKERHUB_USERNAME }}

0 commit comments

Comments
 (0)