Skip to content

Commit c44375d

Browse files
committed
Migrate to use python to fetch data
1 parent 3a19112 commit c44375d

File tree

4 files changed

+74
-38
lines changed

4 files changed

+74
-38
lines changed

.github/workflows/update-docs.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ jobs:
2020
- name: Install pnpm
2121
run: npm install -g pnpm
2222

23-
- name: Fetch docs
23+
- name: Install pipx
24+
run: |
25+
python3 -m pip install --user pipx
26+
python3 -m pipx ensurepath
27+
28+
- name: Fetch data
2429
working-directory: apps/frontend
2530
run: |
26-
pnpm fetch-docs
31+
pnpm fetch-data
2732
2833
- name: Check for changes
2934
run: |

apps/frontend/fetch-docs.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

apps/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "astro check && astro build",
99
"preview": "astro preview",
1010
"astro": "astro",
11-
"fetch-docs": "sh fetch-docs.sh"
11+
"fetch-data": "pipx run scripts/download-data.py"
1212
},
1313
"dependencies": {
1414
"@astrojs/check": "^0.7.0",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# /// script
2+
# dependencies = [
3+
# ]
4+
# requires-python = ">=3.11"
5+
# ///
6+
7+
import os
8+
import shutil
9+
import subprocess
10+
import tempfile
11+
12+
13+
def clone_docs_from_repo(repo, destination_subpath, branch="main"):
14+
working_dir = os.getcwd()
15+
destination = os.path.join(working_dir, "src", "content", destination_subpath)
16+
17+
print(f"Cloning docs from {repo} to {destination} on branch {branch}")
18+
19+
with tempfile.TemporaryDirectory() as tmpdirname:
20+
os.chdir(tmpdirname)
21+
22+
subprocess.run(
23+
["git", "clone", "-n", "--depth=1", "--filter=tree:0", "-b", branch, repo],
24+
stdout=subprocess.DEVNULL,
25+
stderr=subprocess.DEVNULL,
26+
)
27+
28+
repo_name = os.path.basename(repo)
29+
os.chdir(repo_name)
30+
31+
subprocess.run(
32+
["git", "sparse-checkout", "set", "--no-cone", "docs"],
33+
stdout=subprocess.DEVNULL,
34+
stderr=subprocess.DEVNULL,
35+
)
36+
subprocess.run(
37+
["git", "checkout"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
38+
)
39+
40+
os.makedirs(destination, exist_ok=True)
41+
42+
for item in os.listdir("docs"):
43+
s = os.path.join("docs", item)
44+
d = os.path.join(destination, item)
45+
if os.path.isdir(s):
46+
shutil.copytree(s, d, dirs_exist_ok=True)
47+
else:
48+
shutil.copy2(s, d)
49+
50+
os.chdir(working_dir)
51+
52+
53+
# Remove existing docs directory
54+
shutil.rmtree("src/content/docs", ignore_errors=True)
55+
56+
# Clone docs from repository
57+
clone_docs_from_repo("https://github.com/strawberry-graphql/strawberry", "docs")
58+
# clone_docs_from_repo("https://github.com/strawberry-graphql/strawberry-django", "docs/django", "feature/new-docs")
59+
60+
# Rename all .md files to .mdx in the docs folder
61+
for root, _, files in os.walk("src/content/docs"):
62+
for file in files:
63+
if file.endswith(".md"):
64+
file_path = os.path.join(root, file)
65+
new_file_path = os.path.splitext(file_path)[0] + ".mdx"
66+
os.rename(file_path, new_file_path)

0 commit comments

Comments
 (0)