Skip to content

Commit 8a3b8ad

Browse files
feat: add deployment workflow for github actions
1 parent 963be3d commit 8a3b8ad

File tree

15 files changed

+307
-2
lines changed

15 files changed

+307
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Deploy Project Website to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main # Deploy when pushing to main branch
7+
paths:
8+
# Trigger deployment only when content or website files change
9+
- 'afterpython/doc/**'
10+
- 'afterpython/blog/**'
11+
- 'afterpython/tutorial/**'
12+
- 'afterpython/example/**'
13+
- 'afterpython/guide/**'
14+
- 'afterpython/static/**'
15+
- 'afterpython/_website/**'
16+
- 'afterpython/authors.yml'
17+
- 'afterpython/faq.yml'
18+
- '.github/workflows/deploy.yml'
19+
workflow_dispatch: # Allow manual deployment from Actions tab
20+
21+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
22+
permissions:
23+
contents: read
24+
pages: write
25+
id-token: write
26+
27+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
28+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
29+
concurrency:
30+
group: "pages"
31+
cancel-in-progress: false
32+
33+
jobs:
34+
build:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Set up Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: '3.11'
44+
45+
- name: Install uv
46+
uses: astral-sh/setup-uv@v5
47+
with:
48+
version: "latest"
49+
50+
- name: Install afterpython
51+
run: uv pip install --system afterpython
52+
53+
- name: Build website
54+
run: ap build
55+
56+
- name: Upload artifact
57+
uses: actions/upload-pages-artifact@v3
58+
with:
59+
path: './afterpython/_website/build'
60+
61+
deploy:
62+
environment:
63+
name: github-pages
64+
# This will dynamically generate the deployment URL
65+
url: ${{ steps.deployment.outputs.page_url }}
66+
runs-on: ubuntu-latest
67+
needs: build
68+
steps:
69+
- name: Deploy to GitHub Pages
70+
id: deployment
71+
uses: actions/deploy-pages@v4

afterpython/cli/commands/build.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ def build(ctx, dev: bool, execute: bool):
133133
Use --execute to execute Jupyter notebooks for all content types.
134134
"""
135135
from afterpython.utils import has_content_for_myst
136+
from afterpython.utils import handle_passthrough_help
137+
138+
# Show both our options and myst's help and exit
139+
handle_passthrough_help(
140+
ctx,
141+
["myst", "build"],
142+
show_underlying=True,
143+
)
136144

137145
paths = ctx.obj["paths"]
138146
prebuild()
@@ -147,7 +155,7 @@ def build(ctx, dev: bool, execute: bool):
147155
content_path = paths.afterpython_path / content_type
148156
if not has_content_for_myst(content_path):
149157
click.echo(f"Skipping {content_type}/ (no content files found)")
150-
return
158+
continue
151159

152160
click.echo(f"Building {content_type}/...")
153161
# NOTE: needs to set BASE_URL so that the project website can link to the content pages correctly at e.g. localhost:5173/doc

afterpython/cli/commands/bump.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ def bump(ctx, release: bool, pre: bool):
3030
Use --release to bump to next stable version (cz bump default behavior).
3131
"""
3232
from afterpython.tools.pyproject import read_metadata
33+
from afterpython.utils import handle_passthrough_help
34+
35+
# Show both our options and commitizen's help and exit
36+
handle_passthrough_help(
37+
ctx,
38+
["cz", "bump"],
39+
show_underlying=True,
40+
)
3341

3442
if release and pre:
3543
raise click.ClickException("Only one of --release or --pre can be specified")
@@ -38,6 +46,10 @@ def bump(ctx, release: bool, pre: bool):
3846
if release:
3947
subprocess.run(["ap", "cz", "bump", *ctx.args])
4048

49+
# Skip tag push if this is a dry run
50+
if "--dry-run" in ctx.args:
51+
return
52+
4153
# Get the new version after bump
4254
metadata = read_metadata()
4355
new_version = metadata.version

