Skip to content

Commit f871ab4

Browse files
authored
GH action build docs (#118)
1 parent 52b83fb commit f871ab4

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

.github/workflows/gen-docs.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Generate Documentation
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
11+
runs-on: macOS-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
- name: Install Dependencies
19+
run: |
20+
brew install mint
21+
mint install apple/swift-docc@main
22+
echo "$HOME/.mint/bin" >> $GITHUB_PATH
23+
- name: Build
24+
env:
25+
DOCC: docc
26+
run: |
27+
./scripts/build-docc.sh
28+
- name: Commit
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
REMOTE_BRANCH: "gh-pages"
32+
run: |
33+
REMOTE_REPO="https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
34+
git config user.name "${GITHUB_ACTOR}"
35+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
36+
37+
mv docs _docs
38+
git checkout ${REMOTE_BRANCH}
39+
rm -rf docs/
40+
mv _docs/mqtt-nio docs
41+
42+
git add --all docs
43+
git status
44+
git commit -m "Documentation for https://github.com/${GITHUB_REPOSITORY}/tree/${GITHUB_SHA}" -m "Generated by gen-docs.yml"
45+
git push ${REMOTE_REPO} ${REMOTE_BRANCH}
46+

scripts/build-docc.sh

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
#!/usr/bin/env bash
22

3-
DOCC=$(xcrun --find docc)
4-
export DOCC_HTML_DIR="$(dirname $DOCC)/../share/docc/render"
3+
# if plugin worked for us then would use it over everything below
4+
usePlugin()
5+
{
6+
mkdir -p ./docs/mqtt-nio
7+
8+
swift package \
9+
--allow-writing-to-directory ./docs \
10+
generate-documentation \
11+
--target MQTTNIO \
12+
--output-path ./docs/mqtt-nio \
13+
--transform-for-static-hosting \
14+
--hosting-base-path /mqtt-nio
15+
}
16+
17+
TEMP_DIR="$(pwd)/temp"
18+
19+
cleanup()
20+
{
21+
if [ -n "$TEMP_DIR" ]; then
22+
rm -rf $TEMP_DIR
23+
fi
24+
}
25+
trap cleanup exit $?
26+
527
SG_FOLDER=.build/symbol-graphs
628
MQTTNIO_SG_FOLDER=.build/mqtt-nio-symbol-graphs
7-
OUTPUT_PATH=docs/mqtt-nio
29+
OUTPUT_PATH=docs/mqtt-nio/
830

931
BUILD_SYMBOLS=1
1032

@@ -15,6 +37,11 @@ do
1537
esac
1638
done
1739

40+
if [ -z "${DOCC_HTML_DIR:-}" ]; then
41+
git clone https://github.com/apple/swift-docc-render-artifact $TEMP_DIR/swift-docc-render-artifact
42+
export DOCC_HTML_DIR="$TEMP_DIR/swift-docc-render-artifact/dist"
43+
fi
44+
1845
if test "$BUILD_SYMBOLS" == 1; then
1946
# build symbol graphs
2047
mkdir -p $SG_FOLDER
@@ -23,7 +50,7 @@ if test "$BUILD_SYMBOLS" == 1; then
2350
-Xswiftc -emit-symbol-graph-dir -Xswiftc $SG_FOLDER
2451
# Copy MQTTNIO symbol graph into separate folder
2552
mkdir -p $MQTTNIO_SG_FOLDER
26-
cp -f $SG_FOLDER/MQTTNIO* $MQTTNIO_SG_FOLDER
53+
cp $SG_FOLDER/MQTTNIO* $MQTTNIO_SG_FOLDER
2754
fi
2855

2956
# Build documentation

0 commit comments

Comments
 (0)