You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Automating Documentation Testing with Innovation Engine
2
+
3
+
## Overview
4
+
5
+
This guide explains how to set up and use a GitHub Action that automates testing of your Markdown documentation using Innovation Engine. The action ensures your executable documents are accurate and robust by running tests on them. It will create comments on pull requests for any errors found and, when combined with branch protection rules, can prevent pull requests from merging until those errors are resolved.
6
+
7
+
## Prerequisites
8
+
9
+
Before setting up the GitHub Action, you need the following:
10
+
11
+
-**Azure Credentials**: The action logs into Azure using the Azure CLI, so you need to provide the following repository secrets:
12
+
-`AZURE_CLIENT_ID`
13
+
-`AZURE_TENANT_ID`
14
+
-`AZURE_SUBSCRIPTION_ID`
15
+
16
+
To obtain these values:
17
+
1. Register an application in Azure Active Directory.
18
+
2. Assign the necessary permissions to the application.
19
+
3. Note the application (client) ID, tenant ID, and subscription ID.
20
+
21
+
-**GitHub Personal Access Token (PAT)**: The action interacts with the GitHub API to create comments on pull requests. Store your PAT in a repository secret named `PAT`.
22
+
23
+
## GitHub Action Workflow
24
+
25
+
The GitHub Action performs the following steps:
26
+
27
+
1.**Trigger**: Runs on pull request events when a pull request is opened or updated.
28
+
29
+
2.**Checkout Repository**: Uses `actions/checkout@v3` to clone the repository with full history for accurate diffs.
30
+
31
+
3.**Determine Commit SHAs**:
32
+
- Identifies the base and head commits of the pull request.
33
+
- Calculates the number of commits between the base and head.
34
+
- Sets output variables for use in subsequent steps.
35
+
36
+
4.**Check for Changed Markdown Files**:
37
+
38
+
- Compares changes between the base and head commits.
39
+
- Generates a list of changed Markdown files to be tested.
40
+
- If no Markdown files have changed, the workflow exits early.
41
+
42
+
5.**Azure CLI Login**: Logs into Azure using the provided credentials with `azure/login@v2` (only if Markdown files have changed).
43
+
44
+
6.**Set Up Python**: Sets up a Python 3.12 environment using `actions/setup-python@v4` (only if Markdown files have changed).
45
+
46
+
7.**Install Dependencies**: Installs required Python packages (only if Markdown files have changed):
47
+
48
+
```bash
49
+
pip install --upgrade pip==24.3.1
50
+
pip install setuptools wheel
51
+
pip install PyGithub==2.1.1 pyyaml==6.0.2
52
+
```
53
+
54
+
8.**Run Tests and Handle Pull Request**: Executes a Python script that (only if Markdown files have changed):
55
+
56
+
-**Innovation Engine Installation**: Installs `ie` (Innovation Engine) if not already installed.
57
+
-**Repository Information**: Retrieves repository details such as owner, name, and pull request number.
58
+
-**Testing Markdown Files**:
59
+
- Iterates over the list of changed Markdown files.
60
+
- Runs `ie execute` on each file to test the executable documentation.
61
+
-**On Test Failure**:
62
+
- Extracts error logs from the `ie.log` file.
63
+
- Creates a comment on the pull request with the error details.
64
+
- Records the failure in the test results.
65
+
-**On Test Success**:
66
+
- Records the success in the test results.
67
+
-**Reporting Results**:
68
+
- Posts the test results as a comment on the pull request.
69
+
- If any failures occurred, exits with a non-zero status to fail the workflow.
70
+
71
+
## Customization
72
+
73
+
You can modify the GitHub Action to suit your project's needs:
74
+
75
+
-**Event Triggers**: Adjust the `on` section to change when the action runs. Currently, it triggers on pull request events (`opened` and `synchronize`).
76
+
77
+
-**Azure Login Step**: If your documentation doesn't require Azure resources, you can remove the Azure login step.
78
+
79
+
-**Python Version and Dependencies**:
80
+
- Update the `python-version` in the **Set Up Python** step to match your project's requirements.
81
+
- In the **Install Dependencies** step, specify the versions of `pip`, `PyGithub`, and `pyyaml` as needed.
82
+
83
+
-**Testing Script**: Update the Python script to change how tests are executed, how errors are handled, or how results are reported. For example, you might customize the error extraction logic or modify the comment creation process.
84
+
85
+
-**Secrets Management**: Ensure all necessary secrets (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_SUBSCRIPTION_ID`, `PAT`) are correctly named and stored in your repository's settings under **Settings > Secrets and variables > Actions**.
86
+
87
+
## Conclusion
88
+
89
+
By integrating this GitHub Action into your repository, you automate the testing of your executable Markdown documents using Innovation Engine. This helps maintain documentation accuracy and, combined with branch protection rules, prevents broken documentation from being merged into your main branch.
0 commit comments