|
| 1 | +# Go Snippets Tooling |
| 2 | + |
| 3 | +This directory contains the scripts and configuration for building, running, and testing the Go snippets located in `examples/go/`. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The tooling is designed to ensure that all Go snippets are continuously validated and to provide a fast feedback loop for developers. It consists of a unified runner script, a configuration file to manage the list of snippets, and a suite of unit tests for the runner itself. |
| 8 | + |
| 9 | +## Key Components |
| 10 | + |
| 11 | +- **`runner.sh`**: The main script for building and running Go snippets. |
| 12 | +- **`files_to_test.txt`**: The configuration file that lists all Go snippets to be tested. |
| 13 | +- **`check_go_snippets.sh`**: A PR check script that ensures all `.go` files are registered in `files_to_test.txt`. |
| 14 | +- **`runner_test.sh`**: Unit tests for the `runner.sh` script. |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## How to Use |
| 19 | + |
| 20 | +### Automatic Execution (CI/CD) |
| 21 | + |
| 22 | +The scripts are primarily designed to be run automatically by GitHub Actions. |
| 23 | + |
| 24 | +- **On Pull Requests:** When a pull request is opened, two workflows are triggered: |
| 25 | + 1. **Go Snippets Build on PR and Schedule:** This workflow runs `check_go_snippets.sh` to ensure new files are registered. It then intelligently builds **only the `.go` files that were changed** in the PR. |
| 26 | + 2. **Go Build and Test on PR:** This workflow runs a full build of **all** Go snippets and executes any unit tests (`go test ./...`) to ensure that a change has not broken any other part of the Go codebase. |
| 27 | + |
| 28 | +- **Scheduled Runs:** A full regression build of all Go snippets is run automatically every Sunday at 3:00 AM UTC to catch any potential issues. |
| 29 | + |
| 30 | +### Manual Execution |
| 31 | + |
| 32 | +You can also run the scripts locally to test your changes before pushing. All commands should be run from the **root of the repository**. |
| 33 | + |
| 34 | +#### Building All Snippets |
| 35 | + |
| 36 | +To run a full build of every Go snippet listed in `files_to_test.txt`: |
| 37 | + |
| 38 | +```bash |
| 39 | +./tools/go-snippets/runner.sh build |
| 40 | +``` |
| 41 | + |
| 42 | +#### Building Specific Snippets |
| 43 | + |
| 44 | +To build one or more specific Go snippets (for example, if you are working on them and want a quick check): |
| 45 | + |
| 46 | +```bash |
| 47 | +./tools/go-snippets/runner.sh build examples/go/snippets/quickstart/main.go |
| 48 | +``` |
| 49 | + |
| 50 | +#### Running the Unit Tests |
| 51 | + |
| 52 | +To run the unit tests for the `runner.sh` script itself: |
| 53 | + |
| 54 | +```bash |
| 55 | +./tools/go-snippets/runner_test.sh |
| 56 | +``` |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +## Maintaining the Snippet List |
| 61 | + |
| 62 | +### Adding a New Snippet |
| 63 | + |
| 64 | +1. Create your new `.go` file (e.g., `examples/go/snippets/my-new-snippet/main.go`). |
| 65 | +2. Open `tools/go-snippets/files_to_test.txt`. |
| 66 | +3. Add a new line with the path to your file, relative to the `examples/go/` directory. |
| 67 | + |
| 68 | + ``` |
| 69 | + # In files_to_test.txt |
| 70 | + snippets/my-new-snippet/main.go |
| 71 | + ``` |
| 72 | +
|
| 73 | +4. If your snippet is part of a package that requires multiple files to be built together, add them all to the same line: |
| 74 | +
|
| 75 | + ``` |
| 76 | + # In files_to_test.txt |
| 77 | + snippets/my-multi-file-snippet/main.go snippets/my-multi-file-snippet/helpers.go |
| 78 | + ``` |
| 79 | +
|
| 80 | +The `check_go_snippets.sh` script will automatically run on your PR and remind you if you've forgotten to add your new file to the list. |
0 commit comments