Skip to content

Commit 4e58129

Browse files
authored
Create deploy-pr.yml
1 parent 31b834a commit 4e58129

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

.github/workflows/deploy-pr.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Deploy to Azure for Review
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
jobs:
7+
build:
8+
name: Build
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Setup node 12
13+
uses: actions/setup-node@v1
14+
with:
15+
node-version: '12.x'
16+
17+
- name: Cache node modules
18+
id: cache-node
19+
uses: actions/cache@v1
20+
with:
21+
path: node_modules
22+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
23+
restore-keys: |
24+
${{ runner.os }}-node-
25+
26+
- name: Install dependencies
27+
if: steps.cache-node.outputs.cache-hit != 'true'
28+
run: |
29+
npm install --silent
30+
31+
- name: Build site
32+
run: npm run build
33+
34+
- name: Build popular-repos image
35+
uses: docker/build-push-action@v1
36+
with:
37+
username: ${{secrets.AZURE_REGISTRY_USER}}
38+
password: ${{secrets.AZURE_REGISTRY_PASS}}
39+
registry: ${{ secrets.AZURE_REGISTRY_NAME }}
40+
tags: ${{ github.event.pull_request.head.sha }}
41+
repository: popular-repos-old
42+
cache_froms: popular-repos-old:latest
43+
44+
deploy_to_azure:
45+
name: Deploy
46+
runs-on: ubuntu-latest
47+
needs: build
48+
steps:
49+
- name: Azure login
50+
uses: azure/login@v1
51+
with:
52+
creds: ${{ secrets.AZURE_SUBSCRIPTION_SECRET }}
53+
54+
- uses: chrnorm/deployment-action@v1.2.0
55+
name: Create GitHub deployment
56+
id: deployment
57+
with:
58+
token: ${{github.token }}
59+
ref: ${{ github.event.pull_request.head.sha }}
60+
environment: review-pr-${{ github.event.number }}
61+
62+
- name: Create deployment slot
63+
run: |
64+
az webapp deployment slot create --name popular-repos-old --resource-group pied-piper-inc --slot review-pr-${{ github.event.number }} --configuration-source popular-repos
65+
66+
- name: Deploy popular repos
67+
uses: azure/webapps-deploy@v2
68+
id: popular-repos-web
69+
with:
70+
app-name: 'popular-repos-old'
71+
images: '${{ secrets.AZURE_REGISTRY_NAME }}/popular-repos-old:${{ github.event.pull_request.head.sha }}'
72+
slot-name: review-pr-${{ github.event.number }}
73+
74+
- name: Update deployment status (success)
75+
if: success()
76+
uses: chrnorm/deployment-status@releases/v1
77+
with:
78+
token: "${{ github.token }}"
79+
target_url: ${{ steps.popular-repos-web.outputs.webapp-url }}
80+
state: "success"
81+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
82+
83+
- name: Update deployment status (failure)
84+
if: failure()
85+
uses: chrnorm/deployment-status@releases/v1
86+
with:
87+
token: "${{ github.token }}"
88+
state: "failure"
89+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}

0 commit comments

Comments
 (0)