|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # SPDX-License-Identifier: BSD-3-Clause |
3 | | -# Copyright 2018-2020, Intel Corporation |
| 3 | +# Copyright 2018-2022, Intel Corporation |
4 | 4 |
|
5 | 5 | # |
6 | 6 | # run-doc-update.sh - is called inside a Docker container, |
|
10 | 10 |
|
11 | 11 | set -e |
12 | 12 |
|
13 | | -source `dirname $0`/valid-branches.sh |
| 13 | +if [[ -z "${DOC_UPDATE_GITHUB_TOKEN}" ]]; then |
| 14 | + echo "To build documentation and upload it as a Github pull request, variable " \ |
| 15 | + "'DOC_UPDATE_GITHUB_TOKEN' has to be provided." |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +if [[ -z "${WORKDIR}" ]]; then |
| 20 | + echo "ERROR: The variable WORKDIR has to contain a path to the root " \ |
| 21 | + "of this project - 'build' sub-directory may be created there." |
| 22 | + exit 1 |
| 23 | +fi |
14 | 24 |
|
15 | 25 | BOT_NAME=${DOC_UPDATE_BOT_NAME:-"pmem-bot"} |
16 | | -DOC_REPO_OWNER="${DOC_REPO_OWNER:-"pmem"}" |
17 | | -REPO_NAME="libpmemobj-cpp" |
| 26 | +DOC_REPO_OWNER=${DOC_REPO_OWNER:-"pmem"} |
| 27 | +DOC_REPO_NAME=${DOC_REPO_NAME:-"${DOC_REPO_OWNER}.github.io"} |
| 28 | +export GITHUB_TOKEN=${DOC_UPDATE_GITHUB_TOKEN} # export for hub command |
| 29 | +DOC_REPO_DIR=$(mktemp -d -t pmem_io-XXX) |
18 | 30 | ARTIFACTS_DIR=$(mktemp -d -t ARTIFACTS-XXX) |
19 | 31 |
|
20 | | -ORIGIN="https://${DOC_UPDATE_GITHUB_TOKEN}@github.com/${BOT_NAME}/${REPO_NAME}" |
21 | | -UPSTREAM="https://github.com/${DOC_REPO_OWNER}/${REPO_NAME}" |
22 | | -# master or stable-* branch |
23 | | -TARGET_BRANCH=${CI_BRANCH} |
24 | | -VERSION=${TARGET_BRANCHES[$TARGET_BRANCH]} |
25 | | -export GITHUB_TOKEN=${DOC_UPDATE_GITHUB_TOKEN} |
26 | | - |
27 | | -if [ -z $VERSION ]; then |
28 | | - echo "Target location for branch ${TARGET_BRANCH} is not defined." |
29 | | - exit 1 |
| 32 | +# Determine docs location directory, based on the branch (for CI builds: 'master' or 'vX.Y') |
| 33 | +if [[ ${CI_BRANCH} == stable-* ]]; then |
| 34 | + DOCS_TARGET_DIR=$(echo ${CI_BRANCH} | awk -F 'stable-' '/stable-/{printf "v"} {print $(NF)}') |
| 35 | +else |
| 36 | + DOCS_TARGET_DIR=${CI_BRANCH} |
30 | 37 | fi |
31 | | -REPO_DIR=$(mktemp -d -t libpmemobjcpp-XXX) |
32 | | -pushd ${REPO_DIR} |
33 | | -# Clone repo |
34 | | -git clone ${ORIGIN} ${REPO_DIR} |
35 | | -cd ${REPO_DIR} |
36 | | -git remote add upstream ${UPSTREAM} |
37 | 38 |
|
38 | | -git config --local user.name ${BOT_NAME} |
39 | | -git config --local user.email "${BOT_NAME}@intel.com" |
40 | | -hub config --global hub.protocol https |
41 | | - |
42 | | -git remote update |
43 | | -git checkout -B ${TARGET_BRANCH} upstream/${TARGET_BRANCH} |
| 39 | +ORIGIN="https://${GITHUB_TOKEN}@github.com/${BOT_NAME}/${DOC_REPO_NAME}" |
| 40 | +UPSTREAM="https://github.com/${DOC_REPO_OWNER}/${DOC_REPO_NAME}" |
44 | 41 |
|
45 | | -# Build docs |
46 | | -mkdir -p ${REPO_DIR}/build |
47 | | -cd ${REPO_DIR}/build |
| 42 | +echo "Build docs" |
| 43 | +pushd ${WORKDIR} |
| 44 | +mkdir -p build |
| 45 | +pushd build |
48 | 46 |
|
49 | | -cmake .. -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARKS=OFF |
| 47 | +cmake -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_BENCHMARKS=OFF -DBUILD_DOC=ON .. |
50 | 48 | make -j$(nproc) doc |
51 | | -cp -r ${REPO_DIR}/build/doc/cpp_html ${ARTIFACTS_DIR}/ |
| 49 | +cp -R doc/cpp_html ${ARTIFACTS_DIR} |
| 50 | +popd |
| 51 | +popd |
52 | 52 |
|
53 | | -cd ${REPO_DIR} |
| 53 | +echo "Clone pmem.io repo (with web content and our docs):" |
| 54 | +git clone --depth=1 ${ORIGIN} ${DOC_REPO_DIR} |
| 55 | +pushd ${DOC_REPO_DIR} |
| 56 | +git remote add upstream ${UPSTREAM} |
| 57 | +git fetch upstream |
| 58 | + |
| 59 | +git config --local user.name ${BOT_NAME} |
| 60 | +git config --local user.email "${BOT_NAME}@intel.com" |
| 61 | +hub config --global hub.protocol https |
54 | 62 |
|
55 | | -# Checkout gh-pages and copy docs |
56 | | -GH_PAGES_NAME="gh-pages-for-${TARGET_BRANCH}" |
57 | | -git checkout -B ${GH_PAGES_NAME} upstream/gh-pages |
| 63 | +echo "Checkout new branch (based on 'main') for PR" |
| 64 | +DOCS_BRANCH_NAME="libpmemobj-cpp-${DOCS_TARGET_DIR}-docs-update" |
| 65 | +git checkout -B ${DOCS_BRANCH_NAME} upstream/main |
58 | 66 | git clean -dfx |
59 | 67 |
|
60 | | -# Clean old content, since some files might have been deleted |
61 | | -rm -rf ./${VERSION} |
62 | | -mkdir -p ./${VERSION}/doxygen/ |
| 68 | +DOCS_CONTENT_DIR="./content/libpmemobj-cpp/${DOCS_TARGET_DIR}/" |
| 69 | +echo "Clean old content, since some files might have been deleted" |
| 70 | +rm -rf ${DOCS_CONTENT_DIR} |
| 71 | +mkdir -p ${DOCS_CONTENT_DIR}/doxygen/ |
63 | 72 |
|
64 | | -cp -fr ${ARTIFACTS_DIR}/cpp_html/* ./${VERSION}/doxygen/ |
| 73 | +echo "Copy all content" |
| 74 | +cp -r ${ARTIFACTS_DIR}/cpp_html/* ${DOCS_CONTENT_DIR}/doxygen/ |
65 | 75 |
|
66 | | -# Add and push changes. |
| 76 | +echo "Add and push changes" |
67 | 77 | # git commit command may fail if there is nothing to commit. |
68 | 78 | # In that case we want to force push anyway (there might be open pull request with |
69 | 79 | # changes which were reverted). |
70 | 80 | git add -A |
71 | | -git commit -m "doc: automatic gh-pages docs update" && true |
72 | | -git push -f ${ORIGIN} ${GH_PAGES_NAME} |
| 81 | +git commit -m "libpmemobj-cpp: automatic docs update for '${CI_BRANCH}'" && true |
| 82 | +git push -f ${ORIGIN} ${DOCS_BRANCH_NAME} |
73 | 83 |
|
74 | | -# Makes pull request. |
| 84 | +echo "Make a Pull Request" |
75 | 85 | # When there is already an open PR or there are no changes an error is thrown, which we ignore. |
76 | | -hub pull-request -f -b ${DOC_REPO_OWNER}:gh-pages -h ${BOT_NAME}:${GH_PAGES_NAME} -m "doc: automatic gh-pages docs update" && true |
| 86 | +hub pull-request -f -b ${DOC_REPO_OWNER}:main -h ${BOT_NAME}:${DOCS_BRANCH_NAME} \ |
| 87 | + -m "libpmemobj-cpp: automatic docs update for '${CI_BRANCH}'" && true |
77 | 88 |
|
78 | 89 | popd |
0 commit comments