update-api-file #35
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 "api.yaml" ]; then | |
diff 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: Install dependencies using Yarn | |
if: env.api_changed == 'true' | |
run: yarn install --frozen-lockfile | |
- name: Generate SDK only if API changed | |
if: env.api_changed == 'true' | |
env: | |
NODE_OPTIONS: "--experimental-specifier-resolution=node --loader ts-node/esm --no-warnings" | |
run: | | |
mv new_api.yaml api.yaml | |
echo "Generating SDK based on updated API..." | |
npx @openapitools/openapi-generator-cli generate -i api.yaml -g typescript-fetch -o ./typescript-sdk | |
- name: Check for SDK changes | |
if: env.api_changed == 'true' | |
run: git diff --quiet ./typescript-sdk || echo "SDK files have changed" | |
- 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 . | |
git commit -m "Auto-update SDK based on new API file" | |
git push |