diff --git a/.github/workflows/align_pyproject_version.yaml b/.github/workflows/align_pyproject_version.yaml deleted file mode 100644 index 77a5b9b5..00000000 --- a/.github/workflows/align_pyproject_version.yaml +++ /dev/null @@ -1,91 +0,0 @@ -name: Align pyproject.toml version - -on: - workflow_run: - workflows: - - "Generate MISTRALAI" - - "Generate MISTRAL-PYTHON-SDK-AZURE" - - "Generate MISTRAL-PYTHON-SDK-GOOGLE-CLOUD" - types: [completed] - -permissions: - contents: write - -jobs: - align-version: - if: github.event.workflow_run.conclusion == 'success' - runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ github.token }} - BRANCH: ${{ github.event.workflow_run.head_branch }} - REPO: ${{ github.repository }} - steps: - - name: Align SDK versions - run: | - set -euo pipefail - - align_version() { - local gen_lock_path="$1" - local pyproject_path="$2" - local sdk_name="$3" - - echo "::group::Aligning $sdk_name" - - # Fetch gen.lock from PR branch via API - if ! GEN_LOCK=$(gh api "repos/$REPO/contents/$gen_lock_path?ref=$BRANCH" --jq '.content' 2>/dev/null | base64 -d); then - echo "No gen.lock found at $gen_lock_path, skipping" - echo "::endgroup::" - return 0 - fi - - VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"') - if [ -z "$VERSION" ]; then - echo "No releaseVersion found in $gen_lock_path" - echo "::endgroup::" - return 0 - fi - echo "Found version: $VERSION" - - # Fetch current pyproject.toml - if ! PYPROJECT_RESPONSE=$(gh api "repos/$REPO/contents/$pyproject_path?ref=$BRANCH" 2>/dev/null); then - echo "Failed to fetch $pyproject_path" - echo "::endgroup::" - return 1 - fi - - CURRENT_SHA=$(echo "$PYPROJECT_RESPONSE" | jq -r '.sha') - PYPROJECT=$(echo "$PYPROJECT_RESPONSE" | jq -r '.content' | base64 -d) - - # Update version in pyproject.toml - UPDATED=$(echo "$PYPROJECT" | sed "s/^version = \".*\"/version = \"$VERSION\"/") - - if [ "$PYPROJECT" = "$UPDATED" ]; then - echo "Version already aligned to $VERSION" - echo "::endgroup::" - return 0 - fi - - # Commit updated file via API - ENCODED=$(echo "$UPDATED" | base64 -w 0) - if ! gh api "repos/$REPO/contents/$pyproject_path" \ - -X PUT \ - -f message="chore: align $sdk_name pyproject.toml version with gen.lock" \ - -f content="$ENCODED" \ - -f sha="$CURRENT_SHA" \ - -f branch="$BRANCH" > /dev/null; then - echo "Failed to commit $pyproject_path (may have been updated by another job)" - echo "::endgroup::" - return 1 - fi - - echo "Updated $pyproject_path to version $VERSION" - echo "::endgroup::" - } - - # Align all SDKs (continue on failure to attempt all) - EXIT_CODE=0 - align_version ".speakeasy/gen.lock" "pyproject.toml" "main SDK" || EXIT_CODE=$? - align_version "packages/azure/.speakeasy/gen.lock" "packages/azure/pyproject.toml" "Azure SDK" || EXIT_CODE=$? - align_version "packages/gcp/.speakeasy/gen.lock" "packages/gcp/pyproject.toml" "GCP SDK" || EXIT_CODE=$? - - exit $EXIT_CODE diff --git a/.github/workflows/sdk_generation_mistralai_azure_sdk.yaml b/.github/workflows/sdk_generation_mistralai_azure_sdk.yaml index 22af64aa..b4c2e908 100644 --- a/.github/workflows/sdk_generation_mistralai_azure_sdk.yaml +++ b/.github/workflows/sdk_generation_mistralai_azure_sdk.yaml @@ -27,3 +27,61 @@ jobs: github_access_token: ${{ secrets.GITHUB_TOKEN }} pypi_token: ${{ secrets.PYPI_TOKEN }} speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }} + + align-version: + needs: generate + runs-on: ubuntu-latest + steps: + - name: Align pyproject.toml version with gen.lock + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + + # Find the most recent PR created by github-actions bot + PR_BRANCH=$(gh pr list --repo "$REPO" --author "app/github-actions" \ + --json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty') + + if [ -z "$PR_BRANCH" ]; then + echo "No PR found from github-actions bot, skipping" + exit 0 + fi + echo "Found PR branch: $PR_BRANCH" + + # Fetch gen.lock from PR branch + if ! GEN_LOCK=$(gh api "repos/$REPO/contents/packages/azure/.speakeasy/gen.lock?ref=$PR_BRANCH" --jq '.content' 2>/dev/null | base64 -d); then + echo "No gen.lock found, skipping" + exit 0 + fi + + VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"') + if [ -z "$VERSION" ]; then + echo "No releaseVersion found in gen.lock" + exit 0 + fi + echo "Found version: $VERSION" + + # Fetch current pyproject.toml + PYPROJECT_RESPONSE=$(gh api "repos/$REPO/contents/packages/azure/pyproject.toml?ref=$PR_BRANCH") + CURRENT_SHA=$(echo "$PYPROJECT_RESPONSE" | jq -r '.sha') + PYPROJECT=$(echo "$PYPROJECT_RESPONSE" | jq -r '.content' | base64 -d) + + # Update version + UPDATED=$(echo "$PYPROJECT" | sed "s/^version = \".*\"/version = \"$VERSION\"/") + + if [ "$PYPROJECT" = "$UPDATED" ]; then + echo "Version already aligned to $VERSION" + exit 0 + fi + + # Commit updated file + ENCODED=$(echo "$UPDATED" | base64 -w 0) + gh api "repos/$REPO/contents/packages/azure/pyproject.toml" \ + -X PUT \ + -f message="chore: align Azure pyproject.toml version to $VERSION" \ + -f content="$ENCODED" \ + -f sha="$CURRENT_SHA" \ + -f branch="$PR_BRANCH" + + echo "Updated packages/azure/pyproject.toml to version $VERSION" diff --git a/.github/workflows/sdk_generation_mistralai_gcp_sdk.yaml b/.github/workflows/sdk_generation_mistralai_gcp_sdk.yaml index bf1d19b1..5a6cbe71 100644 --- a/.github/workflows/sdk_generation_mistralai_gcp_sdk.yaml +++ b/.github/workflows/sdk_generation_mistralai_gcp_sdk.yaml @@ -27,3 +27,61 @@ jobs: github_access_token: ${{ secrets.GITHUB_TOKEN }} pypi_token: ${{ secrets.PYPI_TOKEN }} speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }} + + align-version: + needs: generate + runs-on: ubuntu-latest + steps: + - name: Align pyproject.toml version with gen.lock + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + + # Find the most recent PR created by github-actions bot + PR_BRANCH=$(gh pr list --repo "$REPO" --author "app/github-actions" \ + --json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty') + + if [ -z "$PR_BRANCH" ]; then + echo "No PR found from github-actions bot, skipping" + exit 0 + fi + echo "Found PR branch: $PR_BRANCH" + + # Fetch gen.lock from PR branch + if ! GEN_LOCK=$(gh api "repos/$REPO/contents/packages/gcp/.speakeasy/gen.lock?ref=$PR_BRANCH" --jq '.content' 2>/dev/null | base64 -d); then + echo "No gen.lock found, skipping" + exit 0 + fi + + VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"') + if [ -z "$VERSION" ]; then + echo "No releaseVersion found in gen.lock" + exit 0 + fi + echo "Found version: $VERSION" + + # Fetch current pyproject.toml + PYPROJECT_RESPONSE=$(gh api "repos/$REPO/contents/packages/gcp/pyproject.toml?ref=$PR_BRANCH") + CURRENT_SHA=$(echo "$PYPROJECT_RESPONSE" | jq -r '.sha') + PYPROJECT=$(echo "$PYPROJECT_RESPONSE" | jq -r '.content' | base64 -d) + + # Update version + UPDATED=$(echo "$PYPROJECT" | sed "s/^version = \".*\"/version = \"$VERSION\"/") + + if [ "$PYPROJECT" = "$UPDATED" ]; then + echo "Version already aligned to $VERSION" + exit 0 + fi + + # Commit updated file + ENCODED=$(echo "$UPDATED" | base64 -w 0) + gh api "repos/$REPO/contents/packages/gcp/pyproject.toml" \ + -X PUT \ + -f message="chore: align GCP pyproject.toml version to $VERSION" \ + -f content="$ENCODED" \ + -f sha="$CURRENT_SHA" \ + -f branch="$PR_BRANCH" + + echo "Updated packages/gcp/pyproject.toml to version $VERSION" diff --git a/.github/workflows/sdk_generation_mistralai_sdk.yaml b/.github/workflows/sdk_generation_mistralai_sdk.yaml index cbe8f1e8..37b8a523 100644 --- a/.github/workflows/sdk_generation_mistralai_sdk.yaml +++ b/.github/workflows/sdk_generation_mistralai_sdk.yaml @@ -27,3 +27,61 @@ jobs: github_access_token: ${{ secrets.GITHUB_TOKEN }} pypi_token: ${{ secrets.PYPI_TOKEN }} speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }} + + align-version: + needs: generate + runs-on: ubuntu-latest + steps: + - name: Align pyproject.toml version with gen.lock + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + + # Find the most recent PR created by github-actions bot + PR_BRANCH=$(gh pr list --repo "$REPO" --author "app/github-actions" \ + --json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty') + + if [ -z "$PR_BRANCH" ]; then + echo "No PR found from github-actions bot, skipping" + exit 0 + fi + echo "Found PR branch: $PR_BRANCH" + + # Fetch gen.lock from PR branch + if ! GEN_LOCK=$(gh api "repos/$REPO/contents/.speakeasy/gen.lock?ref=$PR_BRANCH" --jq '.content' 2>/dev/null | base64 -d); then + echo "No gen.lock found, skipping" + exit 0 + fi + + VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"') + if [ -z "$VERSION" ]; then + echo "No releaseVersion found in gen.lock" + exit 0 + fi + echo "Found version: $VERSION" + + # Fetch current pyproject.toml + PYPROJECT_RESPONSE=$(gh api "repos/$REPO/contents/pyproject.toml?ref=$PR_BRANCH") + CURRENT_SHA=$(echo "$PYPROJECT_RESPONSE" | jq -r '.sha') + PYPROJECT=$(echo "$PYPROJECT_RESPONSE" | jq -r '.content' | base64 -d) + + # Update version + UPDATED=$(echo "$PYPROJECT" | sed "s/^version = \".*\"/version = \"$VERSION\"/") + + if [ "$PYPROJECT" = "$UPDATED" ]; then + echo "Version already aligned to $VERSION" + exit 0 + fi + + # Commit updated file + ENCODED=$(echo "$UPDATED" | base64 -w 0) + gh api "repos/$REPO/contents/pyproject.toml" \ + -X PUT \ + -f message="chore: align pyproject.toml version to $VERSION" \ + -f content="$ENCODED" \ + -f sha="$CURRENT_SHA" \ + -f branch="$PR_BRANCH" + + echo "Updated pyproject.toml to version $VERSION"