-
-
Notifications
You must be signed in to change notification settings - Fork 5
115 lines (106 loc) · 3.68 KB
/
check-api-spec-updates.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
name: "Check Neon API Spec Updates"
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
main:
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-latest
outputs:
isNew: ${{ steps.diff_sdk.outputs.isNew }}
prId: ${{ steps.pr.outputs.pull-request-number }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Pull new spec
run: |
curl -SLo openAPIDefinition_new.json "$SPEC_URL"
env:
SPEC_URL: https://dfv3qgd2ykmrx.cloudfront.net/api_spec/release/v2.json
- name: Diff spec files
id: diff
run: |
if [ $(diff openAPIDefinition_new.json openAPIDefinition.json | wc -l) -gt 0 ]; then
echo "isNew=true" >> $GITHUB_OUTPUT
else
echo "isNew=false" >> $GITHUB_OUTPUT
fi
- uses: actions/setup-go@v4
if: steps.diff.outputs.isNew == 'true'
with:
go-version: 1.18
- name: Generate SDK using new spec
id: diff_sdk
if: steps.diff.outputs.isNew == 'true'
run: |
echo "isNew=false" >> $GITHUB_OUTPUT
mkdir tmp
make generate-sdk PATH_SPEC=${PWD}/openAPIDefinition_new.json PATH_SDK=${PWD}/tmp
for obj in $(ls ${PWD}/tmp); do
echo check ${obj}
if [ $(diff ${obj} ${PWD}/tmp/${obj} | wc -l) -gt 0 ]; then
echo diff in SDK generated using new new spec, file ${obj}
echo "isNew=true" >> $GITHUB_OUTPUT
fi
done
- name: MV new sdk to root
if: steps.diff_sdk.outputs.isNew == 'true'
run: |
mv ${PWD}/tmp/* .
mv openAPIDefinition_new.json openAPIDefinition.json
- name: Create Pull Request
if: steps.diff_sdk.outputs.isNew == 'true'
uses: peter-evans/create-pull-request@v5
id: pr
with:
add-paths: |
*.go
go.mod
openAPIDefinition.json
commit-message: |
feat: auto-updated SDK
signoff: true
branch: feat/auto-generated-new-api-spec
branch-suffix: timestamp
delete-branch: true
assignees: kislerdm
title: Auto-generated SDK upon new spec
body: |
## What changed
New generated SDK
## Why do we need it
To reflect API spec changes
notify:
runs-on: ubuntu-latest
name: Notify
needs:
- main
if: needs.main.outputs.isNew == 'true'
steps:
- name: Telegram
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
New Neon API spec has been detected. Please take action.
PR: https://github.com/kislerdm/neon-sdk-go/pull/${{ needs.main.outputs.prId }}
The message was sent from https://github.com/kislerdm/neon-sdk-go
Get in touch for details: admin@dkisler.com
continue-on-error: true
- name: Ntfy
run: |
curl \
-H "Title: Neon API Spec Updated" \
-H "Priority: urgent" \
-H "Tags: warning" \
-H "Actions: view, Open Repo: https://github.com/kislerdm/neon-sdk-go" \
-d "New Neon API spec has been detected. Please take action.
PR: https://github.com/kislerdm/neon-sdk-go/pull/${{ needs.main.outputs.prId }}
The message was sent from https://github.com/kislerdm/neon-sdk-go
Get in touch for details: admin@dkisler.com" \
ntfy.sh/neon-api-spec-updated