-
Notifications
You must be signed in to change notification settings - Fork 3
146 lines (128 loc) · 5 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
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 }}
env:
NODE_VERSION: 18.x
jobs:
set-env:
name: Determine environment
runs-on: ubuntu-22.04
outputs:
environment: ${{ steps.var.outputs.environment }}
release: ${{ steps.var.outputs.release }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: var
run: |
INPUT=${{ github.event.inputs.environment }}
ENVIRONMENT=${INPUT:-"dev"}
RELEASE=${ENVIRONMENT,,}-`date +%Y-%m-%d`.${{ github.run_number }}
echo "environment=${ENVIRONMENT,,}" >> $GITHUB_OUTPUT
echo "release=${RELEASE}" >> $GITHUB_OUTPUT
deploy-image:
name: Deploy
needs: [ set-env ]
uses: DFE-Digital/deploy-azure-container-apps-action/.github/workflows/[email protected]
with:
docker-image-name: 'a2bint-app'
docker-build-file-name: './Dockerfile'
environment: ${{ needs.set-env.outputs.environment }}
secrets:
azure-acr-credentials: ${{ secrets.ACR_CREDENTIALS }}
azure-acr-name: ${{ secrets.ACR_NAME }}
azure-aca-credentials: ${{ secrets.AZURE_ACA_CREDENTIALS }}
azure-aca-name: ${{ secrets.AZURE_ACA_NAME }}
azure-aca-resource-group: ${{ secrets.AZURE_ACA_RESOURCE_GROUP }}
create-tag:
name: Tag and release
needs: [ set-env, deploy-image ]
runs-on: ubuntu-22.04
if: needs.set-env.outputs.environment == 'production'
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: false,
generate_release_notes: true,
name: "${{ needs.set-env.outputs.release }}",
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: "${{ needs.set-env.outputs.release }}",
});
} catch (error) {
core.setFailed(error.message);
}
cypress-tests:
name: Run Cypress Tests
if: needs.set-env.outputs.environment == 'staging' || needs.set-env.outputs.environment == 'dev'
needs: [ deploy-image, set-env ]
runs-on: ubuntu-22.04
environment: ${{ needs.set-env.outputs.environment }}
defaults:
run:
working-directory: Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Npm install
run: npm install
- name: Run cypress (staging)
if: needs.set-env.outputs.environment == 'staging'
run: npm run cy:run -- --env url='${{ secrets.AZURE_ENDPOINT }}',grep='-dao',cypressTestSecret='${{ secrets.CYPRESS_TEST_SECRET }}, academisationApiUrl=${{secrets.CYPRESS_ACADEMISATION_API_URL}}, academisationApiKey=${{ secrets.CYPRESS_ACADEMISATION_API_KEY}}'
env:
db: ${{ secrets.DB_CONNECTION_STRING }}
- name: Run cypress (dev)
if: needs.set-env.outputs.environment == 'dev'
run: npm run cy:run -- --env url='${{ secrets.AZURE_ENDPOINT }}',cypressTestSecret='${{ secrets.CYPRESS_TEST_SECRET }}, academisationApiUrl=${{secrets.CYPRESS_ACADEMISATION_API_URL}}, academisationApiKey=${{ secrets.CYPRESS_ACADEMISATION_API_KEY}}'
env:
db: ${{ secrets.DB_CONNECTION_STRING }}
- name: Upload screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ needs.set-env.outputs.environment }}
path: Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/screenshots
- name: Generate report
if: always()
run: |
mkdir mochareports
npm run generate:html:report
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: reports-${{ needs.set-env.outputs.environment }}
path: Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/mochareports
- name: Report results
if: always()
run: npm run cy:notify -- --custom-text="Environment ${{ needs.set-env.outputs.environment }}, See more information https://github.com/DFE-Digital/prepare-academy-conversions/actions/runs/${{github.run_id}}"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}