16
16
branches :
17
17
- main
18
18
- releasebranch_*
19
- - ' !releasebranch_7_*'
19
+ - " !releasebranch_7_*"
20
20
# tags: ['*.*.*']
21
21
paths-ignore : [doc/**]
22
+ pull_request :
23
+ paths :
24
+ - .github/workflows/docker.yml
25
+ - Dockerfile
26
+ - docker/**
27
+ - " !docker/**.md"
28
+ workflow_dispatch :
22
29
release :
23
30
types : [published]
24
31
@@ -35,10 +42,17 @@ jobs:
35
42
# For a release, e.g. 8.3.0, created tags are:
36
43
# 8.3.0-alpine, 8.3.0-debian, 8.3.0-ubuntu and latest (with ubuntu)
37
44
docker-os-matrix :
38
- name : build and push ${{ matrix.os }} for ${{ github.ref }}
39
- if : github.repository_owner == 'OSGeo'
45
+ name : ${{ matrix.os }} for ${{ github.ref }}
40
46
runs-on : ubuntu-latest
41
-
47
+ concurrency :
48
+ group : >-
49
+ ${{ github.workflow }}-${{ matrix.os }}-${{ github.event_name }}-
50
+ ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
51
+ # Cancel in progress in pull requests.
52
+ # Otherwise, limit to one in progress and one queued for each type.
53
+ # Only the latest queued job per event type will be kept, older will be cancelled.
54
+ # The already running job will be completed.
55
+ cancel-in-progress : ${{ github.event_name == 'pull_request' }}
42
56
strategy :
43
57
matrix :
44
58
os :
@@ -49,32 +63,78 @@ jobs:
49
63
fail-fast : false
50
64
51
65
permissions :
66
+ attestations : write
52
67
contents : read
68
+ id-token : write
53
69
packages : write
54
70
55
71
steps :
56
72
- name : Checkout
57
73
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
58
74
with :
59
75
fetch-depth : 0
76
+ - name : Get the latest tag and release branches
77
+ id : tag-branch
78
+ run : |
79
+ # Make sure tags are fetched
80
+ git fetch --tags
81
+ # Get sorted list of tags, keep the first that has a semver pattern (not RCs)
82
+ latest_tag="$(git tag --sort=-v:refname \
83
+ | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
84
+ | head -n 1)"
85
+ latest_rel_branch="$(git branch --all --list 'origin/*' \
86
+ --contains "${latest_tag}" --format "%(refname:lstrip=3)")"
87
+ echo "latest_tag=${latest_tag}" >> "${GITHUB_OUTPUT}"
88
+ echo "latest_tag is: ${latest_tag}"
89
+ echo "latest_rel_branch=${latest_rel_branch}" >> "${GITHUB_OUTPUT}"
90
+ echo "latest_rel_branch is: ${latest_rel_branch}"
91
+ - name : Get enable values for meta step
92
+ id : enable
93
+ run : |
94
+ latest="${{
95
+ (github.ref || format('{0}{1}', 'refs/tags/', github.event.release.tag_name))
96
+ == format('refs/tags/{0}', steps.tag-branch.outputs.latest_tag)
97
+ && matrix.os == 'ubuntu' }}"
98
+ current="${{
99
+ ( contains(fromJSON('["tag", "release"]'), github.event_name)
100
+ && (github.ref || format('{0}{1}', 'refs/tags/', github.event.release.tag_name))
101
+ == format('refs/tags/{0}', steps.tag-branch.outputs.latest_tag)
102
+ )
103
+ || github.ref == format('refs/heads/{0}', steps.tag-branch.outputs.latest_rel_branch)
104
+ }}"
105
+ echo "latest=${latest}" >> "${GITHUB_OUTPUT}"
106
+ echo "latest is $latest"
107
+ echo "current=${current}" >> "${GITHUB_OUTPUT}"
108
+ echo "current is $current"
60
109
- name : Docker meta
61
110
id : meta
62
111
uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
63
112
with :
64
- images : osgeo/grass-gis
113
+ images : |
114
+ name=docker.io/osgeo/grass-gis,enable=${{ github.repository_owner == 'OSGeo'
115
+ && github.event_name != 'pull_request' }}
116
+ name=ghcr.io/${{ github.repository }}
65
117
tags : |
66
118
type=ref,event=tag
67
119
type=ref,event=branch
68
- type=raw,value=current,enable=${{ github.ref == format('refs/heads/{0}', 'releasebranch_8_3') }}
69
- type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/8.3') && matrix.os == 'ubuntu' }},suffix=
120
+ type=ref,event=pr
121
+ type=raw,value=current,enable=${{ steps.enable.outputs.current }}
122
+ type=raw,value=latest,enable=${{ steps.enable.outputs.latest }},suffix=
70
123
flavor : |
71
124
latest=false
72
125
suffix=-${{ matrix.os }}
73
126
- name : Set up QEMU
74
127
uses : docker/setup-qemu-action@4574d27a4764455b42196d70a065bc6853246a25 # v3.4.0
75
128
- name : Set up Docker Buildx
76
129
uses : docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3.9.0
77
- - name : Login to DockerHub
130
+ - name : Login to GitHub Container Registry
131
+ uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
132
+ with :
133
+ registry : ghcr.io
134
+ username : ${{ github.actor }}
135
+ password : ${{ secrets.GITHUB_TOKEN }}
136
+ - name : Login to Docker Hub
137
+ if : ${{ github.repository_owner == 'OSGeo' && github.event_name != 'pull_request' }}
78
138
uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
79
139
with :
80
140
username : ${{ secrets.DOCKERHUB_USERNAME }}
@@ -83,12 +143,39 @@ jobs:
83
143
id : docker_build
84
144
uses : docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
85
145
with :
86
- push : true
87
- pull : true
146
+ push : ${{ github.event_name != 'pull_request' }}
88
147
context : .
89
148
tags : ${{ steps.meta.outputs.tags }}
90
149
file : docker/${{ matrix.os }}/Dockerfile
91
- cache-from : type=gha,scope=${{ matrix.os }}
150
+ annotations : ${{ steps.meta.outputs.annotations }}
151
+ provenance : mode=max
152
+ sbom : true
153
+ # Don't use cache for releases.
154
+ no-cache : ${{ contains(fromJSON('["tag", "release"]'), github.event_name) && true }}
155
+ # Don't use gha cache for releases. Cache is not used if `cache-from:` is empty
156
+ cache-from : >-
157
+ ${{ !contains(fromJSON('["tag", "release"]'), github.event_name)
158
+ && format('type=gha,scope={0}', matrix.os) || '' }}
92
159
cache-to : type=gha,mode=max,scope=${{ matrix.os }}
93
160
- name : Image digest
94
161
run : echo ${{ steps.docker_build.outputs.digest }}
162
+ - name : Attest docker.io image
163
+ uses : actions/attest-build-provenance@520d128f165991a6c774bcb264f323e3d70747f4 # v2.2.0
164
+ # If there isn't a digest, an annotation cannot be added
165
+ if : >-
166
+ ${{ github.repository_owner == 'OSGeo' && github.event_name != 'pull_request'
167
+ && steps.docker_build.outputs.digest }}
168
+ id : attest
169
+ with :
170
+ subject-name : docker.io/osgeo/grass-gis
171
+ subject-digest : ${{ steps.docker_build.outputs.digest }}
172
+ push-to-registry : ${{ github.repository_owner == 'OSGeo' && github.event_name != 'pull_request' }}
173
+ - name : Attest ghcr.io image
174
+ uses : actions/attest-build-provenance@520d128f165991a6c774bcb264f323e3d70747f4 # v2.2.0
175
+ # If there isn't a digest, an annotation cannot be added
176
+ if : ${{ steps.docker_build.outputs.digest }}
177
+ id : attest-ghcr
178
+ with :
179
+ subject-name : ghcr.io/${{ github.repository }}
180
+ subject-digest : ${{ steps.docker_build.outputs.digest }}
181
+ push-to-registry : ${{ github.event_name != 'pull_request' }}
0 commit comments