Repository navigation
ci: add Go test job (skips when go.mod absent) #101
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Test detection rules (ci_changed_tests.py + grep pattern): | |
| # - Files must live under a `tests/` subdirectory and be named `test_*.py` | |
| # - Test classes must start with `Test` | |
| # - Test functions/methods must start with `test_` | |
| name: PR Tests | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| permissions: | |
| contents: read | |
| jobs: | |
| run-tests: | |
| name: Run all tests | |
| runs-on: [self-hosted, rune-ci] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Detect changed test node IDs | |
| id: detect | |
| run: | | |
| BASE=${{ github.event.pull_request.base.sha }} | |
| HEAD=${{ github.event.pull_request.head.sha }} | |
| CHANGED=$(git diff --name-only "$BASE" "$HEAD" | grep -E '(^|/)tests/test_[^/]+\.py$' || true) | |
| if [ -z "$CHANGED" ]; then | |
| echo "has_changed=false" >> "$GITHUB_OUTPUT" | |
| echo "test_ids=" >> "$GITHUB_OUTPUT" | |
| else | |
| python .github/scripts/ci_changed_tests.py "$BASE" "$HEAD" $CHANGED | |
| fi | |
| - name: Cache pip | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: pip install -r requirements.txt | |
| - name: Run all tests | |
| id: pytest | |
| run: | | |
| TEST_DIRS=$(find . -type d -name "tests" | grep -v __pycache__ | grep -v "/.git/" | tr '\n' ' ') \ | |
| && python -m pytest $TEST_DIRS \ | |
| -v --tb=long -rs \ | |
| 2>&1 | tee pytest_output.txt | |
| echo "exit_code=${PIPESTATUS[0]}" >> "$GITHUB_OUTPUT" | |
| env: | |
| PYTHONPATH: ${{ github.workspace }} | |
| continue-on-error: true | |
| - name: Save PR info | |
| if: always() | |
| run: | | |
| python3 - <<'EOF' | |
| import json, os | |
| info = { | |
| 'PR_NUMBER': os.environ['PR_NUMBER'], | |
| 'EXIT_CODE': os.environ['EXIT_CODE'], | |
| 'HAS_CHANGED': os.environ['HAS_CHANGED'], | |
| 'TEST_IDS': os.environ['TEST_IDS'], | |
| 'HEAD_SHA': os.environ['HEAD_SHA'], | |
| } | |
| with open('pr_info.json', 'w') as f: | |
| json.dump(info, f) | |
| EOF | |
| env: | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| EXIT_CODE: ${{ steps.pytest.outputs.exit_code }} | |
| HAS_CHANGED: ${{ steps.detect.outputs.has_changed }} | |
| TEST_IDS: ${{ steps.detect.outputs.test_ids }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: | | |
| pytest_output.txt | |
| pr_info.json | |
| - name: Fail if tests failed | |
| if: always() && steps.pytest.outputs.exit_code != '0' | |
| run: exit 1 | |
| run-go-tests: | |
| name: Run Go tests | |
| runs-on: [self-hosted, rune-ci] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Skip silently when go.mod is absent (Python-only branches before the | |
| # Go migration lands on main). Subsequent steps gate on this output. | |
| - name: Detect Go project | |
| id: detect_go | |
| run: | | |
| if [ -f go.mod ]; then | |
| echo "has_go=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_go=false" >> "$GITHUB_OUTPUT" | |
| echo "::notice::No go.mod found — skipping Go tests" | |
| fi | |
| - uses: actions/setup-go@v5 | |
| if: steps.detect_go.outputs.has_go == 'true' | |
| with: | |
| go-version-file: 'go.mod' | |
| cache: true | |
| - name: gofmt | |
| if: steps.detect_go.outputs.has_go == 'true' | |
| run: | | |
| unformatted=$(gofmt -l -e .) | |
| if [ -n "$unformatted" ]; then | |
| echo "::error::gofmt found unformatted files:" | |
| echo "$unformatted" | |
| gofmt -d -e . | |
| exit 1 | |
| fi | |
| - name: go vet | |
| if: steps.detect_go.outputs.has_go == 'true' | |
| run: go vet ./... | |
| - name: go test -race | |
| if: steps.detect_go.outputs.has_go == 'true' | |
| run: go test -race -count=1 ./... |