Skip to content

Commit f53457e

Browse files
ci: add dependabot.yml
1 parent 93696e5 commit f53457e

File tree

7 files changed

+110
-27
lines changed

7 files changed

+110
-27
lines changed

.github/dependabot.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Dependabot configuration for automatic dependency updates
2+
# See: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3+
4+
version: 2
5+
updates:
6+
# Update GitHub Actions versions
7+
# This keeps your workflow actions secure and up-to-date
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
# Check for updates monthly (less noisy than weekly)
12+
interval: "monthly"
13+
labels:
14+
- "dependencies"
15+
- "github-actions"
16+
# Group all GitHub Actions updates into a single PR
17+
# This reduces PR noise and makes reviewing easier
18+
groups:
19+
github-actions:
20+
patterns:
21+
- "*"
22+
# Automatically add reviewers (optional - uncomment and customize)
23+
# reviewers:
24+
# - "your-username"
25+
# Limit how many Dependabot PRs can be open at once (optional)
26+
# Default is 5, increase if you want more concurrent PRs
27+
# open-pull-requests-limit: 10
28+
#
29+
# Note: Auto-merge is configured in GitHub repo settings, not here.
30+
# Go to: Settings → General → Pull Requests → Allow auto-merge

afterpython/cli/commands/init.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def init(ctx, yes):
6363
from afterpython.tools.commitizen import init_commitizen
6464
from afterpython.tools.github_actions import (
6565
create_workflow,
66+
create_dependabot,
6667
)
6768

6869
paths = ctx.obj["paths"]
@@ -84,6 +85,9 @@ def init(ctx, yes):
8485

8586
init_website()
8687

88+
create_workflow("deploy")
89+
create_workflow("ci")
90+
8791
if yes or click.confirm(
8892
f"\nCreate .pre-commit-config.yaml in {afterpython_path}?", default=True
8993
):
@@ -100,5 +104,9 @@ def init(ctx, yes):
100104
init_commitizen()
101105
create_workflow("release")
102106

103-
create_workflow("deploy")
104-
create_workflow("ci")
107+
if yes or click.confirm(
108+
"\nCreate Dependabot configuration (.github/dependabot.yml) "
109+
"to auto-update GitHub Actions versions?",
110+
default=True,
111+
):
112+
create_dependabot()

