@@ -134,6 +134,20 @@ jobs:
134134 - sast-code-snyk
135135 - sast-dockerfile-trivy-hadolint
136136 steps :
137+ - uses : actions/checkout@v4
138+ with :
139+ fetch-depth : 0
140+ - name : fetch-tags
141+ run : git fetch --tags origin
142+ shell : bash
143+ - id : bump-version
144+ uses : armakuni/github-actions/bump-version@main
145+ - name : check-bump-version-output
146+ run : |
147+ echo "version-was-bump: ${{ steps.bump-version.outputs.version-was-bump }}"
148+ echo "previous-version: ${{ steps.bump-version.outputs.previous-version }}"
149+ echo "current-version: ${{ steps.bump-version.outputs.current-version }}"
150+ shell : bash
137151 - name : Login to Docker Hub
138152 uses : docker/login-action@v3
139153 with :
@@ -145,24 +159,29 @@ jobs:
145159 id : meta
146160 uses : docker/metadata-action@v5
147161 with :
148- images : |
149- abhisheksr01/companieshouse
162+ images : abhisheksr01/companieshouse
163+ context : git
164+ flavour : |
165+ latest=true
150166 tags : |
151- type=ref,event=branch
167+ type=ref,event=tag
152168 type=ref,event=pr
153- type=semver,pattern={{version}}
154- type=semver,pattern={{major}}.{{minor}}
169+ type=semver,pattern={{version}},prefix=v,value=${{ steps.bump-version.outputs.current-version }}
155170 labels : |
156171 "org.opencontainers.image.title": "abhisheksr01/companieshouse",
157172 "org.opencontainers.image.description": "Best practices and integrations available for Spring Boot based Microservice in a single repository with companieshouse API use case.",
158173 "org.opencontainers.image.url": "https://github.com/abhisheksr01/spring-boot-microservice-best-practices",
159174 "org.opencontainers.image.source": "https://github.com/abhisheksr01/spring-boot-microservice-best-practices",
160- "org.opencontainers.image.version": "0.1.0" ,
175+ "org.opencontainers.image.version": ${{ steps.bump-version.outputs.current-version }} ,
161176 "org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
162177 "org.opencontainers.image.revision": ${{ github.sha }},
163178 "org.opencontainers.image.licenses": "MIT"
164179 - name : Build and push
165180 uses : docker/build-push-action@v6
166181 with :
167- push : true
168- tags : abhisheksr01/companieshouse:latest
182+ push : ${{ github.event_name != 'pull_request' && steps.bump-version.outputs.version-was-bump == 'true' }} # Only push on main branch & when the version is bumped
183+ tags : ${{ steps.meta.outputs.tags }}
184+ labels : ${{ steps.meta.outputs.labels }}
185+ sbom : true
186+ provenance : true
187+
0 commit comments