From b1c2c3a67d729a3af8fd5c780027196a10a3376b Mon Sep 17 00:00:00 2001 From: 0div Date: Wed, 27 Nov 2024 11:32:15 -0800 Subject: [PATCH] add sdk autogen workflow and make it a part of the release workflow --- .github/scripts/is_new_sdk_ref.sh | 11 +++ .github/workflows/generate_sdk_ref.yml | 106 +++++++++++++++++++++++++ .github/workflows/release.yml | 24 ++++++ 3 files changed, 141 insertions(+) create mode 100755 .github/scripts/is_new_sdk_ref.sh create mode 100644 .github/workflows/generate_sdk_ref.yml diff --git a/.github/scripts/is_new_sdk_ref.sh b/.github/scripts/is_new_sdk_ref.sh new file mode 100755 index 0000000..7068585 --- /dev/null +++ b/.github/scripts/is_new_sdk_ref.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# This script checks for diffs in the js/ and python/ directory. +# If there are diffs, it means we need to generate new SDK references. +if git diff --name-only HEAD^ | grep -q '^js/\|^python/'; then + echo "true" +else + echo "false" +fi diff --git a/.github/workflows/generate_sdk_ref.yml b/.github/workflows/generate_sdk_ref.yml new file mode 100644 index 0000000..3173faf --- /dev/null +++ b/.github/workflows/generate_sdk_ref.yml @@ -0,0 +1,106 @@ +name: Generate SDK references + +on: + workflow_dispatch: + workflow_call: + # Remove after testing + push: + branches: + - improved-api-refs + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +permissions: + contents: write + +jobs: + is_new_sdk_ref: + name: Is new SDK reference? + runs-on: ubuntu-latest + outputs: + new_sdk_ref: ${{ steps.sdk-changes.outputs.new_sdk_ref }} + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Check if SDK changes + id: sdk-changes + run: | + IS_NEW_sdk_REF=$(./.github/scripts/is_new_sdk_ref.sh) + echo "new_sdk_ref=$IS_NEW_sdk_REF" >> "$GITHUB_OUTPUT" + + sdk-changes: + name: SDK changes + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install pnpm + uses: pnpm/action-setup@v3 + id: pnpm-install + with: + version: 9.5 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: "20.x" + registry-url: "https://registry.npmjs.org" + cache: pnpm + cache-dependency-path: pnpm-lock.yaml + + - name: Configure pnpm + run: | + pnpm config set auto-install-peers true + pnpm config set exclude-links-from-lockfile true + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Set up Python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: "3.8" + + - name: Install and configure Poetry + uses: snok/install-poetry@v1 + with: + version: 1.5.1 + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + - name: Install dependencies + working-directory: ./packages/python-sdk + run: poetry install --no-interaction --no-root + + - name: Generate Python SDK reference + id: python-sdk-ref + working-directory: ./python + run: | + source .venv/bin/activate + ./scripts/generate_sdk_ref.sh + + - name: Generate JS SDK reference + id: js-sdk-ref + working-directory: ./js + run: ./scripts/generate_sdk_ref.sh + + - name: Show docs file structure + run: tree apps/web/src/app/\(docs\)/docs/sdk-reference + + - name: Commit new SDK reference versions + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add ./sdk-reference + git commit -m "[skip ci] Release new SDK reference doc versions" || exit 0 + git push \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 237ebc6..2c22852 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -319,6 +319,30 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + is_new_sdk_ref: + name: Is new SDK reference? + runs-on: ubuntu-latest + outputs: + new_sdk_ref: ${{ steps.sdk-changes.outputs.new_sdk_ref }} + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Check if SDK changes + id: sdk-changes + run: | + IS_NEW_SDK_REF=$(./.github/scripts/is_new_sdk_ref.sh) + echo "new_sdk_ref=$IS_NEW_SDK_REF" >> "$GITHUB_OUTPUT" + + generate_sdk_ref: + name: Generate SDK reference + needs: [is_release, python-tests, js-tests, is_new_sdk_ref] + if: (!cancelled()) && !contains(needs.*.result, 'failure') && needs.is_release.outputs.release == 'true' && needs.is_new_sdk_ref.outputs.new_sdk_ref == 'true' + uses: ./.github/workflows/generate_sdk_ref.yml + secrets: inherit + report-failure: needs: [python-tests, js-tests, release] if: failure()