afterpython/cli/commands/check.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
@click.pass_context
1515
def check(ctx):
1616
"""Simple wrapper for ruff check for convenience, always use the afterpython/ruff.toml if it exists"""
17+
from afterpython.utils import handle_passthrough_help
18+
19+
# Show both our options and ruff's help and exit
20+
handle_passthrough_help(
21+
ctx,
22+
["ruff", "check"],
23+
show_underlying=True,
24+
)
25+
1726
paths = ctx.obj["paths"]
1827
ruff_toml = paths.afterpython_path / "ruff.toml"
1928
if ruff_toml.exists():

afterpython/cli/commands/clean.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
)
3030
def clean(ctx, all: bool):
3131
"""Clean the build directory"""
32+
from afterpython.utils import handle_passthrough_help
33+
34+
# Show both our options and myst's help and exit
35+
handle_passthrough_help(
36+
ctx,
37+
["myst", "clean"],
38+
show_underlying=True,
39+
)
40+
3241
paths = ctx.obj["paths"]
3342
node_env: NodeEnv = find_node_env()
3443

afterpython/cli/commands/commit.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
)
1818
def commit(ctx, no_cz: bool):
1919
"""Run 'cz commit'"""
20+
from afterpython.utils import handle_passthrough_help
21+
22+
# Show both our options and commitizen's help and exit
23+
handle_passthrough_help(
24+
ctx,
25+
["cz", "commit"],
26+
show_underlying=True,
27+
)
28+
2029
if not no_cz:
2130
subprocess.run(["ap", "cz", "commit", *ctx.args])
2231
else:

afterpython/cli/commands/commitizen.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
@click.pass_context
1515
def commitizen(ctx):
1616
"""Run commitizen"""
17+
from afterpython.utils import handle_passthrough_help
18+
19+
# Show both our options and commitizen's help and exit
20+
handle_passthrough_help(
21+
ctx,
22+
["cz"],
23+
show_underlying=True,
24+
)
25+
1726
paths = ctx.obj["paths"]
1827
cz_toml_path = paths.afterpython_path / "cz.toml"
1928
result = subprocess.run(

afterpython/cli/commands/dev.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ def dev(ctx, all: bool, execute: bool, no_website: bool):
5050
with custom Vite options in the afterpython/_website directory.
5151
"""
5252

53+
from afterpython.utils import handle_passthrough_help
54+
55+
# Show both our options and myst's help and exit
56+
handle_passthrough_help(
57+
ctx,
58+
["myst", "start"],
59+
show_underlying=True,
60+
)
61+
5362
# Track all MyST processes for cleanup
5463
myst_processes = []
5564

afterpython/cli/commands/format.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
@click.pass_context
1515
def format(ctx):
1616
"""Simple wrapper for ruff format for convenience"""
17+
from afterpython.utils import handle_passthrough_help
18+
19+
# Show both our options and ruff's help and exit
20+
handle_passthrough_help(
21+
ctx,
22+
["ruff", "format"],
23+
show_underlying=True,
24+
)
25+
1726
result = subprocess.run(["ruff", "format", *ctx.args], check=False)
1827
if result.returncode != 0:
1928
raise Exit(result.returncode)

afterpython/cli/commands/init.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ def init(ctx):
5555
from afterpython.tools.myst import init_myst
5656
from afterpython.tools.pre_commit import init_pre_commit
5757
from afterpython.tools.commitizen import init_commitizen
58-
from afterpython.tools.github_actions import init_release_workflow
58+
from afterpython.tools.github_actions import (
59+
init_release_workflow,
60+
init_deploy_workflow,
61+
)
5962

6063
paths = ctx.obj["paths"]
6164
click.echo("Initializing afterpython...")
@@ -91,3 +94,5 @@ def init(ctx):
9194
):
9295
init_commitizen()
9396
init_release_workflow()
97+
98+
init_deploy_workflow()

0 commit comments

Comments
 (0)