This repository contains template workflows for CodeQL security scanning. Follow these steps to enable CodeQL on your actual project repositories.
-
Navigate to your project:
cd /path/to/your/project -
Create the workflow directory:
mkdir -p .github/workflows
-
Copy the workflow file:
cp /Users/dafesmithofoh/codeql/.github/workflows/codeql-org-security.yml .github/workflows/
-
Customize for your languages (edit
.github/workflows/codeql-org-security.yml):# Change this line to match your project's languages: language: [ 'javascript', 'python' ] # Only your languages
-
Commit and push:
git add .github/ git commit -m "Enable CodeQL security scanning" git push -
Done! Check results at:
- Actions:
https://github.com/dafesmith/YOUR-REPO/actions - Security:
https://github.com/dafesmith/YOUR-REPO/security/code-scanning
- Actions:
# Clone your project
gh repo clone dafesmith/YOUR-PROJECT
cd YOUR-PROJECT
# Copy workflow
mkdir -p .github/workflows
cp /Users/dafesmithofoh/codeql/.github/workflows/codeql-org-security.yml .github/workflows/
# Commit and push
git add .github/
git commit -m "Enable CodeQL security scanning"
git pushCreate a file deploy-codeql.sh:
#!/bin/bash
# List of your repositories (add your actual repo names)
REPOS=(
"your-web-app"
"your-api-service"
"your-mobile-app"
"your-backend"
)
# Path to the workflow template
WORKFLOW_FILE="/Users/dafesmithofoh/codeql/.github/workflows/codeql-org-security.yml"
for repo in "${REPOS[@]}"; do
echo "Enabling CodeQL for $repo..."
# Clone the repository
gh repo clone dafesmith/$repo temp-$repo
cd temp-$repo
# Create workflow directory
mkdir -p .github/workflows
# Copy workflow file
cp "$WORKFLOW_FILE" .github/workflows/
# Commit and push
git add .github/
git commit -m "Enable CodeQL security scanning"
git push
# Cleanup
cd ..
rm -rf temp-$repo
echo "✓ CodeQL enabled for $repo"
done
echo "Done! CodeQL enabled for all repositories."Run it:
chmod +x deploy-codeql.sh
./deploy-codeql.shlanguage: [ 'javascript' ]
# No build steps neededlanguage: [ 'python' ]
# No build steps neededlanguage: [ 'java' ]
# Autobuild usually works, but if not:
- name: Build Java
if: matrix.language == 'java'
run: |
mvn clean install -DskipTests
# OR for Gradle:
# ./gradlew build -x testlanguage: [ 'javascript', 'python' ]
# No build steps neededlanguage: [ 'csharp' ]
# Add build step:
- name: Build C#
if: matrix.language == 'csharp'
run: |
dotnet restore
dotnet build --no-restorelanguage: [ 'go' ]
# Autobuild usually workslanguage: [ 'ruby' ]
# No build steps neededCodeQL will automatically scan your code:
- ✅ On every push to main/master/develop branches
- ✅ On every pull request to these branches
- ✅ Weekly (every Monday at 2 AM)
-
Security Tab:
- Go to:
https://github.com/dafesmith/YOUR-REPO/security/code-scanning - See all detected vulnerabilities
- Get AI-powered fix suggestions
- Go to:
-
Pull Request Checks:
- CodeQL status appears on PRs
- Blocks merge if critical issues found (optional)
-
Email Notifications:
- You'll receive emails for new security findings
- Configure in repository settings
Edit the cron schedule:
schedule:
- cron: '0 2 * * 1' # Monday 2 AM
# OR
- cron: '0 9 * * *' # Every day at 9 AM
# OR
- cron: '0 0 * * 0' # Sunday midnighton:
push:
branches: [ "main" ]on:
push:
branches: [ "main", "staging", "production" ]
pull_request:
branches: [ "main", "staging", "production" ]Add to workflow:
on:
push:
branches: [ "main" ]
paths-ignore:
- 'docs/**'
- '*.md'
- 'tests/**'Require CodeQL to pass before merging:
- Go to: Settings → Branches → Add rule
- Branch name:
main - Check: Require status checks to pass
- Select: CodeQL
- Save
Now PRs with security issues can't be merged!
Fix: Ensure your repository contains code files (not just configs)
Fix: Replace autobuild with custom build steps (see language-specific sections above)
Fix: Check that you pushed to main/master/develop branches
Fix: Reduce languages or use the PR-specific workflow for faster scans
# .github/workflows/codeql-org-security.yml
language: [ 'javascript' ]# .github/workflows/codeql-org-security.yml
language: [ 'javascript', 'python' ]# .github/workflows/codeql-org-security.yml
language: [ 'javascript', 'python', 'java', 'go' ]Q: Do I need GitHub Advanced Security? A: For private repos, yes. Public repos get it free.
Q: How long does scanning take? A: 2-10 minutes for small projects, 15-60 minutes for large ones.
Q: Will it slow down my CI/CD? A: CodeQL runs in parallel with your tests, minimal impact.
Q: Can I customize which vulnerabilities to report?
A: Yes, edit .github/codeql/codeql-org-config.yml (copy from this repo first)
Q: Does it scan dependencies? A: No, that's Dependabot. CodeQL scans YOUR code for vulnerabilities.
Q: What if I get too many false positives? A: Dismiss them in the Security tab with justification, or tune the config.
- Documentation: ORGANIZATION_SETUP.md
- CodeQL Docs: https://codeql.github.com/docs/
- GitHub Support: https://support.github.com/
Ready to secure your code? Start with one repository, verify it works, then roll out to all projects! 🛡️
