Skip to content

Commit d571d59

Browse files
fix: use checkout + uv version to also update uv.lock
The API-only approach only updated pyproject.toml but not uv.lock. This version: - Checks out the PR branch (safe for workflow_dispatch context) - Uses `uv version` to update both pyproject.toml and uv.lock - Commits and pushes the changes Security note: checkout is safe here because: - workflow_dispatch trigger (not pull_request_target) - Branch is in same repo, not a fork - Branch was just created by Speakeasy in the same workflow run
1 parent 176b844 commit d571d59

3 files changed

Lines changed: 105 additions & 105 deletions

File tree

‎.github/workflows/sdk_generation_mistralai_azure_sdk.yaml‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,56 +32,56 @@ jobs:
3232
needs: generate
3333
runs-on: ubuntu-latest
3434
steps:
35-
- name: Align pyproject.toml version with gen.lock
35+
- name: Find PR branch
36+
id: find-pr
3637
env:
3738
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
REPO: ${{ github.repository }}
3939
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" \
40+
PR_BRANCH=$(gh pr list --repo ${{ github.repository }} --author "app/github-actions" \
4441
--json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty')
42+
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
4543
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"
44+
- name: Checkout PR branch
45+
if: steps.find-pr.outputs.branch != ''
46+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
47+
with:
48+
ref: ${{ steps.find-pr.outputs.branch }}
5149

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
50+
- name: Install uv
51+
if: steps.find-pr.outputs.branch != ''
52+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
5753

58-
VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"')
54+
- name: Align version using uv
55+
if: steps.find-pr.outputs.branch != ''
56+
run: |
57+
set -euo pipefail
58+
59+
VERSION=$(grep 'releaseVersion:' packages/azure/.speakeasy/gen.lock | head -1 | awk '{print $2}' | tr -d '"')
5960
if [ -z "$VERSION" ]; then
6061
echo "No releaseVersion found in gen.lock"
6162
exit 0
6263
fi
6364
echo "Found version: $VERSION"
6465
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
66+
CURRENT=$(grep '^version = ' packages/azure/pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
67+
if [ "$CURRENT" = "$VERSION" ]; then
7468
echo "Version already aligned to $VERSION"
7569
exit 0
7670
fi
7771
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"
72+
echo "Updating version from $CURRENT to $VERSION"
73+
uv version "$VERSION" --directory packages/azure
8674
87-
echo "Updated packages/azure/pyproject.toml to version $VERSION"
75+
- name: Commit and push
76+
if: steps.find-pr.outputs.branch != ''
77+
run: |
78+
git config user.email "action@github.com"
79+
git config user.name "GitHub Action"
80+
git add packages/azure/pyproject.toml packages/azure/uv.lock
81+
if git diff --cached --quiet; then
82+
echo "No changes to commit"
83+
else
84+
VERSION=$(grep '^version = ' packages/azure/pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
85+
git commit -m "chore: align Azure pyproject.toml and uv.lock to version $VERSION"
86+
git push
87+
fi

‎.github/workflows/sdk_generation_mistralai_gcp_sdk.yaml‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,56 +32,56 @@ jobs:
3232
needs: generate
3333
runs-on: ubuntu-latest
3434
steps:
35-
- name: Align pyproject.toml version with gen.lock
35+
- name: Find PR branch
36+
id: find-pr
3637
env:
3738
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
REPO: ${{ github.repository }}
3939
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" \
40+
PR_BRANCH=$(gh pr list --repo ${{ github.repository }} --author "app/github-actions" \
4441
--json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty')
42+
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
4543
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"
44+
- name: Checkout PR branch
45+
if: steps.find-pr.outputs.branch != ''
46+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
47+
with:
48+
ref: ${{ steps.find-pr.outputs.branch }}
5149

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
50+
- name: Install uv
51+
if: steps.find-pr.outputs.branch != ''
52+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
5753

58-
VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"')
54+
- name: Align version using uv
55+
if: steps.find-pr.outputs.branch != ''
56+
run: |
57+
set -euo pipefail
58+
59+
VERSION=$(grep 'releaseVersion:' packages/gcp/.speakeasy/gen.lock | head -1 | awk '{print $2}' | tr -d '"')
5960
if [ -z "$VERSION" ]; then
6061
echo "No releaseVersion found in gen.lock"
6162
exit 0
6263
fi
6364
echo "Found version: $VERSION"
6465
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
66+
CURRENT=$(grep '^version = ' packages/gcp/pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
67+
if [ "$CURRENT" = "$VERSION" ]; then
7468
echo "Version already aligned to $VERSION"
7569
exit 0
7670
fi
7771
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"
72+
echo "Updating version from $CURRENT to $VERSION"
73+
uv version "$VERSION" --directory packages/gcp
8674
87-
echo "Updated packages/gcp/pyproject.toml to version $VERSION"
75+
- name: Commit and push
76+
if: steps.find-pr.outputs.branch != ''
77+
run: |
78+
git config user.email "action@github.com"
79+
git config user.name "GitHub Action"
80+
git add packages/gcp/pyproject.toml packages/gcp/uv.lock
81+
if git diff --cached --quiet; then
82+
echo "No changes to commit"
83+
else
84+
VERSION=$(grep '^version = ' packages/gcp/pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
85+
git commit -m "chore: align GCP pyproject.toml and uv.lock to version $VERSION"
86+
git push
87+
fi

‎.github/workflows/sdk_generation_mistralai_sdk.yaml‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,56 +32,56 @@ jobs:
3232
needs: generate
3333
runs-on: ubuntu-latest
3434
steps:
35-
- name: Align pyproject.toml version with gen.lock
35+
- name: Find PR branch
36+
id: find-pr
3637
env:
3738
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
REPO: ${{ github.repository }}
3939
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" \
40+
PR_BRANCH=$(gh pr list --repo ${{ github.repository }} --author "app/github-actions" \
4441
--json headRefName,updatedAt --jq 'sort_by(.updatedAt) | reverse | .[0].headRefName // empty')
42+
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
4543
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"
44+
- name: Checkout PR branch
45+
if: steps.find-pr.outputs.branch != ''
46+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
47+
with:
48+
ref: ${{ steps.find-pr.outputs.branch }}
5149

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
50+
- name: Install uv
51+
if: steps.find-pr.outputs.branch != ''
52+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
5753

58-
VERSION=$(echo "$GEN_LOCK" | grep 'releaseVersion:' | head -1 | awk '{print $2}' | tr -d '"')
54+
- name: Align version using uv
55+
if: steps.find-pr.outputs.branch != ''
56+
run: |
57+
set -euo pipefail
58+
59+
VERSION=$(grep 'releaseVersion:' .speakeasy/gen.lock | head -1 | awk '{print $2}' | tr -d '"')
5960
if [ -z "$VERSION" ]; then
6061
echo "No releaseVersion found in gen.lock"
6162
exit 0
6263
fi
6364
echo "Found version: $VERSION"
6465
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
66+
CURRENT=$(grep '^version = ' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
67+
if [ "$CURRENT" = "$VERSION" ]; then
7468
echo "Version already aligned to $VERSION"
7569
exit 0
7670
fi
7771
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"
72+
echo "Updating version from $CURRENT to $VERSION"
73+
uv version "$VERSION"
8674
87-
echo "Updated pyproject.toml to version $VERSION"
75+
- name: Commit and push
76+
if: steps.find-pr.outputs.branch != ''
77+
run: |
78+
git config user.email "action@github.com"
79+
git config user.name "GitHub Action"
80+
git add pyproject.toml uv.lock
81+
if git diff --cached --quiet; then
82+
echo "No changes to commit"
83+
else
84+
VERSION=$(grep '^version = ' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
85+
git commit -m "chore: align pyproject.toml and uv.lock to version $VERSION"
86+
git push
87+
fi

0 commit comments

Comments
 (0)