GitHub Pages Docsify Deployment Workflow
A reusable workflow that builds and deploys Docsify documentation to GitHub Pages with dynamic URL token replacement for GitHub Pages environment.
Overview
This workflow builds Docsify documentation from the repository and deploys it to GitHub Pages. It replaces the previous Jekyll-based build system with a Docsify-native build process that includes dynamic URL configuration generation, comprehensive asset management, and enhanced error handling. The workflow can be triggered manually or called from other workflows (like CI/CD pipelines).
Features
- Docsify Build System: Native Docsify CLI build process with Node.js environment
- Dynamic URL Configuration: Automatic generation of GitHub Pages-specific URL tokens
- Asset Management: Comprehensive copying of docs/assets, custom styling, and CDN-based plugins
- Build Caching: NPM dependency caching for improved build performance
- Build Validation: Multi-layer verification of HTML structure, plugins, and content
- Error Handling: Comprehensive error reporting with detailed debugging information
- Concurrent Deployment Control: Prevents multiple simultaneous deployments
- Manual and Programmatic Triggering: Can be run manually or called from other workflows
- Secure Deployment: Uses GitHub's deployment system with appropriate permissions
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
source_branch | string | Yes | Branch to build documentation from | main, feature/docs |
deploy_environment | string | Yes | Environment to deploy to | github-pages, staging |
Outputs
| Output Variable | Description | Example |
|---|---|---|
page_url | The URL of the deployed GitHub Pages site | steps.deployment.outputs.page_url |
Dependencies
Required GitHub Permissions
contents: read- To read repository contentpages: write- To deploy to GitHub Pagesid-token: write- For authentication
Required Repository Setup
- GitHub Pages: Must be enabled for the repository
- Node.js Dependencies:
package.jsonwithdocsify-cliin devDependencies - Docsify Configuration:
index.htmlwith Docsify setup - Documentation Structure:
docs/directory with_sidebar.md
Environment Variables
The workflow automatically uses the following GitHub-provided environment variables:
GITHUB_REPOSITORY- Full repository name (owner/repo)GITHUB_REPOSITORY_OWNER- Repository ownerGITHUB_REPOSITORY_NAME- Repository nameSOURCE_BRANCH- Branch being deployed (from input parameter)
Usage
Basic Usage from CI/CD Pipeline
This workflow is typically triggered from another workflow with branch and environment parameters:
jobs:
deploy-docs:
name: Deploy Documentation
needs: [build-and-test]
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/pages-deploy.yml
with:
source_branch: 'main'
deploy_environment: 'github-pages'
secrets: inherit
Feature Branch Documentation
Deploy documentation from a feature branch for preview:
jobs:
deploy-docs-preview:
name: Deploy Documentation Preview
uses: ./.github/workflows/pages-deploy.yml
with:
source_branch: ${{ github.head_ref }}
deploy_environment: 'staging'
secrets: inherit
Manual Triggering
The workflow can be triggered manually from the GitHub Actions tab with custom parameters.
Implementation Details
The workflow consists of two main jobs with comprehensive Docsify build process:
Build Job
-
Environment Setup:
- Checks out the repository from specified source branch
- Sets up Node.js 18 with NPM caching
- Configures GitHub Pages environment
-
Dependency Management:
- Installs NPM dependencies (including docsify-cli)
- Uses caching for improved performance
-
URL Configuration Generation:
- Runs
scripts/Generate-GitHubPagesConfig.ps1 - Generates GitHub Pages-specific URL tokens
- Replaces local development URLs with production URLs
- Runs
-
Docsify Build Process:
- Creates
_sitedirectory for build output - Copies
index.htmland generateddocsify-url-config.js - Copies complete
docs/directory with all content - Copies assets (images, CSS, JS) if present
- Copies additional static files (
robots.txt,sitemap.xml, etc.) - Creates
.nojekyllfile to prevent Jekyll processing
- Creates
-
Build Validation:
- Verifies critical files are present
- Checks HTML structure and Docsify configuration
- Validates plugin references and sidebar content
- Reports build statistics and potential issues
-
Artifact Upload:
- Uploads the complete
_sitedirectory as a deployment artifact
- Uploads the complete
Deploy Job
- GitHub Pages Deployment:
- Uses
actions/deploy-pages@v4for deployment - Provides the deployed site URL as output
- Uses
Key Features
Dynamic URL Token Replacement
The workflow generates environment-specific URL configuration:
// Generated docsify-url-config.js for GitHub Pages
window.EDGE_AI_URL_CONFIG = {
context: 'github-pages',
variables: {
"REPO_URL": "https://github.com/owner/repo",
"REPO_BASE_URL": "https://github.com/owner/repo/blob/main",
"DOCS_BASE_URL": "https://owner.github.io/repo",
"CLONE_URL": "https://github.com/owner/repo.git",
"NEW_ISSUE_URL": "https://github.com/owner/repo/issues/new"
}
};
Build Caching Strategy
- NPM dependencies cached based on
package-lock.jsonhash - Node.js setup action includes built-in caching
- Reduces build times significantly for subsequent runs
Comprehensive Error Handling
- Fail-fast approach for critical build failures
- Detailed error reporting with debug information
- Graceful handling of optional components (assets, additional files)
Examples
Example 1: Integration with CI Pipeline
name: CI/CD Pipeline
on:
push:
branches: [main]
paths:
- 'docs/**'
- 'src/**/*.md'
- 'index.html'
- 'docsify-url-config.js'
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
# Build and test steps here
deploy-docs:
name: Deploy Documentation
needs: [build-and-test]
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/pages-deploy.yml
with:
source_branch: 'main'
deploy_environment: 'github-pages'
secrets: inherit
Example 2: Multi-Environment Deployment
jobs:
# Deploy to staging for all branches
deploy-docs-staging:
name: Deploy Documentation (Staging)
if: github.ref != 'refs/heads/main'
uses: ./.github/workflows/pages-deploy.yml
with:
source_branch: ${{ github.ref_name }}
deploy_environment: 'staging'
secrets: inherit
# Deploy to production for main branch only
deploy-docs-production:
name: Deploy Documentation (Production)
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/pages-deploy.yml
with:
source_branch: 'main'
deploy_environment: 'github-pages'
secrets: inherit
Troubleshooting
Common Issues
-
Build Failures
Problem: Docsify build process fails with missing dependencies
Solution:
- Ensure
docsify-cliis listed inpackage.jsondevDependencies - Verify
package-lock.jsonis committed to repository - Check Node.js version compatibility (workflow uses Node.js 18)
- Ensure
-
URL Token Replacement Not Working
Problem: Links in deployed documentation still show local URLs
Solution:
- Verify
scripts/Generate-GitHubPagesConfig.ps1exists and is executable - Check that markdown content uses token format:
{{REPO_URL}} - Ensure
docsify-url-config.jsis properly loaded inindex.html
- Verify
-
Missing Assets or Styling
Problem: Images or custom styling not appearing in deployed site
Solution:
- Verify assets are in
docs/assets/directory - Check that
index.htmlreferences are relative paths - Ensure CDN-based plugins are accessible (check browser console)
- Verify assets are in
-
Navigation or Sidebar Issues
Problem: Navigation menu not working or sidebar empty
Solution:
- Verify
docs/_sidebar.mdexists and contains valid navigation - Check Docsify configuration in
index.htmlfor sidebar settings - Ensure markdown files referenced in sidebar actually exist
- Verify
-
GitHub Pages Not Updating
Problem: Deployed site not reflecting latest changes
Solution:
- Check workflow run logs for deployment status
- Verify GitHub Pages is enabled in repository settings
- Confirm workflow has required permissions (
pages: write,id-token: write) - Check if
.nojekyllfile is present to prevent Jekyll processing
-
Build Performance Issues
Problem: Long build times or frequent cache misses
Solution:
- Verify NPM caching is working (check workflow logs)
- Consider reducing documentation size or splitting large files
- Check for unnecessary files being copied in build process
Debug Information
When troubleshooting, check the following in workflow logs:
- Environment Variables: Repository, owner, branch information
- Build Statistics: Number of files, total size of build output
- Validation Results: Critical file checks, plugin verification
- Cache Status: NPM cache hit/miss information
Migration from Jekyll
If migrating from a Jekyll-based Pages deployment:
-
Remove Jekyll Dependencies:
- Delete
_config.ymlfile - Remove Jekyll-specific front matter from markdown files
- Update any Jekyll-specific templating
- Delete
-
Update Workflow:
- Replace Jekyll build steps with this Docsify workflow
- Update any references to Jekyll build outputs
-
Configure Docsify:
- Ensure
index.htmlcontains proper Docsify configuration - Create
docs/_sidebar.mdfor navigation - Test URL token replacement locally before deployment
- Ensure
Related Workflows
- Main CI/CD Workflow: Triggers this workflow when documentation changes
- Documentation Generation Scripts: May generate content before deployment
Learn More
- Docsify Documentation
- GitHub Pages Documentation
- GitHub Actions Documentation
- GitHub Pages GitHub Action
🤖 Crafted with precision by ✨Copilot following brilliant human instruction, then carefully refined by our team of discerning human reviewers.