7
7
- ' release/*'
8
8
tags :
9
9
- ' 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"
10
16
11
17
env :
12
18
# Build the image for amd64 and arm64
16
22
jobs :
17
23
docker :
18
24
# 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
21
27
runs-on : ubuntu-latest
22
28
steps :
23
29
# Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile
@@ -29,50 +35,65 @@ jobs:
29
35
run : |
30
36
echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
31
37
echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV
38
+ echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
39
+
32
40
- name : Set variables (release branches)
33
41
if : ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }}
34
42
run : |
35
43
echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
36
44
echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV
45
+ echo "URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV
46
+
37
47
- name : Set variables (main branch)
38
48
if : ${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
39
49
run : |
40
50
echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV
41
51
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
42
60
43
61
# Display the variables set above, just in case.
44
62
- name : Check variables
45
63
run : |
46
64
echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG"
47
- echo "CHECKOUT_REF: $CHECKOUT_REF"
48
65
echo "TAG_NAME: $TAG_NAME"
66
+ echo "URL: $URL"
49
67
50
- # The following steps are the standard boilerplate from
51
- # https://github.com/marketplace/actions/build-and-push-docker-images
52
68
- name : Checkout
53
69
uses : actions/checkout@v4
70
+
54
71
- name : Login to Docker Hub
72
+ if : ${{ github.event_name == 'push' }}
55
73
uses : docker/login-action@v3
56
74
with :
57
75
username : ${{ secrets.DOCKERHUB_USERNAME }}
58
76
password : ${{ secrets.DOCKERHUB_TOKEN }}
77
+
59
78
- name : Set up QEMU for multiarch builds
60
79
uses : docker/setup-qemu-action@v3
80
+
61
81
- name : Set up Docker Buildx
62
82
uses : docker/setup-buildx-action@v3
83
+
63
84
- name : Build and push
64
85
uses : docker/build-push-action@v5
65
86
with :
66
87
context : tools/docker
67
- push : true
88
+ push : ${{ github.event_name == 'push' }}
68
89
tags : ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }}
69
90
platforms : ${{ env.BUILD_PLATFORMS }}
70
91
build-args : |
71
- LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git
92
+ LIBBUILDER_CLONE_URL=${{ env.URL }}
72
93
LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }}
73
94
74
95
- 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' }}
76
97
uses : peter-evans/dockerhub-description@v4
77
98
with :
78
99
username : ${{ secrets.DOCKERHUB_USERNAME }}
0 commit comments