@@ -21,42 +21,119 @@ jobs:
21
21
mkdocs :
22
22
runs-on : ubuntu-latest
23
23
env :
24
- CF_API_TOKEN_EXISTS : ${{ secrets.CF_API_TOKEN != '' }}
25
24
MKDOCS_INSIDERS_SSH_KEY_EXISTS : ${{ secrets.MKDOCS_INSIDERS_SSH_KEY != '' }}
26
25
steps :
27
26
- uses : actions/checkout@v4
28
27
with :
29
28
ref : ${{ inputs.ref }}
29
+
30
30
- 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
+
31
62
- name : " Add SSH key"
32
63
if : ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
33
64
uses :
webfactory/[email protected]
34
65
with :
35
66
ssh-private-key : ${{ secrets.MKDOCS_INSIDERS_SSH_KEY }}
67
+
36
68
- name : " Install Rust toolchain"
37
69
run : rustup show
70
+
38
71
- uses : Swatinem/rust-cache@v2
72
+
39
73
- name : " Install Insiders dependencies"
40
74
if : ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
41
75
run : pip install -r docs/requirements-insiders.txt
76
+
42
77
- name : " Install dependencies"
43
78
if : ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS != 'true' }}
44
79
run : pip install -r docs/requirements.txt
80
+
45
81
- name : " Copy README File"
46
82
run : |
47
83
python scripts/transform_readme.py --target mkdocs
48
84
python scripts/generate_mkdocs.py
85
+
49
86
- name : " Build Insiders docs"
50
87
if : ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }}
51
88
run : mkdocs build --strict -f mkdocs.insiders.yml
89
+
52
90
- name : " Build docs"
53
91
if : ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS != 'true' }}
54
92
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