10000 Automate deployment to PYPI (#145) · random-user-pr/sdk-python1@947f6b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 947f6b6

Browse files
authored
Automate deployment to PYPI (strands-agents#145)
* feat: Deploy to pypi on release * feat: get version from tag
1 parent 73dae72 commit 947f6b6

File tree

5 files changed

+110
-13
lines changed

5 files changed

+110
-13
lines changed

.github/workflows/pr-and-push.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Pull Request and Push Action
2+
3+
on:
4+
pull_request: # Safer than pull_request_target for untrusted code
5+
branches: [ main ]
6+
types: [opened, synchronize, reopened, ready_for_review, review_requested, review_request_removed]
7+
push:
8+
branches: [ main ] # Also run on direct pushes to main
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
call-test-lint:
15+
uses: ./.github/workflows/test-lint.yml
16+
with:
17+
ref: ${{ github.event.pull_request.head.sha }}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Publish Python Package
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
call-test-lint:
10+
uses: ./.github/workflows/test-lint.yml
11+
with:
12+
ref: ${{ github.event.release.target_commitish }}
13+
14+
build:
15+
name: Build distribution 📦
16+
needs:
17+
- call-test-lint
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
persist-credentials: false
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.10'
29+
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install hatch twine
34+
35+
- name: Validate version
36+
run: |
37+
version=$(hatch version)
38+
if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
39+
echo "Valid version format"
40+
exit 0
41+
else
42+
echo "Invalid version format"
43+
exit 1
44+
fi
45+
46+
- name: Build
47+
run: |
48+
hatch build
49+
50+
- name: Store the distribution packages
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: python-package-distributions
54+
path: dist/
55+
56+
deploy:
57+
name: Upload release to PyPI
58+
needs:
59+
- build
60+
runs-on: ubuntu-latest
61+
62+
# environment is used by PyPI Trusted Publisher and is strongly encouraged
63+
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
64+
environment:
65+
name: pypi
66+
url: https://pypi.org/p/strands-agents
67+
permissions:
68+
# IMPORTANT: this permission is mandatory for Trusted Publishing
69+
id-token: write
70+
71+
steps:
72+
- name: Download all the dists
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: python-package-distributions
76+
path: dist/
77+
- name: Publish distribution 📦 to PyPI
78+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test-lint-pr.yml renamed to .github/workflows/test-lint.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
name: Test and Lint
22

33
on:
4-
pull_request: # Safer than pull_request_target for untrusted code
5-
branches: [ main ]
6-
types: [opened, synchronize, reopened, ready_for_review, review_requested, review_request_removed]
7-
push:
8-
branches: [ main ] # Also run on direct pushes to main
9-
concurrency:
10-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11-
cancel-in-progress: true
4+
workflow_call:
5+
inputs:
6+
ref:
7+
required: true
8+
type: string
129

1310
jobs:
1411
unit-test:
@@ -56,7 +53,7 @@ jobs:
5653
- name: Checkout code
5754
uses: actions/checkout@v4
5855
with:
59-
ref: ${{ github.event.pull_request.head.sha }} # Explicitly define which commit to check out
56+
ref: ${{ inputs.ref }} # Explicitly define which commit to check out
6057
persist-credentials: false # Don't persist credentials for subsequent actions
6158
- name: Set up Python
6259
uses: actions/setup-python@v5
@@ -78,7 +75,7 @@ jobs:
7875
- name: Checkout code
7976
uses: actions/checkout@v4
8077
with:
81-
ref: ${{ github.event.pull_request.head.sha }}
78+
ref: ${{ inputs.ref }}
8279
persist-credentials: false
8380

8481
- name: Set up Python

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ __pycache__*
77
.pytest_cache
88
.ruff_cache
99
*.bak
10-
.vscode
10+
.vscode
11+
dist

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = ["hatchling", "hatch-vcs"]
33
build-backend = "hatchling.build"
44

55
[project]
66
name = "strands-agents"
7-
version = "0.1.5"
7+
dynamic = ["version"]
88
description = "A model-driven approach to building AI agents in just a few lines of code"
99
readme = "README.md"
1010
requires-python = ">=3.10"
@@ -79,6 +79,10 @@ openai = [
7979
"openai>=1.68.0,<2.0.0",
8080
]
8181

82+
[tool.hatch.version]
83+
# Tells Hatch to use your version control system (git) to determine the version.
84+
source = "vcs"
85+
8286
[tool.hatch.envs.hatch-static-analysis]
8387
features = ["anthropic", "litellm", "llamaapi", "ollama", "openai"]
8488
dependencies = [

0 commit comments

Comments
 (0)
0