Updates SDK based on api-definitions #1682
This file contains hidden or 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: Updates SDK based on api-definitions | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| generate-sdk: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout api-definitions repo | |
| uses: actions/checkout@v4 | |
| with: | |
| path: 'api-definitions' | |
| repository: 'Rebilly/api-definitions' | |
| - name: Checkout PHP SDK repo | |
| uses: actions/checkout@v4 | |
| with: | |
| path: 'sdk' | |
| fetch-depth: 0 | |
| - name: Keep changesets from auto-update branch | |
| working-directory: ./sdk | |
| run: | | |
| mkdir ../carry | |
| git checkout automations/update-sdk-from-api-definitions || true | |
| cp .changeset/* ../carry/ 2>/dev/null || true | |
| git checkout main || true | |
| cp ../carry/*.md .changeset/ 2>/dev/null || true | |
| - name: Checkout generator repo | |
| uses: actions/checkout@v4 | |
| with: | |
| token: '${{ secrets.MACHINE_USER_PAT }}' | |
| path: 'generator' | |
| repository: 'Rebilly/rebilly' | |
| sparse-checkout: | | |
| backend/php-sdk-generator/remove-fqcns.php | |
| backend/php-sdk-generator/remove-unused-models.php | |
| sparse-checkout-cone-mode: true | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.1' | |
| extensions: mbstring, intl, curl, json | |
| tools: composer:v2 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: "npm" | |
| registry-url: "https://npm.pkg.github.com/" | |
| scope: "@rebilly" | |
| cache-dependency-path: "sdk/package-lock.json" | |
| - name: Install api-definitions dependencies | |
| working-directory: ./api-definitions | |
| run: npm install | |
| - name: Build api-definitions | |
| working-directory: ./api-definitions | |
| run: npx redocly bundle all@latest -o all.yaml | |
| - name: Diff API spec against previous snapshot | |
| id: oasdiff | |
| run: | | |
| docker run --rm \ | |
| -v "$PWD/sdk:/sdk" \ | |
| -v "$PWD/api-definitions:/adef" \ | |
| tufin/oasdiff:v1.18.1 \ | |
| changelog /sdk/.openapi-snapshot.yaml /adef/catalog/all.yaml -f json > /tmp/spec-diff.json | |
| - name: Summarize spec diff | |
| id: summarize | |
| working-directory: ./sdk | |
| run: | | |
| node ./scripts/summarize-spec-diff.js /tmp/spec-diff.json > /tmp/changeset-body.md | |
| if [ -s /tmp/changeset-body.md ]; then | |
| echo "has_content=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Login to GitHub Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.MACHINE_USER_PAT }} | |
| - name: Install Dependencies | |
| working-directory: ./sdk | |
| run: npm ci --dev | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build SDK | |
| working-directory: ./sdk | |
| run: | | |
| mkdir /tmp/sdk | |
| rm -rf src | |
| npm run generate /tmp/sdk ../api-definitions/catalog/all.yaml | |
| - name: Bundle SDK | |
| run: | | |
| rm -rf ./sdk/{src,composer.json,.php-cs-fixer.php,psalm.xml} && \ | |
| cp -r /tmp/sdk/{src,composer.json,.php-cs-fixer.php,psalm.xml} ./sdk/ | |
| cd ./sdk && node ./scripts/update-sdk-version.js | |
| - name: Get composer cache directory | |
| working-directory: /tmp/sdk | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | |
| restore-keys: ${{ runner.os }}-composer- | |
| - name: Cache npm dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: '~/.npm' | |
| key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: ${{ runner.os }}-node- | |
| - name: Install composer dependencies | |
| working-directory: ./sdk | |
| run: composer install --prefer-dist | |
| - name: CS fix SDK | |
| working-directory: ./sdk | |
| run: composer cs-fix | |
| - name: Update snapshot | |
| working-directory: ./sdk | |
| run: cp ../api-definitions/catalog/all.yaml .openapi-snapshot.yaml | |
| - name: Write spec-diff changeset | |
| if: steps.summarize.outputs.has_content == 'true' | |
| working-directory: ./sdk | |
| run: | | |
| { | |
| echo '---' | |
| echo '"@rebilly/client-php": patch' | |
| echo '---' | |
| echo '' | |
| cat /tmp/changeset-body.md | |
| } > .changeset/spec-diff.md | |
| - name: Create PR | |
| id: cpr | |
| uses: peter-evans/create-pull-request@v5 | |
| with: | |
| # Path of the checked-out repo where we placed the generated resources | |
| path: 'sdk' | |
| token: ${{ secrets.MACHINE_USER_PAT }} | |
| title: 'chore: update SDK from api-definitions' | |
| commit-message: update SDK from api-definitions | |
| branch: automations/update-sdk-from-api-definitions | |
| base: main | |
| # Delete the branch when closing PRs or merging | |
| delete-branch: true | |
| body: This PR is automatically generated and updates SDK based on a change in the API definitions |