Skip to content

Fix update-docs workflow #103

Fix update-docs workflow

Fix update-docs workflow #103

Workflow file for this run

name: Update Docs
on:
push:
branches: [ main ]
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- name: Swift version
run: swift --version
- uses: actions/checkout@v4
- name: Compile Docs
run: |
set -eux
# Clone existing gh-pages branch to gh-pages subdirectory
git config user.email "[email protected]"
git config user.name "stackotter"
git fetch
git worktree add --checkout gh-pages origin/gh-pages
# Clone custom DocC with TOML syntax highlighting support
git clone https://github.com/stackotter/swift-docc-render-artifact ../swift-docc-render-artifact
# Render documentation
export DOCC_JSON_PRETTYPRINT="YES"
export SWIFTPM_ENABLE_COMMAND_PLUGINS=1
export DOCC_HTML_DIR=../swift-docc-render-artifact/dist
swift package \
--allow-writing-to-directory gh-pages/docs \
generate-documentation \
--target swift-bundler \
--disable-indexing \
--transform-for-static-hosting \
--output-path gh-pages/docs
CURRENT_COMMIT_HASH=`git rev-parse --short HEAD`
cd gh-pages
# Inject our site at the index
rm docs/index.html
rm docs/favicon.ico
cp index.html docs
cp favicon.ico docs
cp CNAME docs
cp css/main.css docs/css
cp -R image docs
# Patch target name from swift_bundler to swift-bundler
mv docs/documentation/swift_bundler/index.html docs/documentation/swift-bundler
mv docs/data/documentation/swift_bundler.json docs/data/documentation/swift-bundler.json
# On macOS, replace `-i` with `-i '' -e`
LC_ALL=C find docs -type f -exec sed -i 's/swift_bundler/swift-bundler/g' {} \;
# Commit changes back to gh-pages branch if there any
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
echo "No documentation changes found."
fi