|
| 1 | +# CI/CD Setup Documentation |
| 2 | + |
| 3 | +This document describes the Continuous Integration and Continuous Deployment (CI/CD) setup for the Mojo algorithms repository, based on [TheAlgorithms](https://github.com/TheAlgorithms) organization standards. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The CI/CD pipeline consists of four main workflows that automate repository maintenance, code quality checks, and documentation generation. |
| 8 | + |
| 9 | +## Workflows Added |
| 10 | + |
| 11 | +### 1. Directory Writer (`directory_writer.yml`) |
| 12 | + |
| 13 | +**Purpose:** Automatically maintains the `DIRECTORY.md` file |
| 14 | + |
| 15 | +**Triggers:** |
| 16 | +- Push to `main` branch |
| 17 | +- Pull requests to `main` branch |
| 18 | + |
| 19 | +**Actions:** |
| 20 | +- Generates an up-to-date list of all `.mojo` files |
| 21 | +- Organizes them in a hierarchical structure |
| 22 | +- Commits changes automatically (on push events) |
| 23 | + |
| 24 | +**Benefits:** |
| 25 | +- No manual maintenance of DIRECTORY.md required |
| 26 | +- Always reflects current repository structure |
| 27 | +- Improves discoverability of algorithms |
| 28 | + |
| 29 | +### 2. Directory Verifier (`verify_directory.yml`) |
| 30 | + |
| 31 | +**Purpose:** Ensures DIRECTORY.md stays synchronized with repository structure |
| 32 | + |
| 33 | +**Triggers:** |
| 34 | +- Pull requests to `main` branch |
| 35 | + |
| 36 | +**Actions:** |
| 37 | +- Generates a fresh DIRECTORY.md |
| 38 | +- Compares with existing file |
| 39 | +- Fails if differences are found |
| 40 | + |
| 41 | +**Benefits:** |
| 42 | +- Catches outdated documentation before merge |
| 43 | +- Enforces consistency |
| 44 | +- Provides clear error messages with diffs |
| 45 | + |
| 46 | +### 3. Linter (`lint.yml`) |
| 47 | + |
| 48 | +**Purpose:** Enforces code quality and naming conventions |
| 49 | + |
| 50 | +**Triggers:** |
| 51 | +- Push to `main` branch |
| 52 | +- Pull requests to `main` branch |
| 53 | + |
| 54 | +**Checks:** |
| 55 | +- No spaces in filenames |
| 56 | +- Lowercase with underscores for `.mojo` files |
| 57 | +- No trailing whitespace |
| 58 | + |
| 59 | +**Benefits:** |
| 60 | +- Consistent file naming across repository |
| 61 | +- Cleaner code |
| 62 | +- Prevents common formatting issues |
| 63 | + |
| 64 | +### 4. Link Checker (`check_links.yml`) |
| 65 | + |
| 66 | +**Purpose:** Validates all links in markdown files |
| 67 | + |
| 68 | +**Triggers:** |
| 69 | +- Pull requests to `main` branch |
| 70 | +- Weekly schedule (Mondays at 00:00 UTC) |
| 71 | + |
| 72 | +**Actions:** |
| 73 | +- Scans all markdown files |
| 74 | +- Tests external links |
| 75 | +- Reports broken links |
| 76 | + |
| 77 | +**Benefits:** |
| 78 | +- Prevents broken documentation links |
| 79 | +- Maintains high documentation quality |
| 80 | +- Catches link rot early |
| 81 | + |
| 82 | +## Scripts Added |
| 83 | + |
| 84 | +### `scripts/build_directory_md.py` |
| 85 | + |
| 86 | +Python script that generates the DIRECTORY.md file by: |
| 87 | +1. Walking through the repository |
| 88 | +2. Finding all files with specified extensions |
| 89 | +3. Creating a hierarchical markdown structure |
| 90 | +4. Formatting filenames into readable titles |
| 91 | + |
| 92 | +**Usage:** |
| 93 | +```bash |
| 94 | +python3 scripts/build_directory_md.py Mojo . .mojo > DIRECTORY.md |
| 95 | +``` |
| 96 | + |
| 97 | +## Configuration Files |
| 98 | + |
| 99 | +### `.github/markdown-link-check-config.json` |
| 100 | + |
| 101 | +Configures the link checker with: |
| 102 | +- Timeout settings (20s) |
| 103 | +- Retry logic (3 attempts) |
| 104 | +- Status code validation |
| 105 | +- URL pattern ignoring (localhost) |
| 106 | + |
| 107 | +## Files Created |
| 108 | + |
| 109 | +``` |
| 110 | +.github/ |
| 111 | +├── workflows/ |
| 112 | +│ ├── check_links.yml |
| 113 | +│ ├── directory_writer.yml |
| 114 | +│ ├── lint.yml |
| 115 | +│ ├── verify_directory.yml |
| 116 | +│ └── README.md |
| 117 | +├── markdown-link-check-config.json |
| 118 | +└── CI_SETUP.md (this file) |
| 119 | +
|
| 120 | +scripts/ |
| 121 | +├── build_directory_md.py |
| 122 | +└── README.md |
| 123 | +
|
| 124 | +DIRECTORY.md (updated) |
| 125 | +``` |
| 126 | + |
| 127 | +## Permissions |
| 128 | + |
| 129 | +The workflows use minimal permissions: |
| 130 | +- `directory_writer.yml`: Requires `contents: write` to commit changes |
| 131 | +- Other workflows: Use default read-only permissions |
| 132 | + |
| 133 | +## Integration with TheAlgorithms |
| 134 | + |
| 135 | +These workflows follow the same patterns used across all TheAlgorithms repositories: |
| 136 | +- [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python) |
| 137 | +- [TheAlgorithms/Java](https://github.com/TheAlgorithms/Java) |
| 138 | +- [TheAlgorithms/JavaScript](https://github.com/TheAlgorithms/JavaScript) |
| 139 | +- And 40+ other language repositories |
| 140 | + |
| 141 | +## Next Steps |
| 142 | + |
| 143 | +1. **Test the workflows:** Push a commit to trigger the workflows |
| 144 | +2. **Monitor Actions tab:** Check that all workflows run successfully |
| 145 | +3. **Add more workflows:** Consider adding: |
| 146 | + - Mojo syntax checking (when available) |
| 147 | + - Performance benchmarking |
| 148 | + - Code coverage reporting |
| 149 | + - Automated releases |
| 150 | + |
| 151 | +## Troubleshooting |
| 152 | + |
| 153 | +### Directory Writer Not Committing |
| 154 | + |
| 155 | +If the directory writer workflow runs but doesn't commit: |
| 156 | +- Check that `DIRECTORY.md` actually changed |
| 157 | +- Verify the workflow has `contents: write` permission |
| 158 | +- Check the Actions logs for error messages |
| 159 | + |
| 160 | +### Link Checker Failing |
| 161 | + |
| 162 | +If the link checker reports false positives: |
| 163 | +- Update `.github/markdown-link-check-config.json` |
| 164 | +- Add patterns to `ignorePatterns` |
| 165 | +- Adjust timeout or retry settings |
| 166 | + |
| 167 | +### Lint Failures |
| 168 | + |
| 169 | +If lint checks fail: |
| 170 | +- Review the error messages in Actions logs |
| 171 | +- Fix naming conventions (lowercase, underscores) |
| 172 | +- Remove trailing whitespace |
| 173 | +- Ensure no spaces in filenames |
| 174 | + |
| 175 | +## References |
| 176 | + |
| 177 | +- [TheAlgorithms/scripts](https://github.com/TheAlgorithms/scripts) - Original scripts repository |
| 178 | +- [GitHub Actions Documentation](https://docs.github.com/en/actions) |
| 179 | +- [Markdown Link Check Action](https://github.com/gaurav-nelson/github-action-markdown-link-check) |
0 commit comments