GitHub Actions Setup
GitHub Actions Setup Guide
Overview
This project includes a fully automated CI/CD pipeline using GitHub Actions that automatically lints Python code, builds the Hugo documentation site, and deploys it to GitHub Pages on every push to the main branch.
Workflow Architecture
graph TB
A[Push to main] --> B[Trigger Workflow]
B --> C[Job 1: Lint]
C --> D{Lint Pass?}
D -->|Yes| E[Job 2: Build]
D -->|No| F[Workflow Fails]
E --> G{Build Success?}
G -->|Yes| H[Job 3: Deploy]
G -->|No| F
H --> I[GitHub Pages Updated]
style A fill:#2ecc71
style C fill:#3498db
style E fill:#9b59b6
style H fill:#e67e22
style I fill:#1abc9c
style F fill:#e74c3cWorkflow File
The workflow is defined in .github/workflows/deploy.yml:
Three Pipeline Jobs
Job 1: Lint Python Code
Purpose: Ensure code quality before deployment
What it does:
- Checks out the repository
- Sets up Python 3.11
- Installs
flake8linter - Runs two-pass linting:
- Strict pass: Fails on syntax errors and undefined names
- Warning pass: Reports style issues without failing
Configuration:
Error Codes Checked:
E9: Runtime errors (syntax, indentation)F63: Invalid print statement usageF7: Syntax errors in statementsF82: Undefined names in__all__
Job 2: Build Hugo Documentation
Purpose: Generate static documentation site
What it does:
- Checks out repository with submodules (Hugo theme)
- Installs Hugo 0.141.0 Extended
- Builds the documentation site with minification
- Uploads built site as artifact for deployment
Key features:
Why submodules: recursive?
- The Relearn theme is installed as a Git submodule
- Without this, the build would fail with “theme not found”
Why fetch-depth: 0?
- Allows Hugo to access Git history
- Enables
.GitInfo(commit info) and.Lastmod(last modified dates)
Job 3: Deploy to GitHub Pages
Purpose: Publish documentation to GitHub Pages
What it does:
- Waits for build job to complete successfully
- Deploys artifact to GitHub Pages
- Returns deployment URL
Configuration:
Enabling GitHub Pages
Required Configuration
Before the workflow can deploy, you must enable GitHub Pages in your repository settings.
Step-by-Step Setup
1. Push the workflow to GitHub:
2. Enable GitHub Pages:
- Go to your repository on GitHub
- Click Settings → Pages (in left sidebar)
- Under “Build and deployment”:
- Source: Select “GitHub Actions”
- (NOT “Deploy from a branch”)
- Click Save
3. Configure Pages Permissions (if needed):
- Go to Settings → Actions → General
- Scroll to “Workflow permissions”
- Select Read and write permissions
- Check Allow GitHub Actions to create and approve pull requests
- Click Save
4. Trigger the workflow:
- Automatic: Push any commit to
mainbranch - Manual: Go to Actions tab → Select “Build & Deploy Documentation” → Click “Run workflow”
5. Verify deployment:
- Go to Actions tab
- Click on the latest workflow run
- Check that all three jobs (lint, build, deploy) completed successfully
- Visit your GitHub Pages URL (shown in deploy job output)
Your Documentation URL
After successful deployment, your documentation will be available at:
Example:
- Repository:
github.com/karmen87/Crypto_Alarm - Documentation URL:
https://karmen87.github.io/Crypto_Alarm/
Workflow Permissions
The workflow requires specific permissions defined in the YAML file:
These permissions allow the workflow to:
- ✅ Read source code and documentation files
- ✅ Build the Hugo site
- ✅ Deploy to GitHub Pages environment
Concurrency Control
What this does:
- Only one deployment can run at a time
- If a new deployment starts while one is running, it waits (doesn’t cancel)
- Prevents race conditions and partial deployments
Manual Triggering
The workflow includes workflow_dispatch trigger:
To manually trigger:
- Go to Actions tab on GitHub
- Select “Build & Deploy Documentation”
- Click “Run workflow” button
- Select branch (usually
main) - Click “Run workflow”
Use cases:
- Rebuild documentation after GitHub Pages settings change
- Force rebuild without pushing new commits
- Test workflow after modifications
Monitoring Workflow Runs
Viewing Logs
- Go to Actions tab
- Click on a workflow run
- Click on individual jobs (lint, build, deploy)
- Expand steps to see detailed logs
Common Log Sections
Lint job:
Build job:
Deploy job:
Troubleshooting
Workflow Fails on Lint Job
Python Linting Errors
Error: E9,F63,F7,F82 errors cause build failure
Solution:
Workflow Fails on Build Job
Error: theme not found
Solution: Ensure Git submodule is initialized
Error: hugo: command not found
Solution: This shouldn’t happen with actions-hugo@v3, but if it does:
- Check Hugo version in workflow matches available version
- Verify
extended: trueis set (required for Relearn theme)
Workflow Fails on Deploy Job
Error: Resource not accessible by integration
Solution: Check permissions in repository settings
- Settings → Actions → General
- Enable “Read and write permissions”
- Re-run workflow
Error: Page build failed
Solution: Ensure GitHub Pages source is set to “GitHub Actions”
- Settings → Pages
- Source: GitHub Actions (not “Deploy from a branch”)
Workflow Performance
Typical Run Times
| Job | Average Duration | Cache Impact |
|---|---|---|
| Lint | 30-45 seconds | 15s with cache |
| Build | 1-2 minutes | 30s with cache |
| Deploy | 30-60 seconds | N/A |
| Total | 2-4 minutes | ~1.5 minutes |
Optimization Tips
1. Enable caching (already configured):
2. Conditional execution:
3. Parallel jobs (if adding more checks):
Cost & Usage
GitHub Actions Minutes:
- Public repositories: Unlimited free minutes
- Private repositories: 2,000 free minutes/month
This workflow uses:
- ~3 minutes per run
- If you push 100 times/month: ~300 minutes
- Well within free tier limits
Adding Status Badge
Show workflow status in your README:
Security Considerations
Secrets Management
This workflow doesn’t use custom secrets (uses built-in GITHUB_TOKEN).
If you need to add secrets:
- Settings → Secrets and variables → Actions
- Click “New repository secret”
- Add secret name and value
- Reference in workflow:
${{ secrets.SECRET_NAME }}
Dependency Security
Dependabot configuration (optional):
Create .github/dependabot.yml:
This keeps GitHub Actions dependencies up-to-date.
Custom Domain (Optional)
To use a custom domain for documentation:
1. Add CNAME file:
2. Configure DNS:
- Add CNAME record:
docs.your-domain.com→<username>.github.io
3. Enable in GitHub:
- Settings → Pages
- Enter custom domain
- Check “Enforce HTTPS”
Next Steps
- Review CI/CD Pipeline documentation for more advanced workflows
- Explore DevOps section for testing and deployment strategies
- Check Implementations for application-specific details
Your documentation is now automatically deployed on every push to main! 🚀