Skip to content

Commit 2104fab

Browse files
authored
Merge pull request #72 from robust-python/docs/better-readme
Docs/better readme
2 parents e29f32a + b8cafe6 commit 2104fab

File tree

7 files changed

+169
-115
lines changed

7 files changed

+169
-115
lines changed

.github/workflows/merge-demo-feature.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- "robust-maturin-demo"
2222
with:
2323
demo_name: ${{ matrix.demo_name }}
24+
branch: ${{ github.ref_name }}
2425

2526
merge-demo-feature:
2627
name: Merge Demo Feature
@@ -30,6 +31,8 @@ jobs:
3031
demo_name:
3132
- "robust-python-demo"
3233
- "robust-maturin-demo"
34+
env:
35+
GH_TOKEN: ${{ secrets.DEMO_TOKEN }}
3336
steps:
3437
- name: Checkout Template
3538
uses: actions/checkout@v4
@@ -42,6 +45,7 @@ jobs:
4245
repository: "${{ github.repository_owner }}/${{ inputs.demo_name }}"
4346
path: ${{ inputs.demo_name }}
4447
ref: develop
48+
token: ${{ secrets.DEMO_TOKEN }}
4549

4650
- name: Set up uv
4751
uses: astral-sh/setup-uv@v6

.github/workflows/sync-demos.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: sync-demo.yml
22
on:
3-
pull_request:
4-
branches:
5-
- develop
3+
push:
4+
branches-ignore:
5+
- "main"
6+
- "develop"
7+
- "release/*"
68

79
jobs:
810
update-demo:
@@ -15,3 +17,6 @@ jobs:
1517
- "robust-maturin-demo"
1618
with:
1719
demo_name: ${{ matrix.demo_name }}
20+
branch: ${{ github.ref_name }}
21+
secrets:
22+
DEMO_TOKEN: ${{ secrets.DEMO_TOKEN }}

.github/workflows/update-demo.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ on:
55
demo_name:
66
required: true
77
type: string
8+
branch:
9+
required: true
10+
type: string
11+
secrets:
12+
DEMO_TOKEN:
13+
required: true
814

915
env:
1016
COOKIECUTTER_ROBUST_PYTHON__DEMOS_CACHE_FOLDER: ${{ github.workspace }}
1117
COOKIECUTTER_ROBUST_PYTHON__APP_AUTHOR: ${{ github.repository_owner }}
1218
ROBUST_PYTHON_DEMO__APP_AUTHOR: ${{ github.repository_owner }}
1319
ROBUST_MATURIN_DEMO__APP_AUTHOR: ${{ github.repository_owner }}
20+
GH_TOKEN: ${{ secrets.DEMO_TOKEN }}
1421

1522
jobs:
1623
update-demo:
@@ -19,16 +26,24 @@ jobs:
1926
- name: Checkout Template
2027
uses: actions/checkout@v4
2128
with:
29+
fetch-depth: 0
2230
repository: ${{ github.repository }}
2331
path: "${{ github.workspace }}/cookiecutter-robust-python"
2432

33+
- name: Configure Git
34+
working-directory: "${{ github.workspace }}/cookiecutter-robust-python"
35+
run: |
36+
git config --global user.name "github-actions[bot]"
37+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
38+
2539
- name: Checkout Demo
2640
uses: actions/checkout@v4
2741
with:
2842
fetch-depth: 0
2943
repository: "${{ github.repository_owner }}/${{ inputs.demo_name }}"
3044
path: ${{ inputs.demo_name }}
3145
ref: develop
46+
token: ${{ secrets.DEMO_TOKEN }}
3247

3348
- name: Set up uv
3449
uses: astral-sh/setup-uv@v6
@@ -40,4 +55,4 @@ jobs:
4055

4156
- name: Update Demo
4257
working-directory: "${{ github.workspace }}/cookiecutter-robust-python"
43-
run: "uvx nox -s 'update-demo(${{ inputs.demo_name }})' -- --branch-override ${{ github.head_ref }}"
58+
run: "uvx nox -s 'update-demo(${{ inputs.demo_name }})' -- --branch-override ${{ inputs.branch }}"

README.md

Lines changed: 120 additions & 109 deletions
Large diffs are not rendered by default.

docs/_static/pin.svg

Lines changed: 4 additions & 0 deletions
Loading

scripts/update-demo.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def update_demo(
5050
demo_name: str = get_demo_name(add_rust_extension=add_rust_extension)
5151
demo_path: Path = demos_cache_folder / demo_name
5252

53+
typer.secho(f"template:\n\tcurrent_branch: {get_current_branch()}\n\tcurrent_commit: {get_current_commit()}")
5354
if branch_override is not None:
5455
typer.secho(f"Overriding current branch name for demo reference. Using '{branch_override}' instead.")
5556
desired_branch_name: str = branch_override
@@ -76,6 +77,7 @@ def update_demo(
7677

7778
typer.secho(f"Updating demo project at {demo_path=}.", fg="yellow")
7879
with work_in(demo_path):
80+
typer.secho(f"demo:\n\tcurrent_branch: {get_current_branch()}\n\tcurrent_commit: {get_current_commit()}")
7981
if get_current_branch() != desired_branch_name:
8082
git("checkout", "-b", desired_branch_name, DEMO.develop_branch)
8183

@@ -146,8 +148,10 @@ def _create_demo_pr(demo_path: Path, branch: str, commit_start: str) -> None:
146148
"""Creates a PR to merge the given branch into develop."""
147149
gh("repo", "set-default", f"{DEMO.app_author}/{DEMO.app_name}")
148150
search_results: subprocess.CompletedProcess = gh("pr", "list", "--state", "open", "--search", branch)
149-
if "no pull requests match your search" not in search_results.stdout:
150-
typer.secho(f"Skipping PR creation due to existing PR found for branch {branch}")
151+
152+
if search_results.returncode == 0:
153+
url: str = _get_pr_url(branch=branch)
154+
typer.secho(f"Skipping PR creation due to existing PR found for branch {branch} at {url}")
151155
return
152156

153157
body: str = _get_demo_feature_pr_body(demo_path=demo_path, commit_start=commit_start)
@@ -160,6 +164,16 @@ def _create_demo_pr(demo_path: Path, branch: str, commit_start: str) -> None:
160164
"--repo": f"{DEMO.app_author}/{DEMO.app_name}",
161165
}
162166
gh("pr", "create", *itertools.chain.from_iterable(pr_kwargs.items()))
167+
url: str = _get_pr_url(branch=branch)
168+
typer.secho(f"Created PR for branch '{branch}' at '{url}'.")
169+
170+
171+
def _get_pr_url(branch: str) -> str:
172+
"""Returns the url of the current branch's PR."""
173+
result: subprocess.CompletedProcess = gh("pr", "view", branch, "--json", "url", "--jq", ".url")
174+
if result.returncode != 0:
175+
raise ValueError(f"Failed to find a PR URL for branch {branch}.")
176+
return result.stdout.strip()
163177

164178

165179
def _get_demo_feature_pr_body(demo_path: Path, commit_start: str) -> str:

scripts/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def require_clean_and_up_to_date_demo_repo(demo_path: Path) -> None:
131131
try:
132132
with work_in(demo_path):
133133
git("fetch")
134+
git("fetch", "origin", f"{DEMO.main_branch}:{DEMO.main_branch}")
134135
git("status", "--porcelain")
135136
validate_is_synced_ancestor(ancestor=DEMO.main_branch, descendent=DEMO.develop_branch)
136137
except Exception as e:

0 commit comments

Comments
 (0)