This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (134 loc) · 5.24 KB
/
cd.yaml
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
158
159
name: Continuous Deployment
on:
workflow_dispatch:
push:
branches:
- saga
paths-ignore:
- Dockerfile
- .github/workflows/test-docker.yaml
- .github/workflows/publish-docker.yaml
- .github/workflows/test-and-release.yaml
permissions:
id-token: write
contents: write
issues: write
jobs:
deploy:
runs-on: ubuntu-22.04
environment:
name: production
url: ${{ steps.web-app-url.outputs.web_app_url }}
env:
APP_REG_CLIENT_ID: ${{ secrets.APP_REG_CLIENT_ID }}
LOCATION: ${{ secrets.LOCATION }}
APP_NAME: ${{ secrets.APP_NAME }}
STORAGE_ACCOUNT_NAME: ${{ secrets.STORAGE_ACCOUNT_NAME }}
B2C_TENANT: ${{ secrets.B2C_TENANT }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
NRF_CLOUD_TEAM_ID: ${{ secrets.NRF_CLOUD_TEAM_ID }}
NRF_CLOUD_SERVICE_KEY: ${{ secrets.NRF_CLOUD_SERVICE_KEY }}
outputs:
web_app_url: ${{ steps.web-app-url.outputs.web_app_url }}
steps:
- name: Login to Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: List Azure Accounts
uses: azure/CLI@v1
with:
inlineScript: |
az account list --output table
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18.x"
- name: Keep npm cache around to speed up installs
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm ci --no-audit
- name: Compile source
run: npx tsc
- name: Set Key Vault name
run: |
echo "keyVaultName=${APP_NAME:-nrfassettracker}" >> $GITHUB_ENV
- name: Set nRF Cloud Location Service key
uses: azure/CLI@v1
with:
inlineScript: |
echo "${{ secrets.NRF_CLOUD_SERVICE_KEY }}" > nrfcloudservice.key
az keyvault secret set --vault-name ${{ env.keyVaultName }} --name nrfCloudServiceKey --file nrfcloudservice.key
rm nrfcloudservice.key
- name: Determine Version
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
TAG=`git tag --contains ${{ github.sha }} | tr -d '\n'`
VERSION=${TAG:-${{ github.sha }}}
echo Version: ${VERSION}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Deploy solution
uses: azure/CLI@v1
with:
inlineScript: |
az deployment group create \
--resource-group ${{ env.RESOURCE_GROUP }} \
--mode Complete \
--name cd-${{ env.VERSION }} \
--template-file azuredeploy.json \
--parameters \
appName=${APP_NAME:-nrfassettracker} \
storageAccountName=${{ env.STORAGE_ACCOUNT_NAME }} \
appRegistrationClientId=${{ env.APP_REG_CLIENT_ID }} \
b2cTenant=${{ env.B2C_TENANT }} \
nrfCloudTeamId=${{ env.NRF_CLOUD_TEAM_ID }} \
keyVaultName=${{ env.keyVaultName }}
- name: Pack Function App
run: node scripts/pack-app.js
- name: Deploy Function App
uses: azure/CLI@v1
with:
inlineScript: |
az functionapp deployment source config-zip -g ${{ env.RESOURCE_GROUP }} -n ${APP_NAME:-nrfassettracker}api --src dist/functionapp.zip
- uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: functionapp-${{ github.sha }}
path: dist/functionapp.zip
- name: Enable static site hosting for the app
uses: azure/CLI@v1
with:
inlineScript: |
az storage blob service-properties update --account-name ${{ env.STORAGE_ACCOUNT_NAME }} --static-website --404-document index.html --index-document index.html
- name: Determine Web App settings
run: ./cli.sh react-config >> $GITHUB_ENV
- name: Determine public URL
id: web-app-url
uses: azure/CLI@v1
with:
inlineScript: |
PUBLIC_URL=`az storage account show -g ${{ env.RESOURCE_GROUP }} -n ${{ env.STORAGE_ACCOUNT_NAME }} --query 'primaryEndpoints.web' --output tsv | tr -d '\n'`
echo "web_app_url=${PUBLIC_URL}" >> $GITHUB_OUTPUT
echo "PUBLIC_URL=${PUBLIC_URL}" >> $GITHUB_ENV
- name: Build app
run: |
export EXTEND_ESLINT=true
WEBAPP_REPO=`cat package.json | jq -r '.deploy.webApp.repository'`
WEBAPP_BRANCH=`cat package.json | jq -r '.deploy.webApp.branch'`
git clone --branch $WEBAPP_BRANCH --single-branch $WEBAPP_REPO app
cd app
git fetch --tags
export REACT_APP_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $REACT_APP_VERSION
npm ci --no-audit
npm run build
- name: Deploy Web App
uses: azure/CLI@v1
with:
inlineScript: |
az storage blob upload-batch --account-name ${{ env.STORAGE_ACCOUNT_NAME }} --overwrite -s ./app/build -d '$web'