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 thats 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
+
19
+ set -eu
20
+
21
+ # A `realpath` alternative using the default C implementation.
22
+ filepath () {
23
+ [[ $1 = /* ]] && echo " $1 " || echo " $PWD /${1# ./ } "
24
+ }
25
+
26
+ SWIFT_SYNTAX_ROOT=" $( dirname $( dirname $( filepath $0 ) ) ) "
27
+
28
+ SWIFT_SYNTAX_BUILD_DIR=" $SWIFT_SYNTAX_ROOT " /.build/swift-syntax-gh-pages-build
29
+ SWIFT_SYNTAX_BUILDER_OUTPUT_DIR=" $SWIFT_SYNTAX_BUILD_DIR " /swift-syntax-builder-docs
30
+
31
+ mkdir -p " $SWIFT_SYNTAX_BUILDER_OUTPUT_DIR "
32
+
33
+ # Set current directory to the repository root
34
+ cd " $SWIFT_SYNTAX_ROOT "
35
+
36
+ # Use git worktree to checkout the gh-pages branch of this repository in a gh-pages sub-directory
37
+ git fetch
38
+ git worktree add --checkout gh-pages origin/gh-pages
39
+
40
+ # Pretty print DocC JSON output so that it can be consistently diffed between commits
41
+ export DOCC_JSON_PRETTYPRINT=" YES"
42
+
43
+ # Generate documentation for the 'SwiftSyntax' target and output it
44
+ # to the /docs subdirectory in the gh-pages worktree directory.
45
+ swift package \
46
+ --allow-writing-to-directory " $SWIFT_SYNTAX_ROOT /gh-pages/docs" \
47
+ generate-documentation \
48
+ --target SwiftSyntax \
49
+ --disable-indexing \
50
+ --transform-for-static-hosting \
51
+ --hosting-base-path swift-syntax \
52
+ --output-path " $SWIFT_SYNTAX_ROOT /gh-pages/docs"
53
+
54
+ # Generate documentation for the 'SwiftSyntaxBuilder' target and output it
55
+ # to a temporary output directory in the .build directory.
56
+ swift package \
57
+ --allow-writing-to-directory " $SWIFT_SYNTAX_BUILD_DIR " \
58
+ generate-documentation \
59
+ --target SwiftSyntaxBuilder \
60
+ --disable-indexing \
61
+ --transform-for-static-hosting \
62
+ --hosting-base-path swift-syntax \
63
+ --output-path " $SWIFT_SYNTAX_BUILDER_OUTPUT_DIR "
64
+
65
+ # Merge the SwiftSyntaxBuilder docs into the primary SwiftSyntax docs
66
+ cp -R " $SWIFT_SYNTAX_BUILDER_OUTPUT_DIR " /* " $SWIFT_SYNTAX_ROOT /gh-pages/docs/"
67
+
68
+ # Save the current commit we've just built documentation from in a variable
69
+ CURRENT_COMMIT_HASH=` git rev-parse --short HEAD`
70
+
71
+ # Commit and push our changes to the gh-pages branch
72
+ cd gh-pages
73
+ git add docs
74
+
75
+ if [ -n " $( git status --porcelain) " ]; then
76
+ echo " Documentation changes found. Commiting the changes to the 'gh-pages' branch and pushing to origin."
77
+ git commit -m " Update GitHub Pages documentation site to $CURRENT_COMMIT_HASH "
78
+ git push origin HEAD:gh-pages
79
+ else
80
+ # No changes found, nothing to commit.
81
+ echo " No documentation changes found."
82
+ fi
83
+
84
+ # Delete the git worktree we created
85
+ cd ..
86
+ git worktree remove gh-pages
0 commit comments