Skip to content

Commit 0f4c2da

Browse files
add pychangeset to project for version management (#115)
* create pr for version bump gh bot * add python-semantic-release config to pyproject.toml * track version variables with psr instead of bumpversion * set major_on_zero to false for now read more https://python-semantic-release.readthedocs.io/en/latest/configuration/configuration.html#allow-zero-version * fix semantic-release configs - allow_zero_version since we've been on 0.x.y - removed deprecated changelog_file field - add build command * add excluded conventional commit patterns * format changelog as .rst * fix toml formatting * add python-semantic-release github action sets up build deps, lints, prevents releases from racing, automatically updates release variables, publishes releases to github and tags them. TODO: pypi distribution * fix package version variable to match pyproject version * add changeset scripts and github action this is inspired by [changesets](https://github.com/changesets/changesets). it's intended to recreate the ux of them with some simple scripts * add testing script for the changesets tool * revert python-semantic-release related changes This reverts commit e35223b. * remove bumpversion * deprecate old publish workflow * copy in workflows from pychangeset * add pychangeset to repo * change version variable to single source from pyproject.toml * ruff fix --------- Co-authored-by: Roaring <[email protected]>
1 parent 93c16e3 commit 0f4c2da

File tree

12 files changed

+330
-157
lines changed

12 files changed

+330
-157
lines changed

.bumpversion.cfg

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

.changeset/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changesets
2+
3+
This directory contains changeset files that track changes.
4+
5+
## Creating a changeset
6+
7+
Run `changeset` or `changeset add` to create a new changeset.
8+
9+
## More info
10+
11+
See https://github.com/browserbase/pychangeset for more information.

.changeset/config.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"changeTypes": {
3+
"major": {
4+
"description": "Breaking changes",
5+
"emoji": "\ud83d\udca5"
6+
},
7+
"minor": {
8+
"description": "New features",
9+
"emoji": "\u2728"
10+
},
11+
"patch": {
12+
"description": "Bug fixes and improvements",
13+
"emoji": "\ud83d\udc1b"
14+
}
15+
},
16+
"baseBranch": "main"
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stagehand": patch
3+
---
4+
5+
start using pychangeset to track changes

.github/workflows/changesets.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Changesets
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
changesets:
11+
name: Create or Update Release PR
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
17+
steps:
18+
- name: Checkout main branch
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.13"
28+
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v2
31+
32+
- name: Check for changesets
33+
id: check_changesets
34+
run: |
35+
if ls .changeset/*.md 2>/dev/null | grep -v README.md > /dev/null; then
36+
echo "has_changesets=true" >> $GITHUB_OUTPUT
37+
else
38+
echo "has_changesets=false" >> $GITHUB_OUTPUT
39+
fi
40+
41+
- name: Get PR metadata
42+
if: steps.check_changesets.outputs.has_changesets == 'true'
43+
id: pr_metadata
44+
run: |
45+
# Get the merge commit info
46+
COMMIT_SHA="${{ github.sha }}"
47+
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
48+
49+
# Try to extract PR info from commit message
50+
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '(?<=#)\d+' | head -1 || echo "")
51+
if [ -n "$PR_NUMBER" ]; then
52+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
53+
54+
# Get PR author using GitHub API
55+
PR_AUTHOR=$(gh api repos/${{ github.repository }}/pulls/$PR_NUMBER --jq '.user.login' || echo "")
56+
echo "PR_AUTHOR=$PR_AUTHOR" >> $GITHUB_ENV
57+
fi
58+
env:
59+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Generate changelogs and PR description
62+
if: steps.check_changesets.outputs.has_changesets == 'true'
63+
run: |
64+
# Generate changelogs and PR description
65+
uvx changeset changelog --output-pr-description pr-description.md
66+
67+
# Save PR description for later use
68+
echo "PR_DESCRIPTION<<EOF" >> $GITHUB_ENV
69+
cat pr-description.md >> $GITHUB_ENV
70+
echo "EOF" >> $GITHUB_ENV
71+
rm pr-description.md
72+
73+
- name: Bump versions
74+
if: steps.check_changesets.outputs.has_changesets == 'true'
75+
run: |
76+
uvx changeset version --skip-changelog
77+
78+
- name: Commit changes
79+
if: steps.check_changesets.outputs.has_changesets == 'true'
80+
id: commit
81+
run: |
82+
git config user.name "github-actions[bot]"
83+
git config user.email "github-actions[bot]@users.noreply.github.com"
84+
85+
# Add all changes
86+
git add .
87+
88+
# Commit if there are changes
89+
if ! git diff --cached --quiet; then
90+
git commit -m "Version packages and update changelogs"
91+
echo "has_changes=true" >> $GITHUB_OUTPUT
92+
else
93+
echo "has_changes=false" >> $GITHUB_OUTPUT
94+
fi
95+
96+
- name: Force push to changeset branch
97+
if: steps.check_changesets.outputs.has_changesets == 'true' && steps.commit.outputs.has_changes == 'true'
98+
run: |
99+
# Force push to the changeset-release branch
100+
git push origin HEAD:changeset-release --force
101+
102+
- name: Create or update PR
103+
if: steps.check_changesets.outputs.has_changesets == 'true' && steps.commit.outputs.has_changes == 'true'
104+
uses: actions/github-script@v7
105+
with:
106+
script: |
107+
const { data: prs } = await github.rest.pulls.list({
108+
owner: context.repo.owner,
109+
repo: context.repo.repo,
110+
head: `${context.repo.owner}:changeset-release`,
111+
base: 'main',
112+
state: 'open'
113+
});
114+
115+
const prBody = process.env.PR_DESCRIPTION;
116+
const prTitle = '🚀 Release packages';
117+
118+
if (prs.length > 0) {
119+
// Update existing PR
120+
const pr = prs[0];
121+
await github.rest.pulls.update({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
pull_number: pr.number,
125+
title: prTitle,
126+
body: prBody
127+
});
128+
console.log(`Updated PR #${pr.number}`);
129+
} else {
130+
// Create new PR
131+
const { data: pr } = await github.rest.pulls.create({
132+
owner: context.repo.owner,
133+
repo: context.repo.repo,
134+
title: prTitle,
135+
body: prBody,
136+
head: 'changeset-release',
137+
base: 'main'
138+
});
139+
console.log(`Created PR #${pr.number}`);
140+
}

.github/workflows/check-changeset.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Check Changeset
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
check-changeset:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.13"
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v2
23+
24+
- name: Check for changeset
25+
run: |
26+
uvx changeset check-changeset

.github/workflows/publish.yml

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

0 commit comments

Comments
 (0)