update-api-file #21
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: Update SDK | |
on: | |
repository_dispatch: | |
types: [update-api-file] | |
jobs: | |
update_sdk: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout auth-sdk repository | |
uses: actions/checkout@v2 | |
- name: Fetch the latest `api.yaml` from the docs repo | |
run: | | |
curl -H "Authorization: token ${{ secrets.AUTOGEN_GITHUB_TOKEN }}" -L \ | |
https://raw.githubusercontent.com/crestalnetwork/docs/main/mintlify-docs/api-reference/api.yaml \ | |
-o new_api.yaml | |
- name: Check for API changes | |
id: check_changes | |
run: | | |
if [ -f "typescript-sdk/api.yaml" ]; then | |
diff typescript-sdk/api.yaml new_api.yaml > /dev/null || echo "true" > api_changed.txt | |
else | |
echo "true" > api_changed.txt | |
fi | |
- name: Set API changed output | |
id: api_changed | |
run: | | |
if [ -f api_changed.txt ]; then | |
echo "api_changed=true" >> $GITHUB_ENV | |
else | |
echo "api_changed=false" >> $GITHUB_ENV | |
fi | |
- name: Generate SDK only if API changed | |
if: env.api_changed == 'true' | |
run: | | |
mv new_api.yaml api.yaml | |
npx @openapitools/openapi-generator-cli generate -i api.yaml -g typescript-fetch -o ./typescript-sdk | |
- name: Commit and push changes | |
if: env.api_changed == 'true' | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add api.yaml typescript-sdk/ api_changed.txt | |
git commit -m "Auto-update SDK based on new API file" | |
git push | |