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