Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/PROJECT_SYNC.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,19 @@ A delivery is released only when all associated implementation PRs are merged, t
- Issue and same-repository PR events reconcile the changed item and its linked items. Fork PR events are skipped; full scans include their repository-visible state.
- Scheduled runs every six hours and manual runs perform full reconciliation, including release verification. Event runs preserve an existing release result while implementation links are unchanged.
- Full scans include open issues, all PRs, tracked or linked closed issues, and items closed since Project creation. Archived items and draft issues are skipped. Preview catch-up before applying to an older Project.
- Each run validates the schema and prints its plan before writing. Runs are serialized and have a 120-minute total timeout. API errors or missing fetched tags stop the run.
- Each run validates the schema and prints its plan before writing. Runs are serialized and have a 10-minute total timeout. API errors or missing fetched tags stop the run.
- A failed apply reports confirmed, outcome-unknown, and unattempted writes. Rerun or wait for the next scheduled scan to reconcile partial changes. The Actions log shows scan progress.

Privileged runs use default-branch code and full Git history and tags. Never check out PR code or expose the Project token in PR test jobs. Keep Actions pinned to immutable commit SHAs when updating them.
Privileged runs use default-branch code and full Git history and tags. Never check out PR code or expose the Project token in PR test jobs. Both workflows reference Actions by version tag.

## Local validation

Run the offline checks without credentials:

```sh
python -I tests/test_sync_github_project.py -v
python -I tests/test_project_delivery.py -v
python -I tests/test_project_events.py -v
uv run ruff format --check scripts/sync_github_project.py tests/test_sync_github_project.py tests/test_project_delivery.py tests/test_project_events.py
uv run --no-project python -I tests/test_sync_github_project.py -v
uv run --no-project python -I tests/test_project_events.py -v
uv run ruff format --check scripts/sync_github_project.py tests/test_sync_github_project.py tests/test_project_events.py
uv run ruff check scripts/sync_github_project.py
```

Expand Down
34 changes: 12 additions & 22 deletions .github/workflows/code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@ on:
jobs:
format-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.12'

- name: Install UV
run: pip install uv

- name: Install dependencies
run: uv sync

- name: Check code formatting with ruff
run: |
uvx --from ruff==0.15.22 ruff format --check .

- name: Check code style with ruff
run: |
uvx --from ruff==0.15.22 ruff check .
- name: Checkout code
uses: actions/checkout@v7

- name: Set up uv
uses: astral-sh/setup-uv@v10.3.3

- name: Check code formatting with ruff
run: uvx ruff@0.15.22 format --check .

- name: Check code style with ruff
run: uvx ruff@0.15.22 check .
13 changes: 4 additions & 9 deletions .github/workflows/project-sync-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ on:
- '.github/workflows/project-sync*.yml'
- 'scripts/sync_github_project.py'
- 'tests/test_sync_github_project.py'
- 'tests/test_project_delivery.py'
- 'tests/test_project_events.py'
push:
branches: [master]
paths:
- '.github/workflows/project-sync*.yml'
- 'scripts/sync_github_project.py'
- 'tests/test_sync_github_project.py'
- 'tests/test_project_delivery.py'
- 'tests/test_project_events.py'
workflow_dispatch:

Expand All @@ -26,14 +24,11 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7
with:
python-version: '3.12'
- uses: astral-sh/setup-uv@v10.3.3
- name: Run network-free regression tests
run: |
python -I tests/test_sync_github_project.py -v
python -I tests/test_project_delivery.py -v
python -I tests/test_project_events.py -v
uv run --no-project python -I tests/test_sync_github_project.py -v
uv run --no-project python -I tests/test_project_events.py -v
14 changes: 6 additions & 8 deletions .github/workflows/project-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# Configure this environment to allow only the default branch before adding secrets.
environment: project-sync
runs-on: ubuntu-latest
timeout-minutes: 120
timeout-minutes: 10
steps:
- name: Validate manual branch
if: github.event_name == 'workflow_dispatch' && github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
Expand All @@ -43,7 +43,7 @@ jobs:
exit 1
# Never check out the PR head or a PR-controlled base branch with this token.
- name: Check out trusted default branch
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
uses: actions/checkout@v7
with:
ref: ${{ github.event.repository.default_branch || github.ref_name }}
persist-credentials: false
Expand All @@ -52,10 +52,8 @@ jobs:
sparse-checkout: scripts/sync_github_project.py
sparse-checkout-cone-mode: false

- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7
with:
python-version: '3.12'
- name: Set up uv
uses: astral-sh/setup-uv@v10.3.3

