Skip to content

Commit 3cd9973

Browse files
Fix/ci workflow (#3)
* feat: add default branch protection rules * ci: add "test" as a separate job to confirm test-uv/test-pixi are done
1 parent 809ded1 commit 3cd9973

File tree

12 files changed

+191
-14
lines changed

12 files changed

+191
-14
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
echo "use_pixi=false" >> $GITHUB_OUTPUT
6262
fi
6363
64-
# Job 3: Test Suite - UV Workflow
64+
# Job 3.1: Test Suite - UV Workflow
6565
# Traditional Python testing with uv for projects without pixi
6666
test-uv:
6767
needs: detect-test-strategy
@@ -99,7 +99,7 @@ jobs:
9999
run: |
100100
pytest -v || if [ $? -eq 5 ]; then exit 0; else exit $?; fi
101101
102-
# Job 4: Test Suite - Pixi Workflow
102+
# Job 3.2: Test Suite - Pixi Workflow
103103
# Pixi-based testing for projects using pixi.toml
104104
test-pixi:
105105
needs: detect-test-strategy
@@ -136,7 +136,28 @@ jobs:
136136
run: |
137137
pixi run -e ${{ matrix.environment }} test || if [ $? -eq 5 ]; then exit 0; else exit $?; fi
138138
139-
# Job 5: Build Verification
139+
# Job 3.3: Test Suite - Complete
140+
# Unified test status for branch protection
141+
test:
142+
if: always()
143+
needs: [detect-test-strategy, test-uv, test-pixi]
144+
runs-on: ubuntu-latest
145+
steps:
146+
- name: Check test results
147+
run: |
148+
uv_result="${{ needs.test-uv.result }}"
149+
pixi_result="${{ needs.test-pixi.result }}"
150+
# One should succeed, the other should be skipped
151+
if [ "$uv_result" == "success" ] || [ "$uv_result" == "skipped" ]; then
152+
if [ "$pixi_result" == "success" ] || [ "$pixi_result" == "skipped" ]; then
153+
echo "All tests passed!"
154+
exit 0
155+
fi
156+
fi
157+
echo "Tests failed: uv=$uv_result, pixi=$pixi_result"
158+
exit 1
159+
160+
# Job 4: Build Verification
140161
# Ensures the package can be built successfully
141162
build:
142163
runs-on: ubuntu-latest
@@ -172,5 +193,5 @@ jobs:
172193
# This ensures the package is usable after installation
173194
run: ap --help
174195

175-
# Job 6: Type Check
196+
# Job 5: Type Check
176197
# typecheck:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ ap init
8585

8686

8787
---
88-
## *Mission*
88+
## *Our Mission*
8989
> Only by making package maintenance and documentation easy can we encourage more Python developers to publish their own packages and grow the ecosystem even further.

afterpython/cli/commands/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _clean_build_directory():
7777
_check_initialized()
7878
_clean_build_directory()
7979

80-
if os.getenv("AP_MOLAB_BADGE", "0") == "1":
80+
if os.getenv("AP_MOLAB_BADGE", "1") == "1":
8181
for content_type in CONTENT_TYPES:
8282
add_molab_badge_to_jupyter_notebooks(content_type)
8383

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import click
2+
3+
4+
@click.command()
5+
def init_branch_rules():
6+
"""Create default branch protection rules for the current repository"""
7+
from afterpython.tools.branch_rules import create_default_branch_rules
8+
9+
create_default_branch_rules()

afterpython/cli/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from afterpython.cli.commands.commit import commit
2424
from afterpython.cli.commands.bump import bump
2525
from afterpython.cli.commands.release import release
26+
from afterpython.cli.commands.init_branch_rules import init_branch_rules
2627

2728

2829
@tui(command="tui", help="Open terminal UI")
@@ -70,3 +71,4 @@ def afterpython_group(ctx):
7071
afterpython_group.add_command(commit)
7172
afterpython_group.add_command(bump)
7273
afterpython_group.add_command(release)
74+
afterpython_group.add_command(init_branch_rules)

afterpython/doc/package_maintenance/ci_cd.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ Deploys your project website to GitHub Pages.
2222
### `dependabot.yml` (optional)
2323
Automatically updates GitHub Actions versions.
2424

25+
26+
---
27+
## Branch Protection Rules
28+
To create default branch protection rules:
29+
1. install GitHub CLI
30+
- on macOS: `brew install gh`
31+
- on Linux: https://github.com/cli/cli/releases
32+
- on Windows: https://cli.github.com/
33+
2. authenticate with GitHub CLI by running `gh auth login`
34+
3. run `ap init-branch-rules`, this will create **3 branch protection rules** (a ruleset named `afterpython-default`) for your `main` branch.
35+
- No Force Pushes
36+
- Prevents overwriting history on the main branch.
37+
- No Branch Deletion
38+
- Protects the main branch from being deleted.
39+
- CI Status Checks (before the branch can be updated)
40+
- Requires all configured CI checks to pass before any update (push or PR merge) is allowed.
41+
42+
You can view them in **GitHub → Settings → Rules → Rulesets**
43+
44+
2545
---
2646
## Security Scanning 🚧
2747

afterpython/doc/quickstart.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ The structure of `afterpython/` is as follows:
2424
- `afterpython/example/`
2525
- `afterpython/guide/`
2626

27+
:::{note} Default Branch Protection Rules
28+
Default branch protection rules can be created by running `ap init-branch-rules`. See [](package_maintenance/ci_cd.md#branch-protection-rules) for more details.
29+
:::
30+
31+
2732
---
2833
## Project Website
2934
A project website is basically a website that serves as the **homepage for your project**.

afterpython/doc/references/environment_variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
66
---
77
## `AP_MOLAB_BADGE`
8-
> Default: `0`. If set to `1`, automatically adds Molab badges to Jupyter notebooks.
8+
> Default: `1`. If set to `1`, automatically adds Molab badges to Jupyter notebooks.

afterpython/templates/ci-workflow-template.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
echo "use_pixi=false" >> $GITHUB_OUTPUT
6262
fi
6363
64-
# Job 3: Test Suite - UV Workflow
64+
# Job 3.1: Test Suite - UV Workflow
6565
# Traditional Python testing with uv for projects without pixi
6666
test-uv:
6767
needs: detect-test-strategy
@@ -99,7 +99,7 @@ jobs:
9999
run: |
100100
pytest -v || if [ $? -eq 5 ]; then exit 0; else exit $?; fi
101101
102-
# Job 4: Test Suite - Pixi Workflow
102+
# Job 3.2: Test Suite - Pixi Workflow
103103
# Pixi-based testing for projects using pixi.toml
104104
test-pixi:
105105
needs: detect-test-strategy
@@ -136,7 +136,28 @@ jobs:
136136
run: |
137137
pixi run -e ${{ matrix.environment }} test || if [ $? -eq 5 ]; then exit 0; else exit $?; fi
138138
139-
# Job 5: Build Verification
139+
# Job 3.3: Test Suite - Complete
140+
# Unified test status for branch protection
141+
test:
142+
if: always()
143+
needs: [detect-test-strategy, test-uv, test-pixi]
144+
runs-on: ubuntu-latest
145+
steps:
146+
- name: Check test results
147+
run: |
148+
uv_result="${{ needs.test-uv.result }}"
149+
pixi_result="${{ needs.test-pixi.result }}"
150+
# One should succeed, the other should be skipped
151+
if [ "$uv_result" == "success" ] || [ "$uv_result" == "skipped" ]; then
152+
if [ "$pixi_result" == "success" ] || [ "$pixi_result" == "skipped" ]; then
153+
echo "All tests passed!"
154+
exit 0
155+
fi
156+
fi
157+
echo "Tests failed: uv=$uv_result, pixi=$pixi_result"
158+
exit 1
159+
160+
# Job 4: Build Verification
140161
# Ensures the package can be built successfully
141162
build:
142163
runs-on: ubuntu-latest
@@ -172,5 +193,5 @@ jobs:
172193
# This ensures the package is usable after installation
173194
run: ap --help
174195

175-
# Job 6: Type Check
196+
# Job 5: Type Check
176197
# typecheck:

afterpython/tools/_git.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_github_url() -> str | None:
5858
return None
5959

6060

61-
def setup_github_auth():
61+
def is_gh_authenticated():
6262
"""Guide user through GitHub authentication."""
6363
if not has_gh():
6464
print("""
@@ -89,7 +89,6 @@ def setup_github_auth():
8989
""")
9090
return False
9191

92-
print("✓ GitHub authentication verified")
9392
return True
9493

9594

0 commit comments

Comments
 (0)