4141 DOTNET_VERSION : " 9.0.x" # set this to the dot net version to use
4242
4343jobs :
44+ version :
45+ name : Compute semantic version
46+ runs-on : ubuntu-latest
47+ outputs :
48+ version : ${{ steps.compute.outputs.version }}
49+ steps :
50+ - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
51+ with :
52+ fetch-depth : 0 # full history + tags required for deterministic version computation
53+
54+ - name : Compute build version
55+ id : compute
56+ shell : pwsh
57+ run : |
58+ $version = & ./scripts/version/Get-BuildVersion.ps1
59+ Write-Host "Computed semantic version: $version"
60+ echo "version=$version" >> $env:GITHUB_OUTPUT
61+
4462 deploy-infrastructure :
4563 name : Deploy Azure Infrastructure
4664 runs-on : ubuntu-latest
@@ -149,11 +167,12 @@ jobs:
149167
150168 cicd :
151169 name : Build and Deploy to Azure Web App
152- needs : deploy-infrastructure
170+ needs : [version, deploy-infrastructure]
153171 runs-on : ubuntu-latest
154172 env :
155173 AZURE_ACR_NAME : ${{ needs.deploy-infrastructure.outputs.acr_name }}
156174 AZURE_WEBAPP_NAME : ${{ needs.deploy-infrastructure.outputs.webapp_name }}
175+ APP_VERSION : ${{ needs.version.outputs.version }}
157176 steps :
158177 # Checkout the repo
159178 - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -191,16 +210,33 @@ jobs:
191210
192211 - name : Build and Push Docker Image
193212 run : |
194- docker build ./src/webapp01 --file ./src/webapp01/Dockerfile -t ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:${{ github.sha }}
195- docker tag ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:${{ github.sha }} ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:latest
213+ docker build ./src/webapp01 --file ./src/webapp01/Dockerfile \
214+ --build-arg APP_VERSION=${{ env.APP_VERSION }} \
215+ -t ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:${{ github.sha }} \
216+ -t ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:v${{ env.APP_VERSION }} \
217+ -t ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:latest
196218 docker push ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:${{ github.sha }}
219+ docker push ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:v${{ env.APP_VERSION }}
197220 docker push ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:latest
198221
199222 - name : Azure Web Apps Deploy
200223 uses : azure/webapps-deploy@8db8b8d14f21b245e6706fd0607244e354884697 # v3
201224 with :
202225 app-name : ${{ env.AZURE_WEBAPP_NAME }}
203- images : " ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:${{ github.sha }}"
226+ images : " ${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:v${{ env.APP_VERSION }}"
227+
228+ - name : Create and push semantic version git tag
229+ shell : pwsh
230+ run : |
231+ $tag = "v${{ env.APP_VERSION }}"
232+ $remote = & git ls-remote --tags origin "refs/tags/$tag"
233+ if (-not [string]::IsNullOrWhiteSpace($remote)) {
234+ Write-Host "Tag $tag already exists on origin; skipping."
235+ exit 0
236+ }
237+ & git tag -a $tag -m "Release $tag"
238+ & git push origin $tag
239+ Write-Host "Created and pushed git tag $tag."
204240
205241 - name : Add deployment link to summary
206242 run : |
@@ -211,7 +247,8 @@ jobs:
211247 echo "| Resource | Value |" >> $GITHUB_STEP_SUMMARY
212248 echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
213249 echo "| URL | ${{ needs.deploy-infrastructure.outputs.webapp_url }} |" >> $GITHUB_STEP_SUMMARY
214- echo "| Image | \`${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
250+ echo "| Version | \`v${{ env.APP_VERSION }}\` |" >> $GITHUB_STEP_SUMMARY
251+ echo "| Image | \`${{ env.AZURE_ACR_NAME }}.azurecr.io/webapp01:v${{ env.APP_VERSION }}\` |" >> $GITHUB_STEP_SUMMARY
215252 echo "| Commit | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
216253
217254 - name : logout
@@ -221,10 +258,11 @@ jobs:
221258 # https://docs.github.com/en/actions/security-for-github-actions/using-artifact-attestations/using-artifact-attestations-and-reusable-workflows-to-achieve-slsa-v1-build-level-3
222259 container-build-publish :
223260 name : Build and Publish Container Image
261+ needs : version
224262 uses : devopsabcs-engineering/devsecops-reusable-workflows/.github/workflows/container.yml@main
225263 with :
226264 # This is used for tagging the container image
227- version : v1.0.0
265+ version : v${{ needs.version.outputs.version }}
228266 container-file : ./src/webapp01/Dockerfile
229267 container-context : ./src/webapp01
230268 container-name : " ${{ github.repository }}/webapp01"
0 commit comments