- name: Synchronize current item state
env:
Expand All @@ -68,7 +66,7 @@ jobs:
APPLY_CHANGES: ${{ github.event_name != 'workflow_dispatch' || inputs.apply }}
run: |
if [ "$APPLY_CHANGES" = 'true' ]; then
python -I scripts/sync_github_project.py --apply
uv run --no-project python -I scripts/sync_github_project.py --apply
else
python -I scripts/sync_github_project.py
uv run --no-project python -I scripts/sync_github_project.py
fi
10 changes: 2 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,8 @@ jobs:
unzip -q "${RUNNER_TEMP}/dashboard-artifact/AstrBot-${{ steps.tag.outputs.tag }}-dashboard.zip" -d "${RUNNER_TEMP}/dashboard-artifact/unpacked"
cp -r "${RUNNER_TEMP}/dashboard-artifact/unpacked/dist/." astrbot/dashboard/dist/

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.10"

- name: Install uv
shell: bash
run: python -m pip install uv
- name: Set up uv
uses: astral-sh/setup-uv@v10.3.3

- name: Build package
shell: bash
Expand Down
32 changes: 4 additions & 28 deletions .github/workflows/smoke_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
smoke-test:
name: Smoke test (${{ matrix.os }}, Python ${{ matrix.python-version }})
name: Smoke test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
Expand All @@ -23,37 +23,13 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
python-version:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
- '3.14'

steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: requirements.txt

- name: Install uv
run: |
python -m pip install --upgrade pip
python -m pip install uv

- name: Install dependencies
run: |
uv pip install --system -r requirements.txt
timeout-minutes: 15
- name: Set up uv
uses: astral-sh/setup-uv@v10.3.3
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved

- name: Run smoke tests
run: |
python scripts/smoke_startup_check.py
timeout-minutes: 2
run: uv run scripts/smoke_startup_check.py
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
12 changes: 2 additions & 10 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.12'

- name: Install uv
run: |
python -m pip install --upgrade pip
python -m pip install uv
- name: Set up uv
uses: astral-sh/setup-uv@v10.3.3

- name: Install Linux sandbox dependency
if: runner.os == 'Linux'
Expand All @@ -70,7 +63,6 @@ jobs:
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
chmod +x scripts/run_pytests_ci.sh
if [ "${{ runner.os }}" = "Linux" ]; then
bash ./scripts/run_pytests_ci.sh ./tests --cov=astrbot --cov-report=xml
else
Expand Down
3 changes: 0 additions & 3 deletions scripts/run_pytests_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ fi

PYTEST_TARGETS=("${@:-./tests}")

echo "[ci] syncing dependencies with uv"
uv sync --dev

echo "[ci] running tests: ${PYTEST_TARGETS[*]}"
# Some tests may leave non-daemon worker threads alive (e.g. aiosqlite warning path),
# which can block pytest process exit in CI. Run pytest via python and force process exit
Expand Down
44 changes: 0 additions & 44 deletions tests/test_sync_github_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,49 +302,5 @@ def test_schedule_uses_configured_default_branch(self):
reconcile.assert_called_once()


class WorkflowSecurityTests(unittest.TestCase):
def test_sync_job_has_120_minute_timeout(self):
workflow = (
SCRIPT.parents[1] / ".github/workflows/project-sync.yml"
).read_text()
job = workflow.split(" sync:\n", 1)[1].split(" steps:", 1)[0]
self.assertIn(" timeout-minutes: 120\n", job)

def test_fork_pull_request_events_are_filtered_at_job_boundary(self):
workflow = (
SCRIPT.parents[1] / ".github/workflows/project-sync.yml"
).read_text()
job_condition = workflow.split(" sync:\n", 1)[1].split(" environment:", 1)[
0
]
self.assertIn("github.event_name != 'pull_request_target'", job_condition)
self.assertIn(
"github.event.pull_request.head.repo.full_name == github.repository",
job_condition,
)

def test_sync_job_requires_environment_before_any_steps(self):
workflow = (
SCRIPT.parents[1] / ".github/workflows/project-sync.yml"
).read_text()
job = workflow.split(" sync:\n", 1)[1]
self.assertIn(" environment: project-sync\n", job.split(" steps:", 1)[0])
self.assertIn(
"ASTRBOT_PROJECT_TOKEN: ${{ secrets.ASTRBOT_PROJECT_ENV_TOKEN }}", job
)
self.assertNotIn("secrets.ASTRBOT_PROJECT_TOKEN", job)

def test_both_workflows_pin_all_actions_to_full_commit_ids(self):
for name in ("project-sync.yml", "project-sync-tests.yml"):
workflow = (SCRIPT.parents[1] / ".github/workflows" / name).read_text()
actions = re.findall(r"uses:\s+([^\s#]+)", workflow)
self.assertEqual(len(actions), 2)
for action in actions:
with self.subTest(workflow=name, action=action):
self.assertRegex(
action, r"^actions/(checkout|setup-python)@[0-9a-f]{40}$"
)


if __name__ == "__main__":
unittest.main()
Loading