-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (138 loc) · 4.43 KB
/
azure-jam-comments-api.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
name: Deploy JamComments API to Azure Functions
on:
workflow_dispatch:
inputs:
environment:
description: 'Name of environment to deploy (staging, prod)'
required: true
default: 'staging'
fullDeployment:
description: 'Whether to do a full deployment or not'
required: true
default: 'false'
push:
branches:
- dev
- master
paths:
- 'infra/azure/apps/api/**'
- '.github/workflows/azure-jam-comments-api.yml'
- 'AzureCommentsApiGet/**'
- 'AzureCommentsApiPost/**'
- 'AzureCommentsApiNotify/**'
- 'AzureHealthCheck/**'
- 'sql/**'
- 'src/**'
- 'test/**'
- 'yarn.lock'
pull_request:
types: [opened, synchronize]
paths:
- 'infra/azure/apps/api/**'
- '.github/workflows/azure-jam-comments-api.yml'
- 'AzureCommentsApiGet/**'
- 'AzureCommentsApiPost/**'
- 'AzureCommentsApiNotify/**'
- 'AzureHealthCheck/**'
- 'sql/**'
- 'src/**'
- 'test/**'
- 'yarn.lock'
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '20.x' # set this to the node version to use (supports 8.x, 10.x, 12.x)
fullDeployment: ${{ github.event.inputs.fullDeployment || 'false' }}
defaults:
run:
shell: bash
jobs:
setupEnv:
name: Set up environments
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: setup environment variables
id: setupEnv
run: |
echo "Setup environment and secrets"
if [ "${{ github.event.inputs.environment }}" = "staging" ] || [ "${{ github.ref }}" = "refs/heads/dev" ]; then
echo "::set-output name=environment::staging"
echo "::set-output name=githubEnvironment::Development"
elif [ "${{ github.event.inputs.environment }}" = "prod" ] || [ "${{ github.ref }}" = "refs/heads/master" ]; then
echo "::set-output name=environment::prod"
echo "::set-output name=githubEnvironment::Production"
fi
outputs:
environment: ${{ steps.setupEnv.outputs.environment }}
githubEnvironment: ${{ steps.setupEnv.outputs.githubEnvironment }}
name: jamcomments-${{ steps.setupEnv.outputs.environment }}-eus-fapp
build-and-test:
name: Build app and test
environment: ${{ needs.setupEnv.outputs.githubEnvironment }}
concurrency: ${{ needs.setupEnv.outputs.name }}
needs:
- setupEnv
env:
environment: ${{ needs.setupEnv.outputs.environment }}
runs-on: ubuntu-latest
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 }}
cache: 'yarn'
- name: 'Install packages, build and test'
shell: bash
run: |
yarn
yarn build
yarn test
deploy-to-azure:
if: (github.ref == 'refs/heads/dev') || (github.ref == 'refs/heads/master') || (github.event.inputs.environment != null)
name: Build app and deploy to Azure
runs-on: ubuntu-latest
environment: ${{ needs.setupEnv.outputs.githubEnvironment }}
concurrency: ${{ needs.setupEnv.outputs.name }}
needs:
- setupEnv
- build-and-test
env:
environment: ${{ needs.setupEnv.outputs.environment }}
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 }}
cache: 'yarn'
- name: 'Install packages and build'
shell: bash
run: |
yarn
yarn build
- name: Azure Login
timeout-minutes: 5
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Create infrastructure
run: infra/azure/apps/api/scripts/create-funcapp.sh
env:
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
- name: Install zip
uses: montudor/action-zip@v1
- name: 'Deploy to Azure Functions'
run: infra/azure/apps/api/scripts/deploy-funcapp.sh
- name: Azure Logout
if: ${{ always() }}
run: |
az logout
az cache purge
az account clear