generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (92 loc) · 3.47 KB
/
functions-deploy.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
name: Deploy Node.js project to Azure Function App
on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
TF_ENVIRONMENT:
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true
permissions:
contents: read
env:
# The AZURE_FUNCTIONAPP_NAME has to match the azurerm_linux_function_app's name in functions.tf
AZURE_FUNCTIONAPP_NAME: 'polling-function-${{inputs.TF_ENVIRONMENT}}'
AZURE_FUNCTIONAPP_PACKAGE_PATH: 'azure_functions'
NODE_VERSION: '20.x'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment:
${{ inputs.ENVIRONMENT }}
permissions:
id-token: write
contents: read
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4
- name: 'Setup Node ${{ env.NODE_VERSION }} Environment'
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'Resolve Project Dependencies Using Npm'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm install
npm run build --if-present
npm run test --if-present
popd
- name: 'Login via Azure CLI'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: 'Get Publish Profile'
run: |
PUBLISH_PROFILE=$(az webapp deployment list-publishing-profiles -g "csels-rsti-${{ inputs.TF_ENVIRONMENT }}-moderate-rg" -n "polling-function-${{ inputs.TF_ENVIRONMENT }}" --xml)
echo "::add-mask::$PUBLISH_PROFILE"
echo "PUBLISH_PROFILE=$PUBLISH_PROFILE" >> $GITHUB_OUTPUT
id: getPublishProfile
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: azure-function-deploy
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ steps.getPublishProfile.outputs.PUBLISH_PROFILE }}
- name: 'Retrieve Azure FunctionApp loaded Functions'
run: |
MAX_TIME=300 # Maximum time in seconds (5 minutes)
INTERVAL=5 # Check every 5 seconds
ELAPSED_TIME=0
FAIL=true
# Loop until the function is created or the maximum time is reached
while [ $ELAPSED_TIME -lt $MAX_TIME ]; do
FUNCTION_LIST=$(az functionapp function list -g "csels-rsti-${{ inputs.TF_ENVIRONMENT }}-moderate-rg" -n "polling-function-${{ inputs.TF_ENVIRONMENT }}")
if [[ $FUNCTION_LIST != *"[]"* ]]; then
echo "Function found after $ELAPSED_TIME seconds"
FAIL=false
break
fi
# If we don't have a function yet, sleep INTERVAL seconds and increment elapsed time
echo "Function not found, sleeping $INTERVAL seconds. $ELAPSED_TIME seconds have elapsed so far"
sleep $INTERVAL
ELAPSED_TIME=$((ELAPSED_TIME + INTERVAL))
done
echo "FAIL=$FAIL" >> $GITHUB_OUTPUT
id: getFunctionList
- name: 'Azure FunctionApp Failed'
if: steps.getFunctionList.outputs.FAIL == 'true'
run: |
echo 'Azure FunctionApp Function is empty'
exit 1