Check Neon API Spec Updates #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
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: [email protected] | |
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: [email protected]" \ | |
ntfy.sh/neon-api-spec-updated |