From da5384ffa8a5dfcff3cab138b1f94de41a9d85ba Mon Sep 17 00:00:00 2001 From: Jinlin Zhang Date: Mon, 29 Jun 2020 07:42:25 -0700 Subject: [PATCH] Automate publishing docs on CirclrCI (#2486) * Automate publishing docs on CirclrCI * Automate publishing docs on CircleCI * Automate publishing docs on CircleCI * Automate publishing docs using linux VM * Fixed Python3 compatible issues * Added code to install android_sdk * Automate docs, installed JDK for java docs * Automate publishing docs on CircleCI, added CNAME * Automate publishing docs deleted an extra line * Automate publishing docs, refactored code * Automate publishing docs, changed a required test name Co-authored-by: buck-bot <66389669+buck-bot@users.noreply.github.com> --- .circleci/config.yml | 57 ++++++++++++++++++++++++++++++++------------ docs/publish.sh | 6 ++++- docs/soy2html.py | 5 ++-- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a53eb43d561..1fd68ff2c21 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -195,6 +195,13 @@ windows_environment: &windows_environment BUCK_NUM_THREADS: 3 BUCK_PEX_LOCATION: "./new_buck.pex" +tags_only_filter: &tags_only_filter + filters: + tags: + only: /^v20.*/ + branches: + ignore: /.*/ + jobs: linux_build_openjdk8: environment: @@ -1226,6 +1233,36 @@ jobs: python3 ./tools/release/publish_release.py --no-build-deb --no-build-homebrew --github-token ${GITHUB_TOKEN} --chocolatey-token ${CHOCO_TOKEN} --use-existing-release --version ${VERSION} --output-dir artifacts shell: bash.exe + publish_docs: + environment: + <<: *linux_environment + working_directory: "/home/circleci/buck" + machine: + image: ubuntu-1604:201903-01 + steps: + - checkout + - run: + <<: *install_openjdk8 + - run: + # android_sdk needed to build java docs. + <<: *install_android_sdk + - run: + <<: *install_python + - run: + # We do not want to build buck, install the latest release instead. + name: Install Buck + command: | + url=`curl -sH "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/facebook/buck/releases/latest |grep "browser_download_url.*deb" |awk '{gsub("\"", "", $2); print $2}'` + curl -L -O $url + filename=`basename ${url}` + sudo dpkg -i ${filename} || echo "Warning: Buck installed without dependencies." + - run: + name: Publish docs + command: | + export ANDROID_HOME="${ANDROID_SDK}" + cd docs + ./publish.sh --start-soyweb + workflows: version: 2.1 linux_jobs: @@ -1260,20 +1297,10 @@ workflows: publish_jobs: jobs: - macos_publish_release: - filters: - tags: - only: /^v20.*/ - branches: - ignore: /.*/ + <<: *tags_only_filter - linux_publish_release: - filters: - tags: - only: /^v20.*/ - branches: - ignore: /.*/ + <<: *tags_only_filter - windows_publish_release: - filters: - tags: - only: /^v20.*/ - branches: - ignore: /.*/ + <<: *tags_only_filter + - publish_docs: + <<: *tags_only_filter diff --git a/docs/publish.sh b/docs/publish.sh index 56d1fd460ad..7728da0e0bf 100755 --- a/docs/publish.sh +++ b/docs/publish.sh @@ -38,6 +38,8 @@ EOF exit 1 } +GIT_USER="buck-bot" +CNAME="buck.build" START_SOYWEB=0 KEEP_FILES=0 SOYWEB_PID=0 @@ -83,7 +85,7 @@ echo "Documentation working directory is ${STATIC_FILES_DIR}" # Create a clean checkout of the gh-pages branch with no data: if [ -z "$1" ] then - git clone git@github.com:facebook/buck.git $STATIC_FILES_DIR + git clone https://${GIT_USER}:${GITHUB_TOKEN}@github.com/facebook/buck.git $STATIC_FILES_DIR else cp -r "$1" $STATIC_FILES_DIR fi @@ -101,6 +103,8 @@ cd - # Commit the new version of the docs: cd $STATIC_FILES_DIR +echo "${CNAME}" > CNAME +git config --global user.name "${GIT_USER}" git add . git commit -m "Updated HTML documentation." diff --git a/docs/soy2html.py b/docs/soy2html.py index 369eeb7f4c6..89e54f4f85c 100644 --- a/docs/soy2html.py +++ b/docs/soy2html.py @@ -57,7 +57,7 @@ def main(output_dir): ): # Copy the static resource to output_dir. relative_path = os.path.join(root, file_name) - with open(relative_path) as resource_file: + with open(relative_path, "rb") as resource_file: resource = resource_file.read() copy_to_output_dir(relative_path, output_dir, resource) @@ -74,7 +74,7 @@ def ensure_dir(path, output_dir): def copy_to_output_dir(path, output_dir, content): output_file = ensure_dir(path, output_dir) - with open(output_file, "w") as f: + with open(output_file, "wb") as f: f.write(content) @@ -88,7 +88,6 @@ def pollForServerReady(): time.sleep(1) print("Server failed to start after %s seconds." % SERVER_START_POLL) - if __name__ == "__main__": output_dir = sys.argv[1] pollForServerReady()