From b46139480150d6e89c4d6fae5ab79a3736508d4f Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 19 Dec 2022 18:18:24 +0100 Subject: [PATCH] ci: sync docs with libretime/website repository --- .github/workflows/docs.yml | 28 +++++++++++++++-- tools/ci-sync-docs.sh | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100755 tools/ci-sync-docs.sh diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8d5e46027..acd82d38e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -2,19 +2,22 @@ name: Docs on: push: - branches: [main] + branches: [main, 3.0.x] paths: - .github/vale/** - .github/workflows/docs.yml - docs/** pull_request: - branches: [main] + branches: [main, 3.0.x] paths: - .github/vale/** - .github/workflows/docs.yml - docs/** +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + jobs: lint: name: Lint @@ -51,3 +54,24 @@ jobs: vale sync vale --output line docs || true 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 }} diff --git a/tools/ci-sync-docs.sh b/tools/ci-sync-docs.sh new file mode 100755 index 000000000..10bcc56e4 --- /dev/null +++ b/tools/ci-sync-docs.sh @@ -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 + +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