-
Notifications
You must be signed in to change notification settings - Fork 3
233 lines (194 loc) · 7.03 KB
/
node.js.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js Build
env:
MODULE_VERSION: '1.0.${{ github.run_number }}' # update MAJOR and MINOR version here
DIST_PATH: 'dist/ezeep' # deployment path
ARTIFACT_NAME: 'ezeep-js.zip' # artifact name
DIST_PATH_NG: 'dist/directives' # angular directives deployment path
ARTIFACT_NAME_NG: 'ng-directives.zip' # angular directives artifact name
NPM_REGISTRY: 'https://registry.npmjs.org' # npm registry url
PRERELEASE: false # true if marked as pre-release, false if production-ready
on:
push:
branches: [ main ]
jobs:
build-npm:
environment: Production
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout main branch
uses: actions/checkout@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: "${{ env.NPM_REGISTRY }}"
cache: 'npm'
- name: Bump package.json version of npm package
uses: reedyuk/npm-version@1.1.1
with:
version: "${{ env.MODULE_VERSION }}"
- name: Build
run: |
npm ci
npm run build
- name: Publish npm package to npm registry
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Upload npm artifact
uses: actions/upload-artifact@v2
with:
path: ${{ env.DIST_PATH }}
name: ${{ env.ARTIFACT_NAME }}
- name: Upload ng directives artifacts
uses: actions/upload-artifact@v2
with:
path: ${{ env.DIST_PATH_NG }}
name: ${{ env.ARTIFACT_NAME_NG }}
- name: Zip npm artifact for release
uses: thedoctor0/zip-release@master
with:
type: 'zip'
directory: ${{ env.DIST_PATH }}
path: '.'
filename: ${{ env.ARTIFACT_NAME }}
- name: Create release with npm package
uses: ncipollo/release-action@v1
with:
tag: "${{ env.MODULE_VERSION }}"
prerelease: ${{ env.PRERELEASE }}
artifacts: "${{ env.DIST_PATH }}/${{ env.ARTIFACT_NAME }}"
token: ${{ secrets.GITHUB_TOKEN }}
build-ng:
environment: Production
needs: build-npm
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout angular branch
uses: actions/checkout@v2
with:
ref: ngx-ezeep-js
- name: Bump package.json version for angular component
uses: reedyuk/npm-version@1.1.1
with:
package: 'ezeep-js-angular/projects/ngx-ezeep-js'
version: "${{ env.MODULE_VERSION }}"
- name: download angular build artifact
uses: actions/download-artifact@v2
with:
name: ng-directives.zip
path: ezeep-js-angular/projects/ngx-ezeep-js/src/lib
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: "${{ env.NPM_REGISTRY }}"
cache: 'npm'
cache-dependency-path: 'ezeep-js-angular/projects/ngx-ezeep-js'
- name: build angular library and publish
run: |
cd ezeep-js-angular
npm install -g @angular/cli
npm install
cd projects/ngx-ezeep-js
npm install
cd ../..
ng build ngx-ezeep-js --prod
cd dist/ngx-ezeep-js
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
cdn-upload-npm:
environment: Production
needs: build-npm
runs-on: ubuntu-latest
steps:
- name: Download npm artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.ARTIFACT_NAME }}
path: "artifacts/v${{ env.MODULE_VERSION }}"
- name: Login to Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Upload artifact to blob storage
run: |
azenv='${{ secrets.AZURE_ENVIRONMENT }}'
account=$(jq -crM .storage.account <<< $azenv)
container=$(jq -crM .storage.container <<< $azenv)
az storage blob upload-batch \
--auth-mode login \
--account-name $account \
-d $container \
-s "artifacts" \
-o none
- name: Update Url redirect
run: |
azenv='${{ secrets.AZURE_ENVIRONMENT }}'
resourceGroup=$(jq -crM .resourceGroup <<< $azenv)
profile=$(jq -crM .cdn.profileName <<< $azenv)
endpoint=$(jq -crM .cdn.endpoint.name <<< $azenv)
rules=$(jq -crM .cdn.endpoint.rules[].name <<< $azenv)
container=$(jq -crM .storage.container <<< $azenv)
for rule in $rules; do
fileName=$(jq -crM --arg rule "$rule" \
'.cdn.endpoint.rules[]
| select(.name == $rule)
| .fileName' \
<<< $azenv)
index=$(az cdn endpoint rule action show \
-g $resourceGroup \
--profile-name $profile \
-n $endpoint \
| jq --arg rule "$rule" '.deliveryPolicy.rules[]
| select(.name == $rule)
| .actions | to_entries | .[]
| select(.value.name == "UrlRedirect") | .key' \
)
az cdn endpoint rule action remove \
-g $resourceGroup \
--profile-name $profile \
-n $endpoint \
--rule-name $rule \
--index $index \
-o none
az cdn endpoint rule action add \
-g $resourceGroup \
--profile-name $profile \
-n $endpoint \
--rule-name $rule \
--action-name UrlRedirect \
--custom-path "/$container/v${{ env.MODULE_VERSION }}/$fileName" \
--redirect-type Found \
-o none
done
- name: Purge CDN endpoint
run: |
azenv='${{ secrets.AZURE_ENVIRONMENT }}'
resourceGroup=$(jq -crM .resourceGroup <<< $azenv)
profile=$(jq -crM .cdn.profileName <<< $azenv)
endpoint=$(jq -crM .cdn.endpoint.name <<< $azenv)
container=$(jq -crM .storage.container <<< $azenv)
az cdn endpoint purge \
-g $resourceGroup \
--profile-name $profile \
-n $endpoint \
--content-paths "/$container/*" \
--no-wait \
-o none
- name: Azure CLI logout
run: |
az logout
az cache purge
az account clear
if: always()