Skip to content

Commit 176b844

Browse files
fix: align pyproject.toml version directly in generation workflows (#392)
Instead of using a separate workflow with workflow_run trigger (which runs on the wrong branch), embed the version alignment logic directly in each SDK generation workflow as a job that runs after generation. This approach works because: - Same workflow = same GITHUB_TOKEN permissions - needs: generate ensures it runs after PR is created - No trigger gymnastics or branch detection issues Deletes the standalone align_pyproject_version.yaml workflow.
1 parent ed618e8 commit 176b844

4 files changed

Lines changed: 174 additions & 91 deletions

File tree

.github/workflows/align_pyproject_version.yaml

Lines changed: 0 additions & 91 deletions
This file was deleted.

.github/workflows/sdk_generation_mistralai_azure_sdk.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,61 @@ jobs:
2727
github_access_token: ${{ secrets.GITHUB_TOKEN }}
2828
pypi_token: ${{ secrets.PYPI_TOKEN }}
2929
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
30+
31+
align-version:
32+
needs: generate
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Align pyproject.toml version with gen.lock
36+
env:
37+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
REPO: ${{ github.repository }}
39+
run: |
40+
set -euo pipefail
41+
42+
# Find the most recent PR created by github-actions bot
43+
PR_BRANCH=$(gh pr list --repo "$REPO" --author "app/github-actions" \
44+
--json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty')
45+
46+
if [ -z "$PR_BRANCH" ]; then
47+
echo "No PR found from github-actions bot, skipping"
48+
exit 0
49+
fi
50+
echo "Found PR branch: $PR_BRANCH"
51+
52+
# Fetch gen.lock from PR branch
53+
if ! GEN_LOCK=$(gh api "repos/$REPO/contents/packages/azure/.speakeasy/gen.lock?ref=$PR_BRANCH" --jq '.content' 2>/dev/null | base64 -d); then
54+
echo "No gen.lock found, skipping"
55+
exit 0
56+
fi
57+
58+
VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"')
59+
if [ -z "$VERSION" ]; then
60+
echo "No releaseVersion found in gen.lock"
61+
exit 0
62+
fi
63+
echo "Found version: $VERSION"
64+
65+
# Fetch current pyproject.toml
66+
PYPROJECT_RESPONSE=$(gh api "repos/$REPO/contents/packages/azure/pyproject.toml?ref=$PR_BRANCH")
67+
CURRENT_SHA=$(echo "$PYPROJECT_RESPONSE" | jq -r '.sha')
68+
PYPROJECT=$(echo "$PYPROJECT_RESPONSE" | jq -r '.content' | base64 -d)
69+
70+
# Update version
71+
UPDATED=$(echo "$PYPROJECT" | sed "s/^version = \".*\"/version = \"$VERSION\"/")
72+
73+
if [ "$PYPROJECT" = "$UPDATED" ]; then
74+
echo "Version already aligned to $VERSION"
75+
exit 0
76+
fi
77+
78+
# Commit updated file
79+
ENCODED=$(echo "$UPDATED" | base64 -w 0)
80+
gh api "repos/$REPO/contents/packages/azure/pyproject.toml" \
81+
-X PUT \
82+
-f message="chore: align Azure pyproject.toml version to $VERSION" \
83+
-f content="$ENCODED" \
84+
-f sha="$CURRENT_SHA" \
85+
-f branch="$PR_BRANCH"
86+
87+
echo "Updated packages/azure/pyproject.toml to version $VERSION"

.github/workflows/sdk_generation_mistralai_gcp_sdk.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,61 @@ jobs:
2727
github_access_token: ${{ secrets.GITHUB_TOKEN }}
2828
pypi_token: ${{ secrets.PYPI_TOKEN }}
2929
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
30+
31+
align-version:
32+
needs: generate
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Align pyproject.toml version with gen.lock
36+
env:
37+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
REPO: ${{ github.repository }}
39+
run: |
40+
set -euo pipefail
41+
42+
# Find the most recent PR created by github-actions bot
43+
PR_BRANCH=$(gh pr list --repo "$REPO" --author "app/github-actions" \
44+
--json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty')
45+
46+
if [ -z "$PR_BRANCH" ]; then
47+
echo "No PR found from github-actions bot, skipping"
48+
exit 0
49+
fi
50+
echo "Found PR branch: $PR_BRANCH"
51+
52+
# Fetch gen.lock from PR branch
53+
if ! GEN_LOCK=$(gh api "repos/$REPO/contents/packages/gcp/.speakeasy/gen.lock?ref=$PR_BRANCH" --jq '.content' 2>/dev/null | base64 -d); then
54+
echo "No gen.lock found, skipping"
55+
exit 0
56+
fi
57+
58+
VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"')
59+
if [ -z "$VERSION" ]; then
60+
echo "No releaseVersion found in gen.lock"
61+
exit 0
62+
fi
63+
echo "Found version: $VERSION"
64+
65+
# Fetch current pyproject.toml
66+
PYPROJECT_RESPONSE=$(gh api "repos/$REPO/contents/packages/gcp/pyproject.toml?ref=$PR_BRANCH")
67+
CURRENT_SHA=$(echo "$PYPROJECT_RESPONSE" | jq -r '.sha')
68+
PYPROJECT=$(echo "$PYPROJECT_RESPONSE" | jq -r '.content' | base64 -d)
69+
70+
# Update version
71+
UPDATED=$(echo "$PYPROJECT" | sed "s/^version = \".*\"/version = \"$VERSION\"/")
72+
73+
if [ "$PYPROJECT" = "$UPDATED" ]; then
74+
echo "Version already aligned to $VERSION"
75+
exit 0
76+
fi
77+
78+
# Commit updated file
79+
ENCODED=$(echo "$UPDATED" | base64 -w 0)
80+
gh api "repos/$REPO/contents/packages/gcp/pyproject.toml" \
81+
-X PUT \
82+
-f message="chore: align GCP pyproject.toml version to $VERSION" \
83+
-f content="$ENCODED" \
84+
-f sha="$CURRENT_SHA" \
85+
-f branch="$PR_BRANCH"
86+
87+
echo "Updated packages/gcp/pyproject.toml to version $VERSION"

.github/workflows/sdk_generation_mistralai_sdk.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,61 @@ jobs:
2727
github_access_token: ${{ secrets.GITHUB_TOKEN }}
2828
pypi_token: ${{ secrets.PYPI_TOKEN }}
2929
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
30+
31+
align-version:
32+
needs: generate
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Align pyproject.toml version with gen.lock
36+
env:
37+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
REPO: ${{ github.repository }}
39+
run: |
40+
set -euo pipefail
41+
42+
# Find the most recent PR created by github-actions bot
43+
PR_BRANCH=$(gh pr list --repo "$REPO" --author "app/github-actions" \
44+
--json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty')
45+
46+
if [ -z "$PR_BRANCH" ]; then
47+
echo "No PR found from github-actions bot, skipping"
48+
exit 0
49+
fi
50+
echo "Found PR branch: $PR_BRANCH"
51+
52+
# Fetch gen.lock from PR branch
53+
if ! GEN_LOCK=$(gh api "repos/$REPO/contents/.speakeasy/gen.lock?ref=$PR_BRANCH" --jq '.content' 2>/dev/null | base64 -d); then
54+
echo "No gen.lock found, skipping"
55+
exit 0
56+
fi
57+
58+
VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"')
59+
if [ -z "$VERSION" ]; then
60+
echo "No releaseVersion found in gen.lock"
61+
exit 0
62+
fi
63+
echo "Found version: $VERSION"
64+
65+
# Fetch current pyproject.toml
66+
PYPROJECT_RESPONSE=$(gh api "repos/$REPO/contents/pyproject.toml?ref=$PR_BRANCH")
67+
CURRENT_SHA=$(echo "$PYPROJECT_RESPONSE" | jq -r '.sha')
68+
PYPROJECT=$(echo "$PYPROJECT_RESPONSE" | jq -r '.content' | base64 -d)
69+
70+
# Update version
71+
UPDATED=$(echo "$PYPROJECT" | sed "s/^version = \".*\"/version = \"$VERSION\"/")
72+
73+
if [ "$PYPROJECT" = "$UPDATED" ]; then
74+
echo "Version already aligned to $VERSION"
75+
exit 0
76+
fi
77+
78+
# Commit updated file
79+
ENCODED=$(echo "$UPDATED" | base64 -w 0)
80+
gh api "repos/$REPO/contents/pyproject.toml" \
81+
-X PUT \
82+
-f message="chore: align pyproject.toml version to $VERSION" \
83+
-f content="$ENCODED" \
84+
-f sha="$CURRENT_SHA" \
85+
-f branch="$PR_BRANCH"
86+
87+
echo "Updated pyproject.toml to version $VERSION"

0 commit comments

Comments
 (0)