-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (133 loc) · 5.84 KB
/
call_update_docs_and_notification.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
on:
workflow_call:
inputs:
env:
type: string
description: Environment
required: true
api_folder_path:
type: string
description: Path of API folder
required: true
#/api/ms_external_api/v2
docs_openapi_path:
type: string
description: Path of docs storage openapi
required: true
#developer/external/v2/ms-external-api.json
api_title:
type: string
description: Title of API to show on message
required: true
enable_notification:
required: true
type: boolean
default: true
is_pnpg:
type: boolean
required: false
default: false
secrets:
API_NOTIFICATION_TRIGGERS_ID:
required: true
ARM_CLIENT_ID:
required: true
env:
DIR: "./infra/apim_v2"
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_USE_OIDC: true
ARM_USE_AZUREAD: true
ARM_STORAGE_USE_AZUREAD: true
jobs:
detect:
name: 'Update Developer Docs And Sending Slack notification'
runs-on: ubuntu-20.04
environment: ${{ inputs.env }}-cd
permissions:
id-token: write
contents: read
steps:
- name: Checkout
id: checkout
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707
- name: Azure Login
uses: azure/login@cb79c773a3cfa27f31f25eb3f677781210c9ce3d # v1.6.1
with:
client-id: ${{ secrets.ARM_CLIENT_ID }}
tenant-id: ${{ vars.ARM_TENANT_ID }}
subscription-id: ${{ vars.ARM_SUBSCRIPTION_ID }}
- name: Extract environment short
id: extract_env_short
shell: bash
run: |
env=${{ inputs.env }}
echo "env_short=${env:0:1}" >> $GITHUB_OUTPUT
if ${{ inputs.is_pnpg }}; then
echo "checkout_cdn_name=selc-${env:0:1}-weu-pnpg-checkout-cdn-endpoint" >> $GITHUB_OUTPUT
echo "checkout_cdn_profile=selc-${env:0:1}-weu-pnpg-checkout-cdn-profile" >> $GITHUB_OUTPUT
echo "pnpg_suffix=-weu-pnpg" >> $GITHUB_OUTPUT
echo "pnpg_suffix_storage=weupnpg" >> $GITHUB_OUTPUT
else
echo "checkout_cdn_name=selc-${env:0:1}-checkout-cdn-endpoint" >> $GITHUB_OUTPUT
echo "checkout_cdn_profile=selc-${env:0:1}-checkout-cdn-profile" >> $GITHUB_OUTPUT
echo "pnpg_suffix=''" >> $GITHUB_OUTPUT
echo "pnpg_suffix_storage=''" >> $GITHUB_OUTPUT
fi
- name: Download Developer OpenAPI from blob storage
uses: azure/CLI@965c8d7571d2231a54e321ddd07f7b10317f34d9 # v2
with:
inlineScript: |
mkdir docs
az storage blob download-batch --auth-mode key -d ./docs/ --account-name selc${{ steps.extract_env_short.outputs.env_short }}${{ steps.extract_env_short.outputs.pnpg_suffix_storage }}checkoutsa -s '$web' --pattern ${{ inputs.docs_openapi_path }}
- name: Install Optic
run: npm install --location global @useoptic/optic
shell: bash
- name: Verify if Operation Changes
id: optic_diff
shell: bash
run: |
optic_output=$(optic diff ./docs/${{ inputs.docs_openapi_path }} ${{ env.DIR }}${{ inputs.api_folder_path }}/openapi.${{ inputs.env }}.json)
echo "$optic_output"
echo "$optic_output" > optic_diff_output.txt
if grep -q "Operations: No operations changed" optic_diff_output.txt; then
echo "changes_detected=false" >> $GITHUB_OUTPUT
else
echo "changes_detected=true" >> $GITHUB_OUTPUT
fi
- name: Upload to blob storage
uses: azure/CLI@965c8d7571d2231a54e321ddd07f7b10317f34d9 # v2
if: ${{ steps.optic_diff.outputs.changes_detected == 'true'}}
with:
inlineScript: |
az storage blob upload --auth-mode key \
--container '$web' \
--account-name selc${{ steps.extract_env_short.outputs.env_short }}${{ steps.extract_env_short.outputs.pnpg_suffix_storage }}checkoutsa \
--file "${{ env.DIR }}${{ inputs.api_folder_path }}/openapi.${{ inputs.env }}.json" \
--overwrite true \
--name '${{ inputs.docs_openapi_path }}' &&
az cdn endpoint purge \
--resource-group selc-${{ steps.extract_env_short.outputs.env_short }}${{ steps.extract_env_short.outputs.pnpg_suffix }}-checkout-fe-rg \
--name ${{ steps.extract_env_short.outputs.checkout_cdn_name }} \
--profile-name ${{ steps.extract_env_short.outputs.checkout_cdn_profile }} \
--content-paths "/${{ inputs.docs_openapi_path }}" \
--no-wait
- name: Extract changes MD
if: ${{ inputs.enable_notification && steps.optic_diff.outputs.changes_detected == 'true' }}
id: extract_change_md
shell: bash
run: |
changed_operations=$(awk '/Operations/{flag=1; next} /Rerun this/{flag=0} flag' optic_diff_output.txt)
echo "$changed_operations"
echo "$changed_operations" > changed_operations.txt
- name: Send HTTP POST notification using Slack
if: ${{ inputs.enable_notification && steps.optic_diff.outputs.changes_detected == 'true' }}
run: |
body_content=$(cat changed_operations.txt)
curl -X POST https://hooks.slack.com/triggers/${{ secrets.API_NOTIFICATION_TRIGGERS_ID }} \
-H "Content-Type: application/json" \
-d '{
"body": "'"$body_content"'",
"title": "${{ inputs.api_title }}"
}'