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