Skip to content

Commit e588022

Browse files
committed
Migrate to standalone docs repo
1 parent 9a817a2 commit e588022

File tree

1 file changed

+86
-9
lines changed

1 file changed

+86
-9
lines changed

Diff for: .github/workflows/publish-docs.yml

+86-9
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,119 @@ jobs:
2121
mkdocs:
2222
runs-on: ubuntu-latest
2323
env:
24-
CF_API_TOKEN_EXISTS: ${{ secrets.CF_API_TOKEN != '' }}
2524
MKDOCS_INSIDERS_SSH_KEY_EXISTS: ${{ secrets.MKDOCS_INSIDERS_SSH_KEY != '' }}
2625
steps:
2726
- uses: actions/checkout@v4
2827
with:
2928
ref: ${{ inputs.ref }}
29+
3030
- uses: actions/setup-python@v5
31+
with:
32+
python-version: 3.12
33+
34+
- name: "Set docs version"
35+
run: |
36+
version="${{ (inputs.plan != '' && fromJson(inputs.plan).announcement_tag) || inputs.ref }}"
37+
# if version is missing, exit with error
38+
if [[ -z "$version" ]]; then
39+
echo "Can't build docs without a version."
40+
exit 1
41+
fi
42+
43+
# Use version as display name for now
44+
display_name="$version"
45+
46+
echo "version=$version" >> $GITHUB_ENV
47+
echo "display_name=$display_name" >> $GITHUB_ENV
48+
49+
- name: "Set branch name"
50+
run: |
51+
version="${{ env.version }}"
52+
display_name="${{ env.display_name }}"
53+
timestamp="$(date +%s)"
54+
55+
# create branch_display_name from display_name by replacing all
56+
# characters disallowed in git branch names with hyphens
57+
branch_display_name="$(echo "$display_name" | tr -c '[:alnum:]._' '-' | tr -s '-')"
58+
59+
echo "branch_name=update-docs-$branch_display_name-$timestamp" >> $GITHUB_ENV
60+
echo "timestamp=$timestamp" >> $GITHUB_ENV
61+
3162
- name: "Add SSH key"
3263
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
3364
uses: webfactory/[email protected]
3465
with:
3566
ssh-private-key: ${{ secrets.MKDOCS_INSIDERS_SSH_KEY }}
67+
3668
- name: "Install Rust toolchain"
3769
run: rustup show
70+
3871
- uses: Swatinem/rust-cache@v2
72+
3973
- name: "Install Insiders dependencies"
4074
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
4175
run: pip install -r docs/requirements-insiders.txt
76+
4277
- name: "Install dependencies"
4378
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS != 'true' }}
4479
run: pip install -r docs/requirements.txt
80+
4581
- name: "Copy README File"
4682
run: |
4783
python scripts/transform_readme.py --target mkdocs
4884
python scripts/generate_mkdocs.py
85+
4986
- name: "Build Insiders docs"
5087
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
5188
run: mkdocs build --strict -f mkdocs.insiders.yml
89+
5290
- name: "Build docs"
5391
if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS != 'true' }}
5492
run: mkdocs build --strict -f mkdocs.public.yml
55-
- name: "Deploy to Cloudflare Pages"
56-
if: ${{ env.CF_API_TOKEN_EXISTS == 'true' }}
57-
uses: cloudflare/[email protected]
58-
with:
59-
apiToken: ${{ secrets.CF_API_TOKEN }}
60-
accountId: ${{ secrets.CF_ACCOUNT_ID }}
61-
# `github.head_ref` is only set during pull requests and for manual runs or tags we use `main` to deploy to production
62-
command: pages deploy site --project-name=astral-docs --branch ${{ github.head_ref || 'main' }} --commit-hash ${GITHUB_SHA}
93+
94+
- name: "Clone repo"
95+
run: |
96+
version="${{ env.version }}"
97+
git clone https://${{ secrets.ASTRAL_DOCS_PAT }}@github.com/astral-sh/docs.git astral-docs
98+
99+
- name: "Copy docs"
100+
run: rm -rf astral-docs/docs/ruff && mkdir -p astral-docs/docs && cp -r docs/ruff astral-docs/docs/
101+
102+
- name: "Commit docs"
103+
working-directory: astral-docs
104+
run: |
105+
branch_name="${{ env.branch_name }}"
106+
107+
git config user.name "$GITHUB_ACTOR"
108+
git config user.email "[email protected]"
109+
110+
git checkout -b $branch_name
111+
git add docs/ruff
112+
git commit -m "Update ruff documentation for $version"
113+
114+
- name: "Create Pull Request"
115+
working-directory: astral-docs
116+
env:
117+
GITHUB_TOKEN: ${{ secrets.ASTRAL_DOCS_PAT }}
118+
run: |
119+
version="${{ env.version }}"
120+
display_name="${{ env.display_name }}"
121+
branch_name="${{ env.branch_name }}"
122+
123+
# set the PR title
124+
pull_request_title="Update documentation for $display_name"
125+
126+
# Delete any existing pull requests that are open for this version
127+
# by checking against pull_request_title because the new PR will
128+
# supersede the old one.
129+
gh pr list --state open --json title --jq '.[] | select(.title == "$pull_request_title") | .number' | \
130+
xargs -I {} gh pr close {}
131+
132+
# push the branch to GitHub
133+
git push origin $branch_name
134+
135+
# create the PR
136+
gh pr create --base main --head $branch_name \
137+
--title "$pull_request_title" \
138+
--body "Automated documentation update for $display_name" \
139+
--label "documentation"

0 commit comments

Comments
 (0)