contrib #696
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v4 | |
with: | |
persist-credentials: false | |
- name: Checkout hyper | |
uses: actions/checkout@v4 | |
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 | |
# Insert frontmatter borders, replace markdown header with | |
# frontmatter title and insert: | |
# - layout: guide | |
# - hyper_path: {path} | |
- name: Convert doc titles to frontmatter | |
run: | | |
for f in hyper/docs/*.md; do | |
sed -i -e '1i ---' \ | |
-e '1s/#/title:/' \ | |
-e '2i layout: guide' \ | |
-e "2i hyper_path: ${f:6}" \ | |
-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 | |
# Lowercase the internal links and replace underscores with | |
# hyphens, so they will point to the correct file. | |
- name: Lowercase internal links | |
run: | | |
for filename in hyper/docs/*.md; do | |
# since we move some docs from hyper root into the docs folder, | |
# fix links to them | |
sed -i -e 's|\.\./|\./|g' $filename; | |
# cut `.md` from the filename before search and replace | |
filename=${filename::-3}; | |
for file in hyper/docs/*.md; 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: | | |
for f in hyper/docs/*; do | |
mv -vn "$f" "$(echo \"$f\" | tr '[:upper:]' '[:lower:]' | tr '_' '-')" || 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 <[email protected]> | |
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/ | |