Skip to content

Commit 4dea60c

Browse files
authored
Docs collate for GitHub Actions (#556)
Documents collate for GitHub Actions
1 parent 461fe2f commit 4dea60c

33 files changed

+565
-144
lines changed

.github/workflows/website-deploy-preview.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ jobs:
7777
run: |
7878
./scripts/render-docs-for-modules.sh
7979
80+
- name: "Render Documentation for GitHub Actions"
81+
env:
82+
PUBLIC_REPO_ACCESS_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
83+
run: |
84+
./scripts/render-docs-for-github-actions.sh
85+
8086
- name: Install Dependencies and Build Website
8187
env:
8288
GOOGLE_TAG_MANAGER: GTM-ABCD123

.github/workflows/website-deploy-release.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,22 @@ jobs:
6464
make init
6565
pip install -r scripts/docs-collator/requirements.txt
6666
67-
- name: "Render docs for components"
67+
- name: "Render Documentation for Terraform Components"
6868
run: |
6969
./scripts/render-docs-for-components.sh
7070
71-
- name: "Render docs for modules"
71+
- name: "Render Documentation for Terraform Modules"
7272
env:
7373
PUBLIC_REPO_ACCESS_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
7474
run: |
7575
./scripts/render-docs-for-modules.sh
7676
77+
- name: "Render Documentation for GitHub Actions"
78+
env:
79+
PUBLIC_REPO_ACCESS_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
80+
run: |
81+
./scripts/render-docs-for-github-actions.sh
82+
7783
- name: Install Dependencies and Build Website
7884
env:
7985
GOOGLE_TAG_MANAGER: ${{ vars.GOOGLE_TAG_MANAGER }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ algolia.index.json
5757
**/__pycache__/
5858
content/components/catalog/aws/**
5959
content/modules/catalog/**
60+
content/github-actions/catalog/actions/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "GitHub Actions",
3+
"position": 0,
4+
"link": {
5+
"type": "doc",
6+
"id": "index"
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "actions",
3+
"collapsible": true,
4+
"collapsed": false,
5+
"className": "command",
6+
"link": {
7+
"type": "generated-index",
8+
"title": "GitHub Actions"
9+
}
10+
}

content/github-actions/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: GitHub Actions
3+
sidebar_label: Overview of GitHub Actions
4+
description: GitHub Actions
5+
sidebar_position: 0
6+
---
7+
8+
This is a collection of reusable GitHub Actions.
9+
10+
## Introduction
11+
12+
In this library you'll find real-world examples of how we've implemented reusable GitHub Actions to solve common CI/CD challenges.

docusaurus.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ const config = {
4545
sidebarPath: require.resolve('./sidebars-modules.js')
4646
},
4747
],
48+
[
49+
'@docusaurus/plugin-content-docs',
50+
{
51+
id: 'github_actions',
52+
path: 'content/github-actions',
53+
routeBasePath: 'github-actions/',
54+
sidebarPath: require.resolve('./sidebars-github-actions.js')
55+
},
56+
],
4857
[
4958
"@docusaurus/plugin-google-gtag",
5059
{
@@ -120,6 +129,11 @@ const config = {
120129
position: 'left',
121130
label: 'Modules',
122131
},
132+
{
133+
to: '/github-actions/',
134+
position: 'left',
135+
label: 'GitHub Actions',
136+
},
123137
{
124138
type: 'dropdown',
125139
label: 'Community',

scripts/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Usage for docs-collator
22

3-
Document collation supports 2 types of projects:
3+
Document collation supports 3 types of projects:
44
- components - `cloudposse/terraform-aws-component` - components from single repo `cloudposse/terraform-aws-component` under `modules/` dir
5-
- modules - `cloudposse/terraform-*` - for all public (non archived) repos except `cloudposse/terraform-aws-component` that are prefixed with `terraform-`
5+
- modules - `cloudposse/terraform-*` - for all public (non-archived) repos except `cloudposse/terraform-aws-component` that are prefixed with `terraform-`
6+
- github actions - `cloudposse/github-action-*` - for all public (non-archived) repos that are prefixed with `github-action-`
67

78
Python is used for both tools so make sure to install python requirements.
89

@@ -12,13 +13,13 @@ Python is used for both tools so make sure to install python requirements.
1213
pip install -r scripts/docs-collator/requirements.txt
1314
```
1415

15-
### Render Documentation for Components
16+
### Render Documentation for Terraform Components
1617

1718
```bash
1819
./scripts/render-docs-for-components.sh
1920
```
2021

21-
### Render Documentation for Modules
22+
### Render Documentation for Terraform Modules
2223

2324
Since this script uses the Github API, the GitHub access token should be set as the `PUBLIC_REPO_ACCESS_TOKEN ` environment variable.
2425

@@ -27,3 +28,13 @@ export PUBLIC_REPO_ACCESS_TOKEN=<github-api-token>
2728

2829
./scripts/render-docs-for-modules.sh
2930
```
31+
32+
### Render Documentation for GitHub Actions
33+
34+
This script also uses GitHub API, so the GitHub access token should be set as the `PUBLIC_REPO_ACCESS_TOKEN ` environment variable.
35+
36+
```bash
37+
export PUBLIC_REPO_ACCESS_TOKEN=<github-api-token>
38+
39+
./scripts/render-docs-for-github-actions.sh
40+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
3+
DOCS_DIR = 'docs'
4+
TARGETS_MD = 'targets.md'
5+
README_YAML = 'README.yaml'
6+
7+
8+
class MissingReadmeYamlException(Exception):
9+
def __init__(self):
10+
self.message = "README.yaml is missing"
11+
super().__init__(self.message)
12+
13+
14+
class AbstractFetcher:
15+
def __init__(self, github_provider, download_dir):
16+
self.download_dir = download_dir
17+
self.github_provider = github_provider
18+
19+
def _fetch_readme_yaml(self, repo, module_download_dir):
20+
self.github_provider.fetch_file(repo, README_YAML, module_download_dir)
21+
22+
def _fetch_docs(self, repo, module_download_dir):
23+
remote_files = self.github_provider.list_repo_dir(repo, DOCS_DIR)
24+
25+
for remote_file in remote_files:
26+
if os.path.basename(remote_file) == TARGETS_MD: # skip targets.md
27+
continue
28+
29+
self.github_provider.fetch_file(repo, remote_file, module_download_dir)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import logging
2+
import os
3+
4+
from utils import io
5+
from utils import rendering
6+
7+
README_YAML = 'README.yaml'
8+
DOCS_DIR = 'docs'
9+
10+
11+
class TerraformDocsRenderingError(Exception):
12+
def __init__(self, message):
13+
self.message = message
14+
super().__init__(f"Failed to render README.md. {message}")
15+
16+
17+
class AbstractRenderer:
18+
def _pre_rendering_fixes(self, repo, module_download_dir):
19+
readme_yaml_file = os.path.join(module_download_dir, README_YAML)
20+
content = io.read_file_to_string(readme_yaml_file)
21+
content = rendering.remove_targets_md(content)
22+
content = rendering.rename_name(repo, content)
23+
io.save_string_to_file(readme_yaml_file, content)
24+
25+
def _post_rendering_fixes(self, repo, readme_md_file):
26+
content = io.read_file_to_string(readme_md_file)
27+
content = rendering.fix_self_non_closing_br_tags(content)
28+
content = rendering.fix_custom_non_self_closing_tags_in_pre(content)
29+
content = rendering.fix_github_edit_url(content, repo)
30+
content = rendering.fix_sidebar_label(content, repo)
31+
io.save_string_to_file(readme_md_file, content)
32+
33+
def _copy_extra_resources_for_docs(self, module_download_dir, module_docs_dir):
34+
extra_resources_dir = os.path.join(module_download_dir, DOCS_DIR)
35+
files = io.get_filenames_in_dir(extra_resources_dir, '*', True)
36+
37+
for file in files:
38+
if os.path.basename(file).lower().endswith('.md') or os.path.isdir(file):
39+
continue
40+
41+
dest_file = os.path.join(module_docs_dir, DOCS_DIR, os.path.relpath(file, extra_resources_dir))
42+
io.copy_file(file, dest_file)
43+
44+
logging.info(f"Copied extra file: {dest_file}")

0 commit comments

Comments
 (0)