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