7
7
- ' release/*'
8
8
tags :
9
9
- ' v*.*'
10
+ pull_request :
11
+ paths :
12
+ - " .github/workflows/docker.yml"
13
+ - " tools/config_editor/**"
14
+ - " tools/docker/**"
15
+ - " !**.md"
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' }}
25
+ if : ${{ github.event_name == 'pull_request' || github. repository_owner == 'espressif' }}
20
26
21
27
runs-on : ubuntu-latest
22
28
steps :
@@ -29,50 +35,66 @@ 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
65
echo "CHECKOUT_REF: $CHECKOUT_REF"
48
66
echo "TAG_NAME: $TAG_NAME"
67
+ echo "URL: $URL"
49
68
50
- # The following steps are the standard boilerplate from
51
- # https://github.com/marketplace/actions/build-and-push-docker-images
52
69
- name : Checkout
53
70
uses : actions/checkout@v4
71
+
54
72
- name : Login to Docker Hub
73
+ if : ${{ github.event_name == 'push' }}
55
74
uses : docker/login-action@v3
56
75
with :
57
76
username : ${{ secrets.DOCKERHUB_USERNAME }}
58
77
password : ${{ secrets.DOCKERHUB_TOKEN }}
78
+
59
79
- name : Set up QEMU for multiarch builds
60
80
uses : docker/setup-qemu-action@v3
81
+
61
82
- name : Set up Docker Buildx
62
83
uses : docker/setup-buildx-action@v3
84
+
63
85
- name : Build and push
64
86
uses : docker/build-push-action@v5
65
87
with :
66
88
context : tools/docker
67
- push : true
89
+ push : ${{ github.event_name == 'push' }}
68
90
tags : ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }}
69
91
platforms : ${{ env.BUILD_PLATFORMS }}
70
92
build-args : |
71
- LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git
93
+ LIBBUILDER_CLONE_URL=${{ env.URL }}
72
94
LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }}
73
95
74
96
- 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' }}
76
98
uses : peter-evans/dockerhub-description@v4
77
99
with :
78
100
username : ${{ secrets.DOCKERHUB_USERNAME }}
0 commit comments