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