1+ # Workflow for building and deploying MkDocs documentation with Terraform docs to GitHub Pages
2+ name : Deploy Documentation to Pages
3+
4+ on :
5+ # Runs on pushes targeting the default branch
6+ push :
7+ branches : [main]
8+ paths :
9+ - ' docs/**'
10+ - ' mkdocs.yml'
11+ - ' *.tf'
12+ - ' modules/**/*.tf'
13+ - ' schemas/**'
14+ - ' .github/workflows/deploy_docs.yml'
15+
16+ pull_request :
17+ types : [opened, synchronize]
18+ paths :
19+ - ' docs/**'
20+ - ' mkdocs.yml'
21+ - ' *.tf'
22+ - ' modules/**/*.tf'
23+ - ' schemas/**'
24+
25+ # Allows you to run this workflow manually from the Actions tab
26+ workflow_dispatch :
27+
28+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
29+ permissions :
30+ contents : read
31+ pages : write
32+ id-token : write
33+
34+ # Allow one concurrent deployment
35+ concurrency :
36+ group : " pages"
37+ cancel-in-progress : true
38+
39+ # Default to bash
40+ defaults :
41+ run :
42+ shell : bash
43+
44+ jobs :
45+ # Build job
46+ build :
47+ runs-on : ubuntu-latest
48+ env :
49+ TERRAFORM_DOCS_VERSION : v0.20.0
50+ steps :
51+ - name : Checkout
52+ uses : actions/checkout@v4
53+ with :
54+ fetch-depth : 0 # Full history for git revision dates
55+
56+ - name : Setup Python
57+ uses : actions/setup-python@v5
58+ with :
59+ python-version : ' 3.12'
60+ cache : ' pip'
61+ cache-dependency-path : ' docs/requirements.txt'
62+
63+ - name : Install MkDocs and dependencies
64+ run : |
65+ pip install -r docs/requirements.txt
66+
67+ - name : Install terraform-docs
68+ run : |
69+ wget -O /tmp/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/${TERRAFORM_DOCS_VERSION}/terraform-docs-${TERRAFORM_DOCS_VERSION}-linux-amd64.tar.gz
70+ tar -xzf /tmp/terraform-docs.tar.gz -C /tmp
71+ sudo mv /tmp/terraform-docs /usr/local/bin/
72+ chmod +x /usr/local/bin/terraform-docs
73+ terraform-docs --version
74+
75+ - name : Generate Terraform documentation
76+ run : |
77+ # Generate main module docs
78+ terraform-docs markdown table . > docs/reference/terraform.md
79+
80+ # Generate submodule docs
81+ for dir in modules/*/; do
82+ module_name=$(basename $dir)
83+ terraform-docs markdown table $dir > docs/reference/module-${module_name}.md
84+ done
85+
86+ - name : Setup Pages
87+ id : pages
88+ uses : actions/configure-pages@v5
89+
90+ - name : Build with MkDocs
91+ run : |
92+ mkdocs build --strict --site-dir ./site
93+
94+ - name : Upload artifact
95+ uses : actions/upload-pages-artifact@v3
96+ with :
97+ path : ./site
98+
99+ # Deployment job
100+ deploy :
101+ if : github.event_name == 'push' || github.event.pull_request.merged == true
102+ environment :
103+ name : github-pages
104+ url : ${{ steps.deployment.outputs.page_url }}
105+ runs-on : ubuntu-latest
106+ needs : build
107+ steps :
108+ - name : Deploy to GitHub Pages
109+ id : deployment
110+ uses : actions/deploy-pages@v4
0 commit comments