-
Notifications
You must be signed in to change notification settings - Fork 8
180 lines (160 loc) · 6.21 KB
/
build-and-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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Build and deploy
permissions:
id-token: write
deployments: write
packages: write
contents: write
actions: read
checks: read
pull-requests: write
statuses: read
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
build_and_test:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- name: Install dependencies
run: pnpm install
- name: Run linters
run: pnpm lint
- name: Test and create coverage
run: pnpm coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Build for production
run: pnpm build
env:
NUXT_PUBLIC_APPLICATION_INSIGHTS: ${{ vars.NUXT_PUBLIC_APPLICATION_INSIGHTS }}
- name: E2E testing
uses: cypress-io/github-action@v5
env:
CYPRESS_LOGIN_USERNAME: ${{ secrets.CYPRESS_LOGIN_USERNAME }}
CYPRESS_LOGIN_PASSWORD: ${{ secrets.CYPRESS_LOGIN_PASSWORD }}
with:
start: pnpm preview
wait-on: "http://localhost:9001"
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: cypress/videos
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-screenshots
path: cypress/screenshots
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: .output/public
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage
deploy_azure_static_web_apps:
runs-on: ubuntu-latest
needs: build_and_test
name: Deploy to Azure Static Web Apps
environment: prod
env:
swa_id: /subscriptions/${{ vars.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ vars.APP_SLUG }}-${{ vars.APP_ENV }}/providers/Microsoft.Web/staticSites/swa-${{ vars.APP_SLUG }}-frontend-${{ vars.APP_ENV }}
steps:
- name: Download production artifacts
uses: actions/download-artifact@v3
with:
name: dist
- name: Azure Login
uses: azure/login@v1
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Get Azure Token
uses: Azure/[email protected]
id: az_token
with:
inlineScript: |
AZ_TOKEN=$(az account get-access-token -o tsv --query 'accessToken')
echo "::add-mask::$AZ_TOKEN"
echo "token=$AZ_TOKEN" >> $GITHUB_OUTPUT
- name: Get Static Web App Token
id: swa_token
run: |
SWA_TOKEN=$(curl -H "Authorization: Bearer ${{ steps.az_token.outputs.token }}" -X POST https://management.azure.com${{ env.swa_id }}/listsecrets?api-version=2019-08-01 -d "" -s -S -f | jq -r '.properties.apiKey')
echo "::add-mask::$SWA_TOKEN"
echo "token=$SWA_TOKEN" >> $GITHUB_OUTPUT
- name: Deploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ steps.swa_token.outputs.token }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
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
skip_app_build: true
app_location: "/"
output_location: ""
###### End of Repository/Build Configurations ######
env:
SKIP_DEPLOY_ON_MISSING_SECRETS: true
- name: Rotate Static Web App Token
if: always()
run: |
curl -H "Authorization: Bearer ${{ steps.az_token.outputs.token }}" -X POST https://management.azure.com${{ env.swa_id }}/resetapikey?api-version=2019-08-01 -d "" -s -S -f
remove_azure_static_web_apps_when_pr_closed:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Remove Azure Static Web App
environment: prod
env:
swa_id: /subscriptions/${{ vars.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ vars.APP_SLUG }}-${{ vars.APP_ENV }}/providers/Microsoft.Web/staticSites/swa-${{ vars.APP_SLUG }}-frontend-${{ vars.APP_ENV }}
steps:
- name: Azure Login
uses: azure/login@v1
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Get Azure Token
uses: Azure/[email protected]
id: az_token
with:
inlineScript: |
AZ_TOKEN=$(az account get-access-token -o tsv --query 'accessToken')
echo "::add-mask::$AZ_TOKEN"
echo "token=$AZ_TOKEN" >> $GITHUB_OUTPUT
- name: Get Static Web App Token
id: swa_token
run: |
SWA_TOKEN=$(curl -H "Authorization: Bearer ${{ steps.az_token.outputs.token }}" -X POST https://management.azure.com${{ env.swa_id }}/listsecrets?api-version=2019-08-01 -d "" -s -S -f | jq -r '.properties.apiKey')
echo "::add-mask::$SWA_TOKEN"
echo "token=$SWA_TOKEN" >> $GITHUB_OUTPUT
- name: Remove the Azure Static Web App
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ steps.swa_token.outputs.token }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
app_location: "/"
action: "close"
- name: Rotate Static Web App Token
if: always()
run: |
curl -H "Authorization: Bearer ${{ steps.az_token.outputs.token }}" -X POST https://management.azure.com${{ env.swa_id }}/resetapikey?api-version=2019-08-01 -d "" -s -S -f
build-electron-app:
if: github.event.action != 'closed'
uses: ./.github/workflows/electron.yml
secrets: inherit