afterpython/doc/package_maintenance/ci_cd.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ See [PyPI and GitHub Releases](./release_management.md#pypi-and-github-releases)
1919
### `deploy.yml`
2020
Deploys your project website to GitHub Pages.
2121

22+
### `dependabot.yml` (optional)
23+
Automatically updates GitHub Actions versions.
24+
2225
---
2326
## Security Scanning 🚧
2427

2528
---
2629
## Code Coverage 🚧
27-
28-
---
29-
## GitHub Dependabot 🚧

afterpython/doc/references/roadmap.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ This roadmap is tentative and subject to change
99
- AI chatbot like kapa.ai using WebLLM
1010
- full-text search engine using pagefind
1111
- incremental build, only build changed content (for `ap dev`)
12-
- github dependabot
13-
- update the versions in github workflows (e.g. `ci.yml`, not `pyproject.toml` coz `pcu` handles it already)
1412
- integrate with `git-cliff` for changelog generation
1513
- integrate with `pixi`, supports `conda install`
1614
- supports docs built by different engines? e.g. Sphix, MkDocs

afterpython/templates/ci-workflow-template.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ jobs:
9595
9696
- name: Run tests with pytest
9797
# Run pytest with verbose output
98-
# Even without tests, pytest will exit successfully (0 tests collected)
99-
run: pytest -v
98+
# Exit code 5 (no tests collected) is treated as success
99+
run: |
100+
pytest -v || if [ $? -eq 5 ]; then exit 0; else exit $?; fi
100101
101102
# Job 4: Test Suite - Pixi Workflow
102103
# Pixi-based testing for projects using pixi.toml
@@ -131,7 +132,9 @@ jobs:
131132
# py311 = ["py311", "test"]
132133
# [feature.test.tasks]
133134
# test = "pytest -v"
134-
run: pixi run -e ${{ matrix.environment }} test
135+
# Note: Exit code 5 (no tests collected) is treated as success
136+
run: |
137+
pixi run -e ${{ matrix.environment }} test || if [ $? -eq 5 ]; then exit 0; else exit $?; fi
135138
136139
# Job 5: Build Verification
137140
# Ensures the package can be built successfully
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Dependabot configuration for automatic dependency updates
2+
# See: https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3+
4+
version: 2
5+
updates:
6+
# Update GitHub Actions versions
7+
# This keeps your workflow actions secure and up-to-date
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
# Check for updates monthly (less noisy than weekly)
12+
interval: "monthly"
13+
labels:
14+
- "dependencies"
15+
- "github-actions"
16+
# Group all GitHub Actions updates into a single PR
17+
# This reduces PR noise and makes reviewing easier
18+
groups:
19+
github-actions:
20+
patterns:
21+
- "*"
22+
# Automatically add reviewers (optional - uncomment and customize)
23+
# reviewers:
24+
# - "your-username"
25+
# Limit how many Dependabot PRs can be open at once (optional)
26+
# Default is 5, increase if you want more concurrent PRs
27+
# open-pull-requests-limit: 10
28+
#
29+
# Note: Auto-merge is configured in GitHub repo settings, not here.
30+
# Go to: Settings → General → Pull Requests → Allow auto-merge
Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
11
import shutil
2+
from pathlib import Path
23

34
import click
45

56
import afterpython as ap
67

78

8-
def create_workflow(workflow_name: str):
9-
if ".yml" in workflow_name:
10-
workflow_name = workflow_name.replace(".yml", "")
11-
12-
user_path = ap.paths.user_path
13-
workflow_dir = user_path / ".github" / "workflows"
14-
workflow_path = workflow_dir / f"{workflow_name}.yml"
15-
16-
if workflow_path.exists():
17-
click.echo(
18-
f"GitHub Actions {workflow_name} workflow {workflow_path} already exists"
19-
)
9+
def _copy_github_template(template_name: str, target_path: Path):
10+
"""Helper to copy GitHub-related templates"""
11+
if target_path.exists():
12+
click.echo(f"{target_path} already exists")
2013
return
2114

22-
# Create .github/workflows directory if it doesn't exist
23-
workflow_dir.mkdir(parents=True, exist_ok=True)
15+
# Create parent directory if it doesn't exist
16+
target_path.parent.mkdir(parents=True, exist_ok=True)
2417

2518
# Copy template from package
26-
template_path = ap.paths.templates_path / f"{workflow_name}-workflow-template.yml"
19+
template_path = ap.paths.templates_path / template_name
2720
if not template_path.exists():
2821
raise FileNotFoundError(
2922
f"Template file not found: {template_path}\n"
3023
"This might indicate a corrupted installation. Please reinstall afterpython."
3124
)
3225

33-
shutil.copy(template_path, workflow_path)
34-
click.echo(f"Created {workflow_path}")
26+
shutil.copy(template_path, target_path)
27+
click.echo(f"Created {target_path}")
28+
29+
30+
def create_workflow(workflow_name: str):
31+
"""Create a GitHub Actions workflow from template"""
32+
if ".yml" in workflow_name:
33+
workflow_name = workflow_name.replace(".yml", "")
34+
35+
user_path = ap.paths.user_path
36+
workflow_path = user_path / ".github" / "workflows" / f"{workflow_name}.yml"
37+
template_name = f"{workflow_name}-workflow-template.yml"
38+
39+
_copy_github_template(template_name, workflow_path)
40+
41+
42+
def create_dependabot():
43+
"""Create Dependabot configuration for GitHub Actions updates"""
44+
user_path = ap.paths.user_path
45+
dependabot_path = user_path / ".github" / "dependabot.yml"
46+
template_name = "dependabot-template.yml"
47+
48+
_copy_github_template(template_name, dependabot_path)

0 commit comments

Comments
 (0)