From a3576e669ba8316143646d08bcfad941171979b0 Mon Sep 17 00:00:00 2001 From: Kyle <43724855+Kyle-Ye@users.noreply.github.com> Date: Tue, 12 Apr 2022 05:25:33 +0800 Subject: [PATCH] Add docc support and publish documentation to GitHub pages (#137) * Move Guides into docc base location * Add Github gh-page support * Conditionally add docc-plugin dependency * Temp skip AsyncSequenceValidation target --- Package.swift | 15 ++++ .../AsyncAlgorithms.docc/AsyncAlgorithms.md | 36 ++++++++++ .../Guides}/AdjacentPairs.md | 0 .../Guides}/BufferedBytes.md | 0 .../AsyncAlgorithms.docc/Guides}/Chain.md | 0 .../AsyncAlgorithms.docc/Guides}/Channel.md | 0 .../AsyncAlgorithms.docc/Guides}/Chunked.md | 0 .../Guides}/Collections.md | 0 .../Guides}/CombineLatest.md | 0 .../AsyncAlgorithms.docc/Guides}/Compacted.md | 0 .../AsyncAlgorithms.docc/Guides}/Debounce.md | 0 .../AsyncAlgorithms.docc/Guides}/Effects.md | 0 .../Guides}/Intersperse.md | 0 .../AsyncAlgorithms.docc/Guides}/Joined.md | 0 .../AsyncAlgorithms.docc/Guides}/Lazy.md | 0 .../AsyncAlgorithms.docc/Guides}/Merge.md | 0 .../Guides}/Reductions.md | 0 .../Guides}/RemoveDuplicates.md | 0 .../AsyncAlgorithms.docc/Guides}/Select.md | 1 - .../AsyncAlgorithms.docc/Guides}/Throttle.md | 0 .../AsyncAlgorithms.docc/Guides}/Timer.md | 0 .../AsyncAlgorithms.docc/Guides}/Zip.md | 0 .../AsyncSequenceValidation.md | 14 ++++ .../Validation.md | 0 bin/update-gh-pages-documentation-site | 71 +++++++++++++++++++ 25 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 Sources/AsyncAlgorithms/AsyncAlgorithms.docc/AsyncAlgorithms.md rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/AdjacentPairs.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/BufferedBytes.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Chain.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Channel.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Chunked.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Collections.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/CombineLatest.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Compacted.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Debounce.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Effects.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Intersperse.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Joined.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Lazy.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Merge.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Reductions.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/RemoveDuplicates.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Select.md (99%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Throttle.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Timer.md (100%) rename {Guides => Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides}/Zip.md (100%) create mode 100644 Sources/AsyncSequenceValidation/AsyncSequenceValidation.docc/AsyncSequenceValidation.md rename {Guides => Sources/AsyncSequenceValidation/AsyncSequenceValidation.docc}/Validation.md (100%) create mode 100755 bin/update-gh-pages-documentation-site diff --git a/Package.swift b/Package.swift index fd3a36f..afc2378 100644 --- a/Package.swift +++ b/Package.swift @@ -41,3 +41,18 @@ let package = Package( ]), ] ) + +#if canImport(Darwin) +import Darwin +let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil +#elseif canImport(Glibc) +import Glibc +let buildingDocs = getenv("BUILDING_FOR_DOCUMENTATION_GENERATION") != nil +#else +let buildingDocs = false +#endif + +// Only require the docc plugin when building documentation +package.dependencies += buildingDocs ? [ + .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), +] : [] diff --git a/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/AsyncAlgorithms.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/AsyncAlgorithms.md new file mode 100644 index 0000000..8a0cbbf --- /dev/null +++ b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/AsyncAlgorithms.md @@ -0,0 +1,36 @@ +# ``AsyncAlgorithms`` + +**Swift Async Algorithms** is an open-source package of asynchronous sequence and advanced algorithms that involve concurrency, along with their related types. + +## Overview + +This package has three main goals: + +- First-class integration with `async/await` +- Provide a home for time-based algorithms +- Be cross-platform and open source + +## Topics + +### Getting Started + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- diff --git a/Guides/AdjacentPairs.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/AdjacentPairs.md similarity index 100% rename from Guides/AdjacentPairs.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/AdjacentPairs.md diff --git a/Guides/BufferedBytes.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/BufferedBytes.md similarity index 100% rename from Guides/BufferedBytes.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/BufferedBytes.md diff --git a/Guides/Chain.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Chain.md similarity index 100% rename from Guides/Chain.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Chain.md diff --git a/Guides/Channel.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Channel.md similarity index 100% rename from Guides/Channel.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Channel.md diff --git a/Guides/Chunked.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Chunked.md similarity index 100% rename from Guides/Chunked.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Chunked.md diff --git a/Guides/Collections.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Collections.md similarity index 100% rename from Guides/Collections.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Collections.md diff --git a/Guides/CombineLatest.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/CombineLatest.md similarity index 100% rename from Guides/CombineLatest.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/CombineLatest.md diff --git a/Guides/Compacted.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Compacted.md similarity index 100% rename from Guides/Compacted.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Compacted.md diff --git a/Guides/Debounce.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Debounce.md similarity index 100% rename from Guides/Debounce.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Debounce.md diff --git a/Guides/Effects.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Effects.md similarity index 100% rename from Guides/Effects.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Effects.md diff --git a/Guides/Intersperse.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Intersperse.md similarity index 100% rename from Guides/Intersperse.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Intersperse.md diff --git a/Guides/Joined.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Joined.md similarity index 100% rename from Guides/Joined.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Joined.md diff --git a/Guides/Lazy.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Lazy.md similarity index 100% rename from Guides/Lazy.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Lazy.md diff --git a/Guides/Merge.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Merge.md similarity index 100% rename from Guides/Merge.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Merge.md diff --git a/Guides/Reductions.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Reductions.md similarity index 100% rename from Guides/Reductions.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Reductions.md diff --git a/Guides/RemoveDuplicates.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/RemoveDuplicates.md similarity index 100% rename from Guides/RemoveDuplicates.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/RemoveDuplicates.md diff --git a/Guides/Select.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Select.md similarity index 99% rename from Guides/Select.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Select.md index 0598201..fb0389c 100644 --- a/Guides/Select.md +++ b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Select.md @@ -50,5 +50,4 @@ This means that `withTaskGroup` is highly suited to run work in parallel, wherea ## Future Directions - ## Credits/Inspiration diff --git a/Guides/Throttle.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Throttle.md similarity index 100% rename from Guides/Throttle.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Throttle.md diff --git a/Guides/Timer.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Timer.md similarity index 100% rename from Guides/Timer.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Timer.md diff --git a/Guides/Zip.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Zip.md similarity index 100% rename from Guides/Zip.md rename to Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Zip.md diff --git a/Sources/AsyncSequenceValidation/AsyncSequenceValidation.docc/AsyncSequenceValidation.md b/Sources/AsyncSequenceValidation/AsyncSequenceValidation.docc/AsyncSequenceValidation.md new file mode 100644 index 0000000..e1c0d3f --- /dev/null +++ b/Sources/AsyncSequenceValidation/AsyncSequenceValidation.docc/AsyncSequenceValidation.md @@ -0,0 +1,14 @@ +# ``AsyncSequenceValidation`` + + +## Overview + +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. + +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. + +## Topics + +### Getting Started + +- diff --git a/Guides/Validation.md b/Sources/AsyncSequenceValidation/AsyncSequenceValidation.docc/Validation.md similarity index 100% rename from Guides/Validation.md rename to Sources/AsyncSequenceValidation/AsyncSequenceValidation.docc/Validation.md diff --git a/bin/update-gh-pages-documentation-site b/bin/update-gh-pages-documentation-site new file mode 100755 index 0000000..0c1e59a --- /dev/null +++ b/bin/update-gh-pages-documentation-site @@ -0,0 +1,71 @@ +#!/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. +# + +export BUILDING_FOR_DOCUMENTATION_GENERATION=1 + +set -eu + +# A `realpath` alternative using the default C implementation. +filepath() { + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" +} + +SWIFT_ASYNC_ALGORITHMS_ROOT="$(dirname $(dirname $(filepath $0)))" + +ASYNC_ALGORITHMS_BUILD_DIR="$SWIFT_ASYNC_ALGORITHMS_ROOT"/.build/async-algorithms-gh-pages-build + +# Set current directory to the repository root +cd "$SWIFT_ASYNC_ALGORITHMS_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 'AsyncAlgorithms' target and output it +# to the /docs subdirectory in the gh-pages worktree directory. +swift package \ + --allow-writing-to-directory "$SWIFT_ASYNC_ALGORITHMS_ROOT/gh-pages/docs" \ + generate-documentation \ + --target AsyncAlgorithms \ + --disable-indexing \ + --transform-for-static-hosting \ + --hosting-base-path swift-async-algorithms \ + --output-path "$SWIFT_ASYNC_ALGORITHMS_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. Commiting 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