-
Notifications
You must be signed in to change notification settings - Fork 3
157 lines (145 loc) · 5.55 KB
/
build-and-push-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Deploy to environment
on:
push:
branches:
- main
workflow_dispatch:
inputs:
environment:
type: environment
description: "Choose an environment to deploy to"
required: true
concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.environment }}
jobs:
set-env:
name: Determine environment
runs-on: ubuntu-24.04
outputs:
environment: ${{ steps.var.outputs.environment }}
branch: ${{ steps.var.outputs.branch }}
release: ${{ steps.var.outputs.release }}
checked-out-sha: ${{ steps.var.outputs.checked-out-sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get branch name for push/dispatch event
run: |
GIT_REF=${{ github.ref_name }}
echo "branch_ref=${GIT_REF}" >> $GITHUB_ENV
- id: var
run: |
GIT_REF=${{ env.branch_ref }}
GIT_BRANCH=${GIT_REF##*/}
INPUT=${{ github.event.inputs.environment }}
ENVIRONMENT=${INPUT:-"development"}
CHECKED_OUT_SHA="$(git log -1 '--format=format:%H')"
RELEASE=${ENVIRONMENT,,}-`date +%Y-%m-%d`.${{ github.run_number }}
echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT
echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT
echo "checked-out-sha=${CHECKED_OUT_SHA}" >> $GITHUB_OUTPUT
echo "release=${RELEASE}" >> $GITHUB_OUTPUT
build-import-init-container:
permissions:
id-token: write
contents: read
packages: write
name: Build and import Init Container
needs: [ set-env ]
uses: DFE-Digital/deploy-azure-container-apps-action/.github/workflows/[email protected]
with:
docker-image-name: tramsapi-app
docker-build-target: initcontainer
docker-tag-prefix: init-
environment: ${{ needs.set-env.outputs.environment }}
import-without-deploy: true
docker-build-args: CI=true
secrets:
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
azure-acr-client-id: ${{ secrets.ACR_CLIENT_ID }}
azure-acr-name: ${{ secrets.ACR_NAME }}
azure-aca-client-id: ${{ secrets.ACA_CLIENT_ID }}
azure-aca-name: ${{ secrets.ACA_CONTAINERAPP_NAME }}
azure-aca-resource-group: ${{ secrets.ACA_RESOURCE_GROUP }}
build-import-deploy-app:
permissions:
id-token: write
contents: read
packages: write
name: Build, import and deploy App Container
needs: [ build-import-init-container ]
uses: DFE-Digital/deploy-azure-container-apps-action/.github/workflows/[email protected]
with:
docker-image-name: tramsapi-app
docker-build-target: final
environment: ${{ needs.set-env.outputs.environment }}
annotate-release: true
docker-build-args: |
COMMIT_SHA="${{ needs.set-env.outputs.checked-out-sha }}"
CI=true
secrets:
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
azure-acr-client-id: ${{ secrets.ACR_CLIENT_ID }}
azure-acr-name: ${{ secrets.ACR_NAME }}
azure-aca-client-id: ${{ secrets.ACA_CLIENT_ID }}
azure-aca-name: ${{ secrets.ACA_CONTAINERAPP_NAME }}
azure-aca-resource-group: ${{ secrets.ACA_RESOURCE_GROUP }}
create-tag:
name: Tag and release
needs: [ set-env, build-import-deploy-app ]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Create tag
run: |
git tag ${{ needs.set-env.outputs.release }}
git push origin ${{ needs.set-env.outputs.release }}
- name: Create release
uses: "actions/github-script@v7"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
try {
await github.rest.repos.createRelease({
draft: ${{ needs.set-env.outputs.environment == 'test' }},
generate_release_notes: true,
name: "${{ needs.set-env.outputs.release }}",
owner: context.repo.owner,
prerelease: ${{ needs.set-env.outputs.environment == 'test' }},
repo: context.repo.repo,
tag_name: "${{ needs.set-env.outputs.release }}",
});
} catch (error) {
core.setFailed(error.message);
}
- name: Trigger Build and Push NuGet Package workflow
uses: "actions/github-script@v7"
if: needs.set-env.outputs.environment == 'production'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const tagName = "${{ needs.set-env.outputs.release }}"
console.log("Triggering Build and Push NuGet Package workflow with tag:", tagName);
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "build-and-push-package.yml",
ref: "main",
inputs: {
tag_name: tagName
}
});
cypress-tests:
name: Run Cypress Tests
needs: [ set-env, create-tag ]
if: needs.set-env.outputs.environment == 'test' || needs.set-env.outputs.environment == 'development'
uses: ./.github/workflows/cypress-tests.yml
with:
environment: ${{ needs.set-env.outputs.environment }}
secrets:
TRAMS_API_KEY: ${{ secrets.TRAMS_API_KEY }}
TRAMS_API_BASE_URL: ${{ secrets.TRAMS_API_BASE_URL }}