Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Generate and Deploy DocC to GH pages #949

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/deploy_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: macos-12
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Generate docs
shell: bash
run: |
./generate_docs.sh
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload just docs directory
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@
"version": "3.1.2"
}
},
{
"package": "SwiftDocCPlugin",
"repositoryURL": "https://github.com/apple/swift-docc-plugin",
"state": {
"branch": null,
"revision": "26ac5758409154cc448d7ab82389c520fa8a8247",
"version": "1.3.0"
}
},
{
"package": "SymbolKit",
"repositoryURL": "https://github.com/apple/swift-docc-symbolkit",
"state": {
"branch": null,
"revision": "b45d1f2ed151d057b54504d653e0da5552844e34",
"version": "1.0.0"
}
},
{
"package": "swift-qrcode-generator",
"repositoryURL": "https://github.com/dagronf/swift-qrcode-generator",
Expand Down
52 changes: 52 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"object": {
"pins": [
{
"package": "QRCode",
"repositoryURL": "https://github.com/WalletConnect/QRCode",
"state": {
"branch": null,
"revision": "263f280d2c8144adfb0b6676109846cfc8dd552b",
"version": "14.3.1"
}
},
{
"package": "SwiftDocCPlugin",
"repositoryURL": "https://github.com/apple/swift-docc-plugin",
"state": {
"branch": null,
"revision": "26ac5758409154cc448d7ab82389c520fa8a8247",
"version": "1.3.0"
}
},
{
"package": "SymbolKit",
"repositoryURL": "https://github.com/apple/swift-docc-symbolkit",
"state": {
"branch": null,
"revision": "b45d1f2ed151d057b54504d653e0da5552844e34",
"version": "1.0.0"
}
},
{
"package": "swift-qrcode-generator",
"repositoryURL": "https://github.com/dagronf/swift-qrcode-generator",
"state": {
"branch": null,
"revision": "5ca09b6a2ad190f94aa3d6ddef45b187f8c0343b",
"version": "1.0.3"
}
},
{
"package": "SwiftImageReadWrite",
"repositoryURL": "https://github.com/dagronf/SwiftImageReadWrite",
"state": {
"branch": null,
"revision": "5596407d1cf61b953b8e658fa8636a471df3c509",
"version": "1.1.6"
}
}
]
},
"version": 1
}
8 changes: 6 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let package = Package(
name: "WalletConnect",
platforms: [
.iOS(.v14),
.macOS(.v11),
.macOS(.v12),
.tvOS(.v14)
],
products: [
Expand Down Expand Up @@ -55,6 +55,7 @@ let package = Package(

],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
.package(url: "https://github.com/WalletConnect/QRCode", from: "14.3.1")
],
targets: [
Expand Down Expand Up @@ -134,7 +135,10 @@ let package = Package(
name: "WalletConnectModal",
dependencies: ["QRCode", "WalletConnectSign"],
exclude: ["Secrets/secrets.json.sample"],
resources: [.copy("Secrets/secrets.json")]
resources: [
.copy("Secrets/secrets.json"),
.copy("Resources/Assets.xcassets")
]
),
.target(
name: "WalletConnectSync",
Expand Down
2 changes: 2 additions & 0 deletions Sources/Web3Inbox/WebView/WebViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ final class WebViewFactory {

func create() -> WKWebView {
let configuration = WKWebViewConfiguration()
#if os(iOS)
configuration.allowsInlineMediaPlayback = true
#endif
configuration.userContentController.add(
webviewSubscriber,
name: WebViewRequestSubscriber.chat
Expand Down
118 changes: 118 additions & 0 deletions generate_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

DOCS_BASE_DIR="./docs"

dump=$(swift package dump-package | jq -r '.targets[].name')

IFS=$'\n' read -rd '' -a TARGETS <<<"$dump"

mkdir -p tmp-doc

for target in "${TARGETS[@]}"; do
swift package --allow-writing-to-directory "./tmp-doc/${target}-docs" \
generate-documentation \
--target $target \
--disable-indexing \
--include-extended-types \
--output-path "./tmp-doc/${target}-docs" \
--hosting-base-path WalletConnectSwiftV2
done

rm -rf ${DOCS_BASE_DIR}
is_first=1
for target in "${TARGETS[@]}"; do
if [ $is_first -eq 1 ]; then
echo "Copying initial documentation for ${target}"
cp -R "tmp-doc/${target}-docs" "${DOCS_BASE_DIR}"
is_first=0
else
echo "Merging documentation for ${target}"
cp -R "tmp-doc/${target}-docs/data/documentation/"* "${DOCS_BASE_DIR}/data/documentation/"
cp -R "tmp-doc/${target}-docs/documentation/"* "${DOCS_BASE_DIR}/documentation/"
fi
done
echo "Deleting non-mergable metadata.json"
rm -f "${DOCS_BASE_DIR}/metadata.json"
rm -rf tmp-doc

TARGET_DOCS_DIR='./docs/documentation'
INDEX_FILE='./docs/index.html'
BASE_URL='https://walletconnect.github.io/WalletConnectSwiftV2/documentation'
REPO_NAME='WalletConnectSwiftV2'

target_count=0
target_list=""
single_target_name=""
for target in $(ls "${TARGET_DOCS_DIR}"); do
if [ -d "${TARGET_DOCS_DIR}/${target}" ]; then
single_target_name="${target}"
target_count=$((target_count + 1))
target_list="${target_list}<li><a href=\"${BASE_URL}/${target}\"><code>${target}</code> Documentation</a></li>"
fi
done
if [ ${target_count} -gt 1 ]; then
echo "Found ${target_count} targets. Generating list..."
cat >"${INDEX_FILE}" <<EOF
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #d2d2d2;
}

h1 {
text-align: center;
}

ul {
list-style-type: none;
padding: 0;
}

li {
margin-bottom: 10px;
}

a {
display: block;
padding: 10px;
background-color: #ccc;
text-decoration: none;
color: #337ab7;
border-radius: 5px;
transition: background-color 0.3s ease;
}

a:hover {
background-color: #aaa;
}
</style>
<title>${REPO_NAME} Documentation</title>
</head>
<body>
<h1>${REPO_NAME} Documentation</h1>
<ul>
${target_list}
</ul>
</body>
</html>
EOF
else
echo "Found one target. Generating redirect file to target ${single_target_name}"
cat >"${INDEX_FILE}" <<EOF
<!DOCTYPE html>
<html>
<head>
<title>${REPO_NAME} Documentation</title>
<meta http-equiv="refresh" content="0; url=${BASE_URL}/${single_target_name}" />
</head>
<body>
<p>Redirecting...</p>
</body>
</html>
EOF
fi