Skip to content

Commit 875ed89

Browse files
feat: Add action to run toxgen periodically (#4805)
### Description Run `scripts/generate-test-files.sh` in a GitHub action every Monday morning and create a PR with the changes. If there are already any toxgen PRs open, close them. Here's an example run of the action: https://github.com/sentrivana/sentry-python/actions/runs/17768312844 (from a fork of the repo so that I can test it) And an example PR: sentrivana#6 Action shamelessly stolen and adapted from sentry-cli. 🥔 #### Issues Closes #4050 #### Reminders - Please add tests to validate your changes, and lint your code using `tox -e linters`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](../CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr) --------- Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
1 parent 7a90508 commit 875ed89

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

.github/workflows/update-tox.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Update test matrix
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# early Monday morning
7+
- cron: '23 3 * * 1'
8+
9+
jobs:
10+
update-tox:
11+
name: Update test matrix
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 10
14+
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
steps:
20+
- name: Setup Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: 3.13
24+
25+
- name: Checkout repo
26+
uses: actions/checkout@v5.0.0
27+
with:
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Configure git
31+
run: |
32+
git config user.name 'github-actions[bot]'
33+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
34+
35+
- name: Run generate-test-files.sh
36+
run: |
37+
set -e
38+
sh scripts/generate-test-files.sh
39+
40+
- name: Create branch
41+
id: create-branch
42+
run: |
43+
COMMIT_TITLE="ci: 🤖 Update test matrix with new releases"
44+
DATE=`date +%m/%d`
45+
BRANCH_NAME="toxgen/update"
46+
47+
git checkout -B "$BRANCH_NAME"
48+
git add --all
49+
git commit -m "$COMMIT_TITLE"
50+
git push origin "$BRANCH_NAME" --force
51+
52+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
53+
echo "commit_title=$COMMIT_TITLE" >> $GITHUB_OUTPUT
54+
echo "date=$DATE" >> $GITHUB_OUTPUT
55+
56+
- name: Create pull request
57+
uses: actions/github-script@v8.0.0
58+
with:
59+
script: |
60+
const branchName = '${{ steps.create-branch.outputs.branch_name }}';
61+
const commitTitle = '${{ steps.create-branch.outputs.commit_title }}';
62+
const date = '${{ steps.create-branch.outputs.date }}';
63+
const prBody = `Update our test matrix with new releases of integrated frameworks and libraries.
64+
65+
## How it works
66+
- Scan PyPI for all supported releases of all frameworks we have a dedicated test suite for.
67+
- Pick a representative sample of releases to run our test suite against. We always test the latest and oldest supported version.
68+
- Update [tox.ini](tox.ini) with the new releases.
69+
70+
## Action required
71+
- If CI passes on this PR, it's safe to approve and merge. It means our integrations can handle new versions of frameworks that got pulled in.
72+
- If CI doesn't pass on this PR, this points to an incompatibility of either our integration or our test setup with a new version of a framework.
73+
- Check what the failures look like and either fix them, or update the [test config](scripts/populate_tox/config.py) and rerun [scripts/generate-test-files.sh](scripts/generate-test-files.sh). See [README.md](scripts/populate_tox/README.md) for what configuration options are available.
74+
75+
_____________________
76+
77+
_🤖 This PR was automatically created using [a GitHub action](.github/workflows/update-tox.yml)._`.replace(/^ {16}/gm, '')
78+
79+
// Close existing toxgen PRs as they're now obsolete
80+
81+
const { data: existingPRs } = await github.rest.pulls.list({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
head: `${context.repo.owner}:${branchName}`,
85+
state: 'open'
86+
});
87+
88+
for (const pr of existingPRs) {
89+
await github.rest.pulls.update({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
pull_number: pr.number,
93+
state: 'closed'
94+
})
95+
};
96+
97+
const { data: pr } = await github.rest.pulls.create({
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
title: commitTitle + ' (' + date + ')',
101+
head: branchName,
102+
base: '${{ github.ref_name }}',
103+
body: prBody,
104+
});
105+
106+
await github.rest.issues.addLabels({
107+
owner: context.repo.owner,
108+
repo: context.repo.repo,
109+
issue_number: pr.number,
110+
labels: ['Component: CI', 'Component: Tests']
111+
});

0 commit comments

Comments
 (0)