-
Notifications
You must be signed in to change notification settings - Fork 9
99 lines (91 loc) · 4.26 KB
/
azure-swa-deploy-byof-ms.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
name: Azure Static Web Apps CI/CD BYOF MS
env:
swaconfig: src/front/staticwebapp.config.json
footerjs: src/front/src/components/Footer/Footer.js
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
pull_request_target:
# Only run when the pull request has at least one label
# Exact label will be checked below
types: [labeled, reopened, closed]
workflow_dispatch:
jobs:
build_and_deploy_job:
if: github.event_name == 'workflow_dispatch'
|| github.event_name == 'push'
|| (github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name)
|| (github.event_name == 'pull_request_target' && github.event.action != 'closed' && contains(github.event.pull_request.labels.*.name, 'safe to test'))
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
# Check out files
- uses: actions/checkout@v2
with:
submodules: true
# Update NPM & Node to proper versions for SWA
- uses: actions/setup-node@v2
with:
node-version: 16.x
- name: cache node_modules
uses: actions/cache@v2
with:
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
path: |
node_modules
- name: install latest npm
run: |
npm install -g npm &&
npm --version &&
npm list -g --depth 0
# Replace __APP_VERSION__ in footer
- name: Replace APP_VERSION in footer
uses: falnyr/replace-env-vars-action@master
with:
filename: ${{ env.footerjs }}
env:
APP_VERSION: ${{github.workflow}}.${{github.head_ref}}.${{github.run_number}}
# Replace __AZURE_TENANT_ID__ in staticwebapp.config.json variables
- name: Add Azure Tenant ID in staticwebapp.config.json
uses: falnyr/replace-env-vars-action@master
with:
filename: ${{env.swaconfig}}
env:
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID_MS }}
- name: Display contents of updated staticwebapp.config.json file
run: cat ${{env.swaconfig}}
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.SAS_DEPLOYMENT_TOKEN_BYOF_MS }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e., PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "src/front" # App source code path
app_build_command: "npm ci && npm run build"
output_location: "build" # Built app content directory - optional
##api_location: "src/api" # Api source code path - optional
###### End of Repository/Build Configurations ######
close_pull_request_job:
# On a pull request close
if:
(github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
&& github.event.action == 'closed'
runs-on: ubuntu-latest
name: Remove SWA Environment on Pull Request Close Job
env:
swa_secret: ${{ secrets.SAS_DEPLOYMENT_TOKEN }}
steps:
- name: Remove SWA Environment
if: ${{ env.swa_secret }}
id: removeswaenvironment
uses: Azure/static-web-apps-deploy@v1
with:
# Remove the Environment that might have been created for the PR
azure_static_web_apps_api_token: ${{ secrets.SAS_DEPLOYMENT_TOKEN }}
action: "close"