-
Notifications
You must be signed in to change notification settings - Fork 64
168 lines (143 loc) · 5.21 KB
/
analyze-pr-changes.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
name: Analyze PR Changes
on: [pull_request]
env:
OPENSEARCH_INITIAL_ADMIN_PASSWORD: BobgG7YrtsdKf9M
jobs:
determine-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Docker Image
run: docker build coverage --tag opensearch-with-api-plugin
- name: Run OpenSearch
shell: bash -eo pipefail {0}
run: |
docker run \
--name opensearch \
--rm -d \
-p 9200:9200 -p 9600:9600 \
-e "discovery.type=single-node" \
-e OPENSEARCH_INITIAL_ADMIN_PASSWORD="$OPENSEARCH_INITIAL_ADMIN_PASSWORD" \
opensearch-with-api-plugin
for attempt in {1..20}; do
sleep 5
if curl -ksS -u "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" https://localhost:9200; then
echo '=> ready'
exit 0
fi
echo '=> waiting...'
done
exit 1
- name: Dump Cluster's API
shell: bash -eo pipefail {0}
run: curl -ksS -u "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" https://localhost:9200/_plugins/api | jq > /tmp/opensearch-openapi-CLUSTER.json
- name: Determine Branch Point
shell: bash -eo pipefail {0}
run: |
{
echo "BRANCH_POINT_SHA=$(git merge-base "$BASE_SHA" "$HEAD_SHA")"
echo "HEAD_SHA=${HEAD_SHA}"
} | tee "$GITHUB_ENV"
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
- name: Checkout Original Spec
shell: bash -eo pipefail {0}
run: git checkout $BRANCH_POINT_SHA
- name: Build Original Spec
shell: bash -eo pipefail {0}
run: |
npm install
npm run merge -- --source ./spec --output /tmp/opensearch-openapi-ORIGINAL.yaml
- name: Checkout Changed Spec
shell: bash -eo pipefail {0}
run: git checkout $HEAD_SHA
- name: Build Changed Spec
shell: bash -eo pipefail {0}
run: |
npm install
npm run merge -- --source ./spec --output /tmp/opensearch-openapi-CHANGED.yaml
- name: Calculate Coverage
shell: bash -eo pipefail {0}
run: |
for variant in ORIGINAL CHANGED ; do
echo "Calculating coverage of ${variant}"
npm run coverage:spec -- \
--cluster /tmp/opensearch-openapi-CLUSTER.json \
--specification /tmp/opensearch-openapi-${variant}.yaml \
--output /tmp/coverage-api-${variant}.json
done
- name: Upload Coverage Data
id: upload-coverage
uses: actions/upload-artifact@v4
with:
name: coverage-api
path: |
/tmp/coverage-api-ORIGINAL.json
/tmp/coverage-api-CHANGED.json
- name: Install openapi-changes
shell: bash -eo pipefail {0}
run: npm install --global @pb33f/openapi-changes
- name: Generate HTML Report
shell: bash -eo pipefail {0}
run: openapi-changes html-report --no-logo --no-color /tmp/opensearch-openapi-ORIGINAL.yaml /tmp/opensearch-openapi-CHANGED.yaml
- name: Upload HTML Report
id: upload-report
uses: actions/upload-artifact@v4
with:
name: changes-report
path: |
report.html
/tmp/opensearch-openapi-ORIGINAL.yaml
/tmp/opensearch-openapi-CHANGED.yaml
- name: Generate Summary
shell: bash -eo pipefail {0}
run: |
if ! openapi-changes summary --no-logo --no-color --markdown /tmp/opensearch-openapi-ORIGINAL.yaml /tmp/opensearch-openapi-CHANGED.yaml >output.md ; then
if ! grep -q 'breaking changes discovered' output.md ; then
cat output.md >/dev/stderr
exit 1
fi
fi
gawk -v HEAD_SHA="${HEAD_SHA}" -v REPORT_URL="${REPORT_URL}" '
BEGIN {
print "### API Changes Summary"
RS = "(\r|\n|\r\n)"
WAS_BLANK = 0
HAD_CHANGES = 0
}
/^starting work/ || /^Building original model/ || /^SPEC: extracted/ || /^ERROR: breaking/ || /^DONE: completed/ {
next
}
/^[[:space:]]*$/ {
WAS_BLANK = 1
next
}
WAS_BLANK {
WAS_BLANK = 0
print ""
}
{
HAD_CHANGES = 1
sub(/Commit: New:/, "Commit: " HEAD_SHA ", New:")
print
}
END {
if (!HAD_CHANGES) {
print "Commit: " HEAD_SHA ", **NO CHANGES**\n"
}
print "\nFull Report: " REPORT_URL
}
' output.md | tee changes-summary.md
env:
REPORT_URL: ${{ steps.upload-report.outputs.artifact-url }}
- name: Upload Summary
uses: actions/upload-artifact@v4
with:
name: changes-summary
path: changes-summary.md