|
| 1 | +# Update Test Results Badge Action |
| 2 | + |
| 3 | +A reusable GitHub Action that updates test result badges by uploading test data to GitHub Gist files and displaying badge URLs for README files. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +This action simplifies the process of maintaining dynamic test result badges by: |
| 8 | + |
| 9 | +- Creating structured JSON data from test results |
| 10 | +- Uploading the data to platform-specific files in a single GitHub Gist |
| 11 | +- Providing ready-to-use badge URLs for documentation |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +```yaml |
| 16 | +- name: "Update Test Results Badge" |
| 17 | + uses: ./.github/actions/update-test-badge |
| 18 | + with: |
| 19 | + platform: "Linux" |
| 20 | + gist_id: "472c59b7c2a1898c48a29f3c88897c5a" |
| 21 | + filename: "test-results-linux.json" |
| 22 | + gist_token: ${{ secrets.GIST_SECRET }} |
| 23 | + test_passed: 1099 |
| 24 | + test_failed: 0 |
| 25 | + test_skipped: 0 |
| 26 | + test_url_html: "https://github.com/owner/repo/runs/12345" |
| 27 | + commit_sha: ${{ github.sha }} |
| 28 | + run_id: ${{ github.run_id }} |
| 29 | + repository: ${{ github.repository }} |
| 30 | + server_url: ${{ github.server_url }} |
| 31 | +``` |
| 32 | +
|
| 33 | +## Gist Structure |
| 34 | +
|
| 35 | +This action uses a **single Gist** with **multiple files** for different platforms: |
| 36 | +
|
| 37 | +``` |
| 38 | +Gist ID: 472c59b7c2a1898c48a29f3c88897c5a |
| 39 | +├── test-results-linux.json |
| 40 | +├── test-results-windows.json |
| 41 | +└── test-results-macos.json |
| 42 | +``` |
| 43 | + |
| 44 | +## Inputs |
| 45 | + |
| 46 | +| Input | Description | Required | Default | |
| 47 | +|-------|-------------|----------|---------| |
| 48 | +| `platform` | Platform name (Linux, Windows, macOS) | ✅ | - | |
| 49 | +| `gist_id` | GitHub Gist ID for storing test results | ✅ | - | |
| 50 | +| `filename` | Filename for platform-specific JSON (e.g., test-results-linux.json) | ✅ | - | |
| 51 | +| `gist_token` | GitHub token with gist permissions | ✅ | - | |
| 52 | +| `test_passed` | Number of passed tests | ✅ | - | |
| 53 | +| `test_failed` | Number of failed tests | ✅ | - | |
| 54 | +| `test_skipped` | Number of skipped tests | ✅ | - | |
| 55 | +| `test_url_html` | URL to test results page | ❌ | `''` | |
| 56 | +| `commit_sha` | Git commit SHA | ✅ | - | |
| 57 | +| `run_id` | GitHub Actions run ID | ✅ | - | |
| 58 | +| `repository` | Repository in owner/repo format | ✅ | - | |
| 59 | +| `server_url` | GitHub server URL | ✅ | - | |
| 60 | +| `api_domain` | Badge API domain for URLs | ❌ | `your-api-domain` | |
| 61 | + |
| 62 | +## Outputs |
| 63 | + |
| 64 | +This action produces: |
| 65 | + |
| 66 | +- **Gist File Update**: Updates the platform-specific file in the single Gist |
| 67 | +- **Console Output**: Displays badge URLs ready for README usage |
| 68 | +- **Debug Info**: Shows HTTP status and error details |
| 69 | + |
| 70 | +## Generated JSON Format |
| 71 | + |
| 72 | +The action creates JSON data in this format for each platform file: |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "platform": "Linux", |
| 77 | + "passed": 1099, |
| 78 | + "failed": 0, |
| 79 | + "skipped": 0, |
| 80 | + "total": 1099, |
| 81 | + "url_html": "https://github.com/owner/repo/runs/12345", |
| 82 | + "timestamp": "2025-01-16T10:30:00Z", |
| 83 | + "commit": "abc123def456", |
| 84 | + "run_id": "12345678", |
| 85 | + "workflow_run_url": "https://github.com/owner/repo/actions/runs/12345678" |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## Error Handling |
| 90 | + |
| 91 | +- **Non-essential**: Uses `continue-on-error: true` to prevent workflow failures |
| 92 | +- **Graceful degradation**: Provides detailed error messages without stopping execution |
| 93 | +- **HTTP status reporting**: Shows API response codes for debugging |
| 94 | +- **File-specific updates**: Only updates the specific platform file, doesn't affect other platform data |
| 95 | + |
| 96 | +## Integration with Badge API |
| 97 | + |
| 98 | +This action is designed to work with the LocalStack .NET Client Badge API that: |
| 99 | + |
| 100 | +- Reads from the updated Gist files |
| 101 | +- Generates shields.io-compatible badge JSON |
| 102 | +- Provides redirect endpoints to test result pages |
| 103 | + |
| 104 | +## Matrix Integration Example |
| 105 | + |
| 106 | +```yaml |
| 107 | +env: |
| 108 | + BADGE_GIST_ID: "472c59b7c2a1898c48a29f3c88897c5a" |
| 109 | + |
| 110 | +strategy: |
| 111 | + matrix: |
| 112 | + include: |
| 113 | + - os: ubuntu-22.04 |
| 114 | + name: "Linux" |
| 115 | + filename: "test-results-linux.json" |
| 116 | + - os: windows-latest |
| 117 | + name: "Windows" |
| 118 | + filename: "test-results-windows.json" |
| 119 | + - os: macos-latest |
| 120 | + name: "macOS" |
| 121 | + filename: "test-results-macos.json" |
| 122 | + |
| 123 | +steps: |
| 124 | + - name: "Update Test Results Badge" |
| 125 | + uses: ./.github/actions/update-test-badge |
| 126 | + with: |
| 127 | + platform: ${{ matrix.name }} |
| 128 | + gist_id: ${{ env.BADGE_GIST_ID }} |
| 129 | + filename: ${{ matrix.filename }} |
| 130 | + gist_token: ${{ secrets.GIST_SECRET }} |
| 131 | + # ... other inputs |
| 132 | +``` |
| 133 | + |
| 134 | +## Required Setup |
| 135 | + |
| 136 | +1. **Create single GitHub Gist** with platform-specific files: |
| 137 | + - `test-results-linux.json` |
| 138 | + - `test-results-windows.json` |
| 139 | + - `test-results-macos.json` |
| 140 | +2. **Generate GitHub PAT** with `gist` scope |
| 141 | +3. **Add to repository secrets** as `GIST_SECRET` |
| 142 | +4. **Deploy Badge API** to consume the Gist data |
| 143 | + |
| 144 | +## Badge URLs Generated |
| 145 | + |
| 146 | +The action displays ready-to-use markdown for README files: |
| 147 | + |
| 148 | +```markdown |
| 149 | +[](https://your-api-domain/redirect/tests/linux) |
| 150 | +``` |
| 151 | + |
| 152 | +## Advantages of Explicit Filename Configuration |
| 153 | + |
| 154 | +- ✅ **No String Manipulation**: Eliminates brittle string transformation logic |
| 155 | +- ✅ **Declarative**: Filenames are explicitly declared in workflow configuration |
| 156 | +- ✅ **Predictable**: No risk of unexpected filename generation |
| 157 | +- ✅ **Reusable**: Action works with any filename structure |
| 158 | +- ✅ **Debuggable**: Easy to see exactly what files will be created |
| 159 | +- ✅ **Flexible**: Supports any naming convention without code changes |
| 160 | + |
| 161 | +## Advantages of Single Gist Approach |
| 162 | + |
| 163 | +- ✅ **Simplified Management**: One Gist to manage instead of three |
| 164 | +- ✅ **Atomic Operations**: All platform data in one place |
| 165 | +- ✅ **Better Organization**: Clear file structure with descriptive names |
| 166 | +- ✅ **Easier Debugging**: Single location to check all test data |
| 167 | +- ✅ **Cost Efficient**: Fewer API calls and resources |
| 168 | + |
| 169 | +## Troubleshooting |
| 170 | + |
| 171 | +**Common Issues:** |
| 172 | + |
| 173 | +- **403 Forbidden**: Check `GIST_SECRET` permissions |
| 174 | +- **404 Not Found**: Verify `gist_id` is correct |
| 175 | +- **JSON Errors**: Ensure `jq` is available in runner |
| 176 | +- **File Missing**: Gist files are created automatically on first update |
| 177 | + |
| 178 | +**Debug Steps:** |
| 179 | + |
| 180 | +1. Check action output for HTTP status codes |
| 181 | +2. Verify Gist exists and is publicly accessible |
| 182 | +3. Confirm token has proper `gist` scope |
| 183 | +4. Check individual file URLs: `https://gist.githubusercontent.com/{gist_id}/raw/test-results-{platform}.json` |
0 commit comments