-
Notifications
You must be signed in to change notification settings - Fork 0
207 lines (201 loc) · 7.59 KB
/
build_PR.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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: (PR)build and publish image to Functions
on:
pull_request:
branches: [ master ]
paths:
- 'Azure/Functions/**'
- 'Azure/Vue/**'
- '.github/**/*.yml'
env:
node-version: 13.10.1
dotnet: 6.0.300
registry: ghcr.io
image: weatherdisp
functionsApp: WeatherInfo
jobs:
CancelPreviousRuns:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
Prepare:
name: Prepare environment variable
runs-on: ubuntu-latest
outputs:
SLOT_NAME: ${{github.event.number}}-${{steps.run.outputs.safeBranch}}
BRANCH: ${{steps.run.outputs.safeBranch}}
TAG_NAME: ${{steps.run.outputs.safeBranch}}-${{steps.run.outputs.stag}}
env:
HEAD_REF: ${{github.head_ref}}
STAG: ${{github.event.pull_request.head.sha}}
steps:
- id: run
run: |
DATA=${HEAD_REF##*/}
echo "::set-output name=safeBranch::`echo $DATA | sed -E 's/[^a-zA-Z0-9]/\-/g'`"
echo "::set-output name=stag::${STAG::7}"
Create_Slot:
name: Create Azure functions slot if PR opened
runs-on: ubuntu-latest
needs: Prepare
steps:
- name: 'Login via Azure CLI'
if: github.event.action == 'opened' || github.event.action == 'reopened'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Env'
if: github.event.action == 'opened' || github.event.action == 'reopened'
run: |
echo RESOURCE_GROUP=`az functionapp list | jq -r '.[] | select(.name =="${{env.functionsApp}}") | .resourceGroup'` >> $GITHUB_ENV
- name: 'Create Azure functions slot'
if: github.event.action == 'opened' || github.event.action == 'reopened'
run: |
az functionapp deployment slot create --name ${{env.functionsApp}} --slot ${{needs.Prepare.outputs.SLOT_NAME}} --configuration-source ${{env.functionsApp}} --resource-group $RESOURCE_GROUP > /dev/null
Build_frontend:
name: Build frontend using Vue.
runs-on: ubuntu-latest
defaults:
run:
working-directory: Azure/Vue/weatherdisp
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Build
run: yarn run build
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: vue
path: Azure/Vue/weatherdisp/dist/index.html
Build_runtime:
name: Build functions.
runs-on: ubuntu-latest
defaults:
run:
working-directory: Azure/Functions/WeatherDisp
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.dotnet }}
- name: Create Dist
run: mkdir -p dist
- name: Build and publish
run: dotnet publish *.csproj --output dist
- name: Copy Image magick
run: cp dist/bin/runtimes/linux-x64/native/Magick.Native-Q8-x64.dll.so dist/bin/Magick.Native-Q8-x64.dll.so
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: functions
path: Azure/Functions/WeatherDisp/dist
Build_and_publish_image:
name: Build and publish image.
runs-on: ubuntu-latest
needs: [Prepare, Build_frontend, Build_runtime]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.registry }}
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Download frontend artifact
uses: actions/download-artifact@v2
with:
name: vue
path: images/artifacts/dist
- name: Download runtime artifact
uses: actions/download-artifact@v2
with:
name: functions
path: images/artifacts
- name: Prepare
id: prep
run: |
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: build image and push to GitHub Container Registry
uses: docker/build-push-action@v2
with:
push: true
context: images
tags: |
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:latest
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{ steps.prep.outputs.version }}
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.BRANCH}}-latest
${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
DeployPR:
name: Deploy functions container from PR
needs: [Prepare, Create_Slot, Build_and_publish_image]
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: GitHub Container Registry login
uses: azure/docker-login@v1
with:
login-server: ${{ env.registry }}
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Deploy PR container'
id: fa
uses: Azure/functions-container-action@v1
with:
app-name: ${{ env.functionsApp }}
image: ${{ env.registry }}/${{ github.repository_owner }}/${{ env.image }}:${{needs.Prepare.outputs.TAG_NAME}}
slot-name: ${{needs.Prepare.outputs.SLOT_NAME}}
- name: 'comment access url'
uses: actions/github-script@v1
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'URL is ${{steps.fa.outputs.app-url}}/api/WeatherInfo'
})