Skip to content

Check Neon API Spec Updates #479

Check Neon API Spec Updates

Check Neon API Spec Updates #479

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: make fetch-specs
- 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@v5
if: steps.diff.outputs.isNew == 'true'
with:
go-version-file: generator/go.mod
- 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@v6
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