-
Notifications
You must be signed in to change notification settings - Fork 15
138 lines (110 loc) · 4.59 KB
/
auto-preview.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
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
name: Auto Preview
on:
pull_request_target:
branches:
- master
types: [opened, synchronize, reopened, closed]
jobs:
deploy:
if: github.event.action != 'closed'
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Azure/docker-login@v1
with:
login-server: api7registry.azurecr.io
username: ${{ secrets.AZURE_REGISTRY_USERNAME }}
password: ${{ secrets.AZURE_REGISTRY_PASSWORD }}
- id: set-deploy-comment-body
name: Set deploy comment body
run: |
DATE=$(date)
echo "**The auto preview on your projects!**." >> deploy.txt
echo "| Name | Status | Preview | Updated|" >> deploy.txt
echo "| :--- | :----- | :------ | :------ |" >> deploy.txt
echo "| **contributor-graph** | Deploying | | $DATE |" >> deploy.txt
BODY=$(cat deploy.txt)
BODY="${BODY//'%'/'%25'}"
BODY="${BODY//$'\n'/'%0A'}"
BODY="${BODY//$'\r'/'%0D'}"
echo "::set-output name=body::$BODY"
- name: Find comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: "The auto preview on your projects!"
- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.set-deploy-comment-body.outputs.body }}
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v2
with:
edit-mode: replace
comment-id: ${{ steps.fc.outputs.comment-id }}
body: ${{ steps.set-deploy-comment-body.outputs.body }}
- name: Build Contributor Graph Images
run: |
docker build -t api7/contributor-graph:dev .
- name: Push to Azure Registry
run: |
docker tag api7/contributor-graph:dev api7registry.azurecr.io/contributor-graph:${{ github.event.pull_request.number }}
docker push api7registry.azurecr.io/contributor-graph:${{ github.event.pull_request.number }}
- uses: azure/login@v1
with:
environment: AzureCloud
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Install Contributor Graph
run: |
az account set --subscription ffb9d49d-93e7-4f61-bf47-1e9b5f9e4cc0
az aks get-credentials --resource-group API7-Web-Preview_group --name API7-Web-Preview
export ID=${{ github.event.pull_request.number }}
sh ./preview/install.sh
kubectl rollout restart deployment/contributor-graph-${{ github.event.pull_request.number }} -n contributor-graph
- id: set-preview-comment-body
name: Set preview comment body
run: |
DATE=$(date)
echo "**The auto preview on your projects!**." >> preview.txt
echo "| Name | Status | Preview | Updated|" >> preview.txt
echo "| :--- | :----- | :------ | :------ |" >> preview.txt
echo "| **contributor-graph** | ✅ Ready | [Visit Preview](http://contributor-graph-${{ github.event.pull_request.number }}.preview.api7.ai) | $DATE |" >> preview.txt
BODY=$(cat preview.txt)
BODY="${BODY//'%'/'%25'}"
BODY="${BODY//$'\n'/'%0A'}"
BODY="${BODY//$'\r'/'%0D'}"
echo "::set-output name=body::$BODY"
- name: Find comment
uses: peter-evans/find-comment@v2
id: fc2
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: "The auto preview on your projects!"
- name: Update comment
if: steps.fc2.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
edit-mode: replace
body: ${{ steps.set-preview-comment-body.outputs.body }}
clean:
if: github.event.action == 'closed'
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: azure/login@v1
with:
environment: AzureCloud
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Uninstall Contributor Graph
run: |
az account set --subscription ffb9d49d-93e7-4f61-bf47-1e9b5f9e4cc0
az aks get-credentials --resource-group API7-Web-Preview_group --name API7-Web-Preview
export ID=${{ github.event.pull_request.number }}
sh ./preview/uninstall.sh