GitHub Actions Setup Guide for Codity.ai
This guide covers best practices for configuring GitHub Actions workflows to work seamlessly with Codity.ai's automated test generation and monitoring.
Why GitHub Actions Works Well with Codity.ai
GitHub Actions is well-integrated with Codity.ai and requires minimal configuration. Most workflows work out-of-the-box because:
- Automatic path handling (no manual PYTHONPATH needed)
- Job names are typically descriptive by default
- Workflow files are easily discoverable in
.github/workflows/
Critical Configuration Points
1. Workflow Name
- Should contain keywords:
test,ci, orbuild(recommended) - Works without keywords, but better detection with them
- Why: Codity identifies CI workflows by checking names
Examples:
-
CI Tests -
Run Tests -
Build and Test -
Main Workflow(works, but less specific)
2. Job Name
- Should contain keywords:
test,python,go,ruby,javascript,jest,pytest - Why: Helps filter out non-test jobs (lint, deploy, etc.)
Examples:
-
test -
run-tests -
python-tests -
build(might be skipped if no test keyword)
3. Working Directory (Optional)
- Only needed if your project files are in a subdirectory
- Use
working-directoryin step configuration - Important: The path must actually exist in your repository
4. Pull Request Triggers
- Include
pull_requesttrigger - Why: Without this, CI won't run on PRs
5. Verbose Output (Recommended)
- Use
-vor--verboseflags for better logs - Why: Provides detailed error information for auto-fixing
Sample GitHub Actions Workflows
Python with pytest
name: Python CI Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install pytest
pip install -r requirements.txt
# Only set working-directory if requirements.txt is in a subdirectory
# working-directory: ./backend
- name: Run pytest
run: pytest -v
# Only set working-directory if tests are in a subdirectory
# working-directory: ./backend
Go with testing
name: Go CI Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run Go tests
run: go test -v ./...
# Only set working-directory if go.mod is in a subdirectory
# working-directory: ./services
JavaScript/TypeScript with Jest
name: JavaScript CI Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
# Only set working-directory if package.json is in a subdirectory
# Example: working-directory: ./frontend
- name: Run Jest tests
run: npm test -- --verbose
# Only set working-directory if tests are in a subdirectory
# Example: working-directory: ./frontend
Ruby with RSpec
name: Ruby CI Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Install dependencies
run: bundle install
# Only set working-directory if Gemfile is in a subdirectory
# working-directory: ./api
- name: Run RSpec tests
run: bundle exec rspec --format documentation
# Only set working-directory if tests are in a subdirectory
# working-directory: ./api
Java with JUnit/Gradle
name: Java CI Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Only set working-directory if build.gradle is in a subdirectory
# working-directory: ./service
- name: Run tests with Gradle
run: ./gradlew test --info
# Only set working-directory if build.gradle is in a subdirectory
# working-directory: ./service
Multi-language Monorepo
name: Monorepo CI Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
backend-tests:
name: Python Backend Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: pip install pytest
working-directory: ./backend
- name: Run tests
run: pytest -v
working-directory: ./backend
frontend-tests:
name: JavaScript Frontend Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
working-directory: ./frontend
- name: Run tests
run: npm test -- --verbose
working-directory: ./frontend
services-tests:
name: Go Services Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run tests
run: go test -v ./...
working-directory: ./services
Understanding Working Directory
Important: Paths Must Actually Exist
When you set working-directory: ./backend, the directory must exist in your repository:
✅ CORRECT - Directory exists:
my-repo/
├── backend/ ← This directory EXISTS
│ ├── requirements.txt
│ ├── src/
│ └── tests/
└── .github/
└── workflows/
└── ci.yml
❌ INCORRECT - Directory doesn't exist:
my-repo/
├── src/ ← Your code is here, not in /backend
│ ├── requirements.txt
│ └── tests/
└── .github/
└── workflows/
└── ci.yml ← Says working-directory: ./backend (WRONG!)
How to Check Your Project Structure
Run this command in your repository root:
ls -la
You should see your actual directories. Examples:
Scenario 1: Root-level project
my-repo/
├── package.json ← Files at root level
├── src/
├── tests/
└── .github/
Solution: Don't set working-directory (or use ./)
Scenario 2: Backend subdirectory
my-repo/
├── backend/ ← Backend code is here
│ ├── requirements.txt
│ └── tests/
└── .github/
Solution: working-directory: ./backend
Scenario 3: Multiple subdirectories
my-repo/
├── frontend/
│ └── package.json
├── backend/
│ └── requirements.txt
├── services/
│ └── go.mod
└── .github/
Solution: Different working-directory for each job
Common Issues and Solutions
Issue: "Error: Unable to locate executable file: pytest"
Cause: Dependencies not installed or wrong working directory Solution:
- Check if
working-directorypath exists in your repo - Ensure
pip installstep runs before tests - Verify requirements.txt is in the correct location
Issue: "ENOENT: no such file or directory, open 'package.json'"
Cause: npm commands running in wrong directory Solution:
- Find where package.json actually is:
find . -name "package.json" - Set
working-directoryto match that location - Example: If package.json is in
./frontend, useworking-directory: ./frontend
Issue: "go.mod file not found"
Cause: Go commands running in wrong directory Solution:
- Find where go.mod actually is:
find . -name "go.mod" - Set
working-directoryto match that location
Issue: "Could not find Gemfile"
Cause: Bundle commands running in wrong directory Solution:
- Find where Gemfile actually is:
find . -name "Gemfile" - Set
working-directoryto match that location
Issue: "Workflow doesn't run on pull requests"
Cause: Missing pull_request trigger Solution: Add to your workflow:
on:
pull_request:
branches: [ main ]
Checklist Before Committing
- Workflow file is in
.github/workflows/directory - Workflow name contains
test,ci, orbuild(recommended) - Job name contains test-related keywords
pull_requesttrigger is included- If using
working-directory, verify the path actually exists withls -la - Test commands use verbose flags (
-v,--verbose) - Workflow runs successfully on test PR
Language-Specific Notes
Python
- GitHub handles PYTHONPATH automatically - no manual setup needed!
- Use
actions/setup-python@v4for Python version - Install dependencies before running tests
- Common locations:
/,/backend,/api,/src
JavaScript/TypeScript
- Must have package.json in the directory where you run
npm install - Use
actions/setup-node@v3for Node version - If using workspaces/monorepo, set working-directory for each package
- Common locations:
/,/frontend,/web,/client,/app
Go
- Must have go.mod in the directory where you run
go test - Use
actions/setup-go@v4for Go version - Use
./...to run all tests in subdirectories - Common locations:
/,/services,/cmd,/pkg
Ruby
- Must have Gemfile in the directory where you run
bundle install - Use
ruby/setup-ruby@v1withbundler-cache: truefor faster builds - Common locations:
/,/app,/api,/lib
Java
- Must have build.gradle or pom.xml in the directory where you run gradle/maven
- Use
actions/setup-java@v3for Java version - Make gradlew executable:
chmod +x gradlew - Common locations:
/,/service,/app,/backend
How Codity.ai Monitors GitHub Actions
- Workflow Discovery: Finds workflows in
.github/workflows/containing test keywords - Check Run Detection: Monitors check runs on PR commits
- Log Retrieval: Fetches logs from completed check runs
- Failure Analysis: Identifies failed tests and error patterns
- Auto-Fix: Automatically fixes failing tests (up to 3 attempts)
- Status Updates: Posts comments on PR with test results
Testing Your Workflow
- Create workflow file in
.github/workflows/test.yml - Commit and push to a branch
- Create a pull request
- Check that workflow runs automatically
- Verify Codity.ai detects and monitors the workflow
- Check workflow logs in GitHub Actions tab for any errors
Best Practices
DO
- Use descriptive workflow and job names
- Include
pull_requesttrigger - Set
working-directoryonly when files are actually in subdirectories - Use verbose test output flags
- Keep workflows simple and focused
DON'T
- Don't set
working-directoryif files are at repository root - Don't use incorrect paths that don't exist
- Don't skip
pull_requesttrigger - Don't mix multiple languages in one job (use separate jobs instead)
- Don't forget to install dependencies before running tests
Quick Reference: Finding Your Project Files
# Find all package.json files
find . -name "package.json"
# Find all go.mod files
find . -name "go.mod"
# Find all Gemfiles
find . -name "Gemfile"
# Find all requirements.txt files
find . -name "requirements.txt"
# Find all build.gradle files
find . -name "build.gradle"
# List directory structure (first 2 levels)
tree -L 2
# or
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
The output will show you exactly where your files are, so you can set working-directory correctly.
Example: Determining Correct Working Directory
Command:
find . -name "package.json"
Output:
./frontend/package.json
Conclusion: Your package.json is in ./frontend, so use:
working-directory: ./frontend
Need help? Check the GitHub Actions documentation