Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@swolfand
Copy link

@swolfand swolfand commented Jul 9, 2025

Add a GitHub Action to automatically generate Swift-DocC HTML documentation and push it to a dedicated docs branch.


Slack Thread

@swolfand swolfand enabled auto-merge (squash) July 9, 2025 06:19
Comment on lines +17 to +116
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Swift
uses: swift-actions/setup-swift@v1
with:
swift-version: '5.9'

- name: Cache Swift packages
uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-swift-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-swift-

- name: Build package
run: swift build

- name: Generate documentation
run: |
# Generate documentation for the Clerk target
swift package generate-documentation \
--target Clerk \
--disable-indexing \
--transform-for-static-hosting \
--hosting-base-path Clerk \
--output-path ./docs

- name: Setup docs directory structure
run: |
# Create a clean docs directory structure
mkdir -p ./docs-output

# Copy the generated documentation
if [ -d "./docs" ]; then
cp -r ./docs/* ./docs-output/
fi

# Create index.html if it doesn't exist
if [ ! -f "./docs-output/index.html" ]; then
cat > ./docs-output/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
<title>Clerk Documentation</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 40px; }
.header { text-align: center; margin-bottom: 40px; }
.links { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; }
.link { padding: 10px 20px; background: #007AFF; color: white; text-decoration: none; border-radius: 8px; }
.link:hover { background: #0056CC; }
</style>
</head>
<body>
<div class="header">
<h1>Clerk Documentation</h1>
<p>Swift Package Documentation</p>
</div>
<div class="links">
<a href="./documentation/clerk/" class="link">Browse Documentation</a>
</div>
</body>
</html>
EOF
fi

- name: Deploy to docs branch
run: |
# Configure git
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

# Create/checkout docs branch
git checkout --orphan docs || git checkout docs

# Remove all files except docs-output
git rm -rf . 2>/dev/null || true

# Copy documentation files to root
cp -r ./docs-output/* . 2>/dev/null || true

# Add and commit all documentation files
git add .

# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi

git commit -m "📚 Update documentation ($(date '+%Y-%m-%d %H:%M:%S'))"

# Push to docs branch
git push origin docs --force

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 4 months ago

To fix the issue, we will add a permissions block at the root of the workflow file. This block will explicitly define the minimal permissions required for the workflow to function. Based on the workflow's actions, it needs contents: write to push changes to the docs branch and contents: read to access the repository's files. These permissions will be applied to all jobs in the workflow.


Suggested changeset 1
.github/workflows/docs.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -2,2 +2,5 @@
 
+permissions:
+  contents: write
+
 on:
EOF
@@ -2,2 +2,5 @@

permissions:
contents: write

on:
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants