|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +# This source file is part of the Swift.org open source project |
| 4 | +# |
| 5 | +# Copyright (c) 2022 Apple Inc. and the Swift project authors |
| 6 | +# Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +# |
| 8 | +# See https://swift.org/LICENSE.txt for license information |
| 9 | +# See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 10 | + |
| 11 | +# Updates the GitHub Pages documentation site that's published from the 'docs' |
| 12 | +# subdirectory in the 'gh-pages' branch of this repository. |
| 13 | +# |
| 14 | +# This script should be run by someone with commit access to the 'gh-pages' branch |
| 15 | +# at a regular frequency so that the documentation content on the GitHub Pages site |
| 16 | +# is up-to-date with the content in this repo. |
| 17 | +# |
| 18 | +# To use top-of-tree DocC, clone the following repositories: |
| 19 | +# |
| 20 | +# https://github.com/apple/swift-docc |
| 21 | +# https://github.com/apple/swift-docc-render |
| 22 | +# |
| 23 | +# Then set environment variables to paths in their working directories, |
| 24 | +# like the following, before running this script: |
| 25 | +# |
| 26 | +# DOCC_EXEC=~/git/DocC/.build/arm64-apple-macosx/debug/docc |
| 27 | +# DOCC_HTML_DIR=~/git/DocC-Renderer/dist/ |
| 28 | + |
| 29 | +set -eu |
| 30 | + |
| 31 | +REMOTE=${1:-origin} |
| 32 | +CURRENT_COMMIT_HASH="$(git rev-parse --short HEAD)" |
| 33 | + |
| 34 | +# Start at the top level directory of the repository. |
| 35 | +cd "$(git rev-parse --show-toplevel)" |
| 36 | + |
| 37 | +# Check out the 'gh-pages' branch in a subdirectory. |
| 38 | +git worktree add --checkout gh-pages "$REMOTE"/gh-pages |
| 39 | + |
| 40 | +# Pretty print DocC JSON output, so that it has a stable ordering and |
| 41 | +# can be diffed. This lets us determine whether rebuilding resulted in |
| 42 | +# any changes to the content. |
| 43 | +export DOCC_JSON_PRETTYPRINT="YES" |
| 44 | + |
| 45 | +# Build documentation, writing output in the gh-pages/docs subdirectory. |
| 46 | +swift package \ |
| 47 | + --allow-writing-to-directory "./gh-pages/docs" \ |
| 48 | + generate-documentation \ |
| 49 | + --target TSPL \ |
| 50 | + --disable-indexing \ |
| 51 | + --experimental-enable-custom-templates \ |
| 52 | + --hosting-base-path swift-book \ |
| 53 | + --output-path "./gh-pages/docs" |
| 54 | + |
| 55 | +# Commit and push our changes to the gh-pages branch |
| 56 | +pushd gh-pages |
| 57 | +git add docs |
| 58 | + |
| 59 | +if [[ -n "$(git status --porcelain)" ]] |
| 60 | +then |
| 61 | + echo "Found documentation changes." |
| 62 | + echo "Committing the changes to the 'gh-pages' branch and pushing to $REMOTE." |
| 63 | + git commit -m "Update GitHub Pages documentation site to '$CURRENT_COMMIT_HASH'." |
| 64 | + echo |
| 65 | + git push "$REMOTE" HEAD:gh-pages |
| 66 | +else |
| 67 | + echo "No documentation changes found." |
| 68 | +fi |
| 69 | + |
| 70 | +popd |
| 71 | + |
| 72 | +git worktree remove gh-pages |
0 commit comments