ci: sync docs with libretime/website repository

This commit is contained in:
jo 2022-12-19 18:18:24 +01:00 committed by Jonas L
parent dc0353c1d3
commit fa5bd5ed11
2 changed files with 88 additions and 2 deletions

View File

@ -2,19 +2,22 @@ name: Docs
on: on:
push: push:
branches: [main] branches: [main, 3.0.x]
paths: paths:
- .github/vale/** - .github/vale/**
- .github/workflows/docs.yml - .github/workflows/docs.yml
- docs/** - docs/**
pull_request: pull_request:
branches: [main] branches: [main, 3.0.x]
paths: paths:
- .github/vale/** - .github/vale/**
- .github/workflows/docs.yml - .github/workflows/docs.yml
- docs/** - docs/**
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs: jobs:
lint: lint:
name: Lint name: Lint
@ -51,3 +54,24 @@ jobs:
vale sync vale sync
vale --output line docs || true vale --output line docs || true
vale --output line --minAlertLevel=error docs/releases vale --output line --minAlertLevel=error docs/releases
sync:
name: Sync
if: >
github.repository_owner == 'libretime' &&
github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/checkout@v3
with:
repository: libretime/website
path: website
ssh-key: "${{ secrets.WEBSITE_DEPLOY_KEY }}"
- name: Sync docs changes
run: tools/ci-sync-docs.sh ${{ github.event.before }}..${{ github.sha }}

62
tools/ci-sync-docs.sh Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env bash
# Sync the docs folder with the libretime/website repository.
set -e
error() {
echo >&2 "error: $*"
exit 1
}
command -v git > /dev/null || error "git command not found!"
usage() {
cat >&2 <<- EOF
Usage : $0 <commit_range>
Positional arguments:
commit_range Commit range to scan for changes within the docs folder.
EOF
}
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
commit_range="$1"
[[ -n "$GITHUB_REF_NAME" ]] || error "GITHUB_REF_NAME variable is not set!"
[[ -n "$GITHUB_REPOSITORY" ]] || error "GITHUB_REPOSITORY variable is not set!"
git config --global user.name "libretime-bot"
git config --global user.email "libretime-bot@users.noreply.github.com"
if [[ "$GITHUB_REF_NAME" == "main" ]]; then
dest="docs"
else
dest="versioned_docs/version-$GITHUB_REF_NAME"
fi
for commit in $(git rev-list --reverse --no-merges "$commit_range" -- docs); do
rm -fR "website/$dest"
cp -r "docs" "website/$dest"
git show \
--quiet \
--format="%B%n${GITHUB_REPOSITORY}@%H" \
"$commit" \
> commit-message
pushd website
git add "$dest"
git diff-index --quiet HEAD -- || git commit --file=../commit-message
popd
rm commit-message
done
pushd website
git push
popd