Repository navigation
146 lines (123 loc) · 4.96 KB
/
Copy pathcontrib.yml
File metadata and controls
146 lines (123 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: contrib
on:
schedule:
- cron: '15 3 * * *'
workflow_dispatch:
permissions:
contents: write # to update _contrib
pull-requests: write # to send the updated _contrib PRs
jobs:
update-contrib:
name: Update _contrib
runs-on: ubuntu-latest
steps:
- name: Checkout website
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Checkout hyper
uses: actions/checkout@v7
with:
persist-credentials: false
repository: hyperium/hyper
path: hyper
- name: Copy CONTRIBUTING.md into docs
run: |
sed -i -e 's|./docs/||g' hyper/CONTRIBUTING.md
cp -a hyper/CONTRIBUTING.md hyper/docs/CONTRIBUTING.md
- name: Generate HIP index
run: |
index=hyper/docs/hips/index.md
printf '# hyper Improvement Proposals\n\n' > "$index"
for f in hyper/docs/hips/[0-9][0-9][0-9][0-9]-*.md; do
if [[ "$(basename "$f")" == '0000-template.md' ]]; then
continue
fi
title=$(sed -n '1s/^# //p' "$f")
path=$(basename "$f" .md)
printf -- '- [%s](./%s/)\n' "$title" "$path" >> "$index"
done
# Insert frontmatter borders, replace markdown header with
# frontmatter title and insert:
# - layout: guide
# - hyper_path: {path}
- name: Convert doc titles to frontmatter
run: |
find hyper/docs -mindepth 1 -maxdepth 2 -type f -name '*.md' -print0 |
while IFS= read -r -d '' f; do
sed -i -e '1i ---' \
-e '1s/^# /title: >-\n /' \
-e '2i layout: guide' \
-e "2i hyper_path: ${f#hyper/}" \
-e '2i ---' "$f"
done
# CONTRIBUTING.md is uniquely copied into the docs folder.
# This adjustment links the correct source file.
- name: Retain correct CONTRIBUTING.md path
run: |
sed -i -e '4s/docs\///' hyper/docs/CONTRIBUTING.md
# Use the hyper docs readme as the index page of contrib,
# and insert permalink: /contrib/ in the frontmatter
- name: Convert readme to index
run: |
sed -i -e '4i permalink: /contrib/' hyper/docs/README.md
mv hyper/docs/README.md hyper/docs/index.md
sed -i -e '/^hyper_path:/d' hyper/docs/hips/index.md
sed -i -e '4i permalink: /contrib/hips/' hyper/docs/hips/index.md
# Lowercase the internal links and replace underscores with
# hyphens, so they will point to the correct file.
- name: Lowercase internal links
run: |
mapfile -d '' markdown_files < <(
find hyper/docs -mindepth 1 -maxdepth 2 -type f -name '*.md' -print0
)
for filename in "${markdown_files[@]}"; do
# since we move some docs from hyper root into the docs folder,
# fix links to them
if [[ "$filename" != hyper/docs/hips/* ]]; then
sed -i -e 's|\.\./|\./|g' "$filename"
fi
# cut `.md` from the filename before search and replace
filename=${filename::-3};
for file in "${markdown_files[@]}"; do
# filename without parent path
filename=${filename##*/}
# don't lowercase MSRV
if [[ "${filename}" == 'MSRV' ]]; then
continue
fi
# lowercase filenames outside frontmatter
sed -i -e "1,/^---$/!s|${filename}|${filename,,}|g" "$file"
# match on the lowercased filename from here on
lowercased=${filename,,}
hyphenated=${lowercased//_/-}
# replace underscores in internal links with hyphens
sed -i -e "s|${lowercased}|${hyphenated}|g" "$file"
done
done
- name: Lowercase filenames and replace underscores
run: |
find hyper/docs -mindepth 1 -maxdepth 2 -type f -print0 |
while IFS= read -r -d '' f; do
directory=$(dirname "$f")
filename=$(basename "$f" | tr '[:upper:]' '[:lower:]' | tr '_' '-')
mv -vn "$f" "$directory/$filename" || true
done
- name: Copy the hyper docs to contrib
run: |
mkdir -p _contrib
cp -a hyper/docs/. _contrib/
- uses: gr2m/create-or-update-pull-request-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
author: github-actions <github-actions@github.com>
branch: actions/update-contrib
title: 'doc: update contrib docs'
body: >
The _contrib docs are likely out of date. This is an automatically
generated PR by the `contrib.yml` GitHub workflow, which clones the docs
from the main repo, implements the changes in _contrib then submits a new
PR or updates an existing PR.
commit-message: 'doc: update contrib docs'
path: _contrib/