add testing script for the changesets tool #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Changesets | ||
on: | ||
push: | ||
branches: | ||
- main | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
jobs: | ||
version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install click toml gitpython | ||
- name: Check for changesets | ||
id: changesets | ||
run: | | ||
if ls .changeset/*.md 2>/dev/null | grep -v README.md > /dev/null; then | ||
echo "has_changesets=true" >> $GITHUB_OUTPUT | ||
echo "Found changesets to process" | ||
else | ||
echo "has_changesets=false" >> $GITHUB_OUTPUT | ||
echo "No changesets found" | ||
fi | ||
- name: Create or Update Release PR | ||
if: steps.changesets.outputs.has_changesets == 'true' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Configure git | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
# Check if release PR already exists | ||
EXISTING_PR=$(gh pr list --state open --label "changeset-release" --json number --jq '.[0].number' || echo "") | ||
if [ -n "$EXISTING_PR" ]; then | ||
echo "Existing release PR found: #$EXISTING_PR" | ||
BRANCH_NAME=$(gh pr view $EXISTING_PR --json headRefName --jq '.headRefName') | ||
# Checkout existing branch | ||
git fetch origin $BRANCH_NAME | ||
git checkout $BRANCH_NAME | ||
git merge main --no-edit | ||
else | ||
echo "Creating new release branch" | ||
BRANCH_NAME="changeset-release/next" | ||
git checkout -b $BRANCH_NAME | ||
fi | ||
# Run version script | ||
python .changeset/scripts/version.py | ||
# Run changelog script | ||
python .changeset/scripts/changelog.py | ||
# Get the new version | ||
NEW_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") | ||
# Commit changes | ||
git add -A | ||
git commit -m "Version packages to v${NEW_VERSION}" || echo "No changes to commit" | ||
# Push branch | ||
git push origin $BRANCH_NAME --force | ||
# Create or update PR | ||
if [ -n "$EXISTING_PR" ]; then | ||
echo "Updating existing PR #$EXISTING_PR" | ||
gh pr edit $EXISTING_PR \ | ||
--title "Version Packages (v${NEW_VERSION})" \ | ||
--body "$(cat <<EOF | ||
This PR was opened by the Changesets GitHub action. When you're ready to do a release, merge this PR and the packages will be published to PyPI automatically. | ||
## Changes | ||
This PR includes changesets to release the following: | ||
- \`stagehand\` to \`${NEW_VERSION}\` | ||
If you're not ready to do a release yet, that's fine - whenever you add more changesets to main, this PR will be updated. | ||
## Releases | ||
When this PR is merged, a GitHub release will be created and the package will be published to PyPI. | ||
EOF | ||
)" | ||
else | ||
echo "Creating new PR" | ||
gh pr create \ | ||
--title "Version Packages (v${NEW_VERSION})" \ | ||
--body "$(cat <<EOF | ||
This PR was opened by the Changesets GitHub action. When you're ready to do a release, merge this PR and the packages will be published to PyPI automatically. | ||
## Changes | ||
This PR includes changesets to release the following: | ||
- \`stagehand\` to \`${NEW_VERSION}\` | ||
If you're not ready to do a release yet, that's fine - whenever you add more changesets to main, this PR will be updated. | ||
## Releases | ||
When this PR is merged, a GitHub release will be created and the package will be published to PyPI. | ||
EOF | ||
)" \ | ||
--base main \ | ||
--head $BRANCH_NAME \ | ||
--label "changeset-release" | ||
fi |