Skip to content

Commit a3576e6

Browse files
authored
Add docc support and publish documentation to GitHub pages (apple#137)
* Move Guides into docc base location * Add Github gh-page support * Conditionally add docc-plugin dependency * Temp skip AsyncSequenceValidation target
1 parent 94a7ece commit a3576e6

25 files changed

+136
-1
lines changed

Package.swift

+15
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,18 @@ let package = Package(
4141
]),
4242
]
4343
)
44+
45+
#if canImport(Darwin)
46+
import Darwin
47+
let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil
48+
#elseif canImport(Glibc)
49+
import Glibc
50+
let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil
51+
#else
52+
let buildingDocs = false
53+
#endif
54+
55+
// Only require the docc plugin when building documentation
56+
package.dependencies += buildingDocs ? [
57+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
58+
] : []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# ``AsyncAlgorithms``
2+
3+
**Swift Async Algorithms** is an open-source package of asynchronous sequence and advanced algorithms that involve concurrency, along with their related types.
4+
5+
## Overview
6+
7+
This package has three main goals:
8+
9+
- First-class integration with `async/await`
10+
- Provide a home for time-based algorithms
11+
- Be cross-platform and open source
12+
13+
## Topics
14+
15+
### Getting Started
16+
17+
- <doc:AdjacentPairs>
18+
- <doc:BufferedBytes>
19+
- <doc:Chain>
20+
- <doc:Channel>
21+
- <doc:Chunked>
22+
- <doc:Collections>
23+
- <doc:CombineLatest>
24+
- <doc:Compacted>
25+
- <doc:Debounce>
26+
- <doc:Effects>
27+
- <doc:Intersperse>
28+
- <doc:Joined>
29+
- <doc:Lazy>
30+
- <doc:Merge>
31+
- <doc:Reductions>
32+
- <doc:RemoveDuplicates>
33+
- <doc:Select>
34+
- <doc:Throttle>
35+
- <doc:Timer>
36+
- <doc:Zip>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Guides/Select.md Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Select.md

-1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ This means that `withTaskGroup` is highly suited to run work in parallel, wherea
5050
## Future Directions
5151

5252

53-
5453
## Credits/Inspiration
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ``AsyncSequenceValidation``
2+
3+
4+
## Overview
5+
6+
Testing is a critical area of focus for any package to make it robust, catch bugs, and explain the expected behaviors in a documented manner. Testing things that are asynchronous can be difficult, testing things that are asynchronous multiple times can be even more difficult.
7+
8+
Types that implement `AsyncSequence` can often be described in deterministic actions given particular inputs. For the inputs, the events can be described as a discrete set: values, errors being thrown, the terminal state of returning a `nil` value from the iterator, or advancing in time and not doing anything. Likewise, the expected output has a discrete set of events: values, errors being caught, the terminal state of receiving a `nil` value from the iterator, or advancing in time and not doing anything.
9+
10+
## Topics
11+
12+
### Getting Started
13+
14+
- <doc:Validation>
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
export BUILDING_FOR_DOCUMENTATION_GENERATION=1
20+
21+
set -eu
22+
23+
# A `realpath` alternative using the default C implementation.
24+
filepath() {
25+
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
26+
}
27+
28+
SWIFT_ASYNC_ALGORITHMS_ROOT="$(dirname $(dirname $(filepath $0)))"
29+
30+
ASYNC_ALGORITHMS_BUILD_DIR="$SWIFT_ASYNC_ALGORITHMS_ROOT"/.build/async-algorithms-gh-pages-build
31+
32+
# Set current directory to the repository root
33+
cd "$SWIFT_ASYNC_ALGORITHMS_ROOT"
34+
35+
# Use git worktree to checkout the gh-pages branch of this repository in a gh-pages sub-directory
36+
git fetch
37+
git worktree add --checkout gh-pages origin/gh-pages
38+
39+
# Pretty print DocC JSON output so that it can be consistently diffed between commits
40+
export DOCC_JSON_PRETTYPRINT="YES"
41+
42+
# Generate documentation for the 'AsyncAlgorithms' target and output it
43+
# to the /docs subdirectory in the gh-pages worktree directory.
44+
swift package \
45+
--allow-writing-to-directory "$SWIFT_ASYNC_ALGORITHMS_ROOT/gh-pages/docs" \
46+
generate-documentation \
47+
--target AsyncAlgorithms \
48+
--disable-indexing \
49+
--transform-for-static-hosting \
50+
--hosting-base-path swift-async-algorithms \
51+
--output-path "$SWIFT_ASYNC_ALGORITHMS_ROOT/gh-pages/docs"
52+
53+
# Save the current commit we've just built documentation from in a variable
54+
CURRENT_COMMIT_HASH=`git rev-parse --short HEAD`
55+
56+
# Commit and push our changes to the gh-pages branch
57+
cd gh-pages
58+
git add docs
59+
60+
if [ -n "$(git status --porcelain)" ]; then
61+
echo "Documentation changes found. Commiting the changes to the 'gh-pages' branch and pushing to origin."
62+
git commit -m "Update GitHub Pages documentation site to $CURRENT_COMMIT_HASH"
63+
git push origin HEAD:gh-pages
64+
else
65+
# No changes found, nothing to commit.
66+
echo "No documentation changes found."
67+
fi
68+
69+
# Delete the git worktree we created
70+
cd ..
71+
git worktree remove gh-pages

0 commit comments

Comments
 (0)