Skip to content

CI

CI #639

Workflow file for this run

name: CI
on:
pull_request:
push:
branches: [ main ]
schedule:
- cron: "30 6 * * *"
jobs:
lint:
runs-on: ubuntu-latest
env:
BUNDLE_FORCE_RUBY_PLATFORM: "true"
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 4.0.1
bundler-cache: true
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install Node dependencies
run: npm ci
- name: Lint frontend assets
run: npm run lint
- name: Verify committed assets are current
run: |
npm run build
if ! git diff --quiet app/assets/builds/source_monitor/; then
echo "::error::Committed assets are stale. Run 'npm run build' and commit the changes."
git diff --stat app/assets/builds/source_monitor/
exit 1
fi
- name: Lint code for consistent style
run: bin/rubocop -f github
- name: Verify setup files have matching tests
run: bin/check-setup-tests
security:
runs-on: ubuntu-latest
env:
BUNDLE_FORCE_RUBY_PLATFORM: "true"
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 4.0.1
bundler-cache: true
- name: Run Brakeman security scanner
run: bin/brakeman --no-pager
test:
runs-on: ubuntu-latest
env:
BUNDLE_FORCE_RUBY_PLATFORM: "true"
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sourcemon_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config google-chrome-stable
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 4.0.1
bundler-cache: true
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install Node dependencies
run: npm ci
- name: Build assets
run: npm run build
- name: Run tests with coverage
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TEST_DB: sourcemon_dummy_test
# REDIS_URL: redis://localhost:6379/0
run: bin/rails db:create db:migrate && bin/test-coverage
- name: Enforce diff coverage
run: bundle exec ruby bin/check-diff-coverage
- name: Verify coverage artifact
run: |
if [ ! -f coverage/.resultset.json ]; then
echo "coverage/.resultset.json not found!"
ls -Rla coverage || echo "coverage directory missing"
exit 1
fi
- name: Upload coverage report
uses: actions/upload-artifact@v7
with:
name: coverage
path: coverage
include-hidden-files: true
if-no-files-found: error
- name: Keep screenshots from failed system tests
uses: actions/upload-artifact@v7
if: failure()
with:
name: screenshots
path: ${{ github.workspace }}/tmp/screenshots
if-no-files-found: ignore
release_verification:
runs-on: ubuntu-latest
needs: [ lint, security, test ]
env:
BUNDLE_FORCE_RUBY_PLATFORM: "true"
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sourcemon_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev libsqlite3-dev pkg-config postgresql-client
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 4.0.1
bundler-cache: true
- name: Prepare database
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TEST_DB: sourcemon_dummy_test
run: bin/rails db:create db:migrate
- name: Reset coverage directory
run: rm -rf coverage
- name: Download coverage artifacts
uses: actions/download-artifact@v8
with:
name: coverage
path: coverage
- name: Backup coverage result
run: |
mkdir -p tmp/ci-coverage
RESULTSET_PATH=$(find coverage -name ".resultset.json" -print -quit)
if [ -z "$RESULTSET_PATH" ]; then
echo "Unable to locate coverage result after artifact download"
exit 1
fi
cp "$RESULTSET_PATH" tmp/ci-coverage/resultset.json
- name: Run release packaging verification
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TEST_DB: sourcemon_dummy_test
SOURCE_MONITOR_SKIP_COVERAGE: "true"
run: bin/rails test test/integration/release_packaging_test.rb
- name: Restore coverage result if missing
run: |
if [ ! -f coverage/.resultset.json ] && [ -f tmp/ci-coverage/resultset.json ]; then
echo "Restoring coverage result from backup after packaging verification"
mkdir -p coverage
cp tmp/ci-coverage/resultset.json coverage/.resultset.json
fi
- name: Enforce diff coverage
run: bundle exec ruby bin/check-diff-coverage
profiling:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
env:
BUNDLE_FORCE_RUBY_PLATFORM: "true"
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sourcemon_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev libsqlite3-dev pkg-config google-chrome-stable
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 4.0.1
bundler-cache: true
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install Node dependencies
run: npm ci
- name: Build assets
run: npm run build
- name: Prepare database
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TEST_DB: sourcemon_dummy_test
run: bundle exec rails db:create db:migrate
- name: Run TagProf suite
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TEST_DB: sourcemon_dummy_test
SOURCE_MONITOR_SKIP_COVERAGE: "true"
SOURCE_MONITOR_TEST_WORKERS: "1"
TAG_PROF: type
run: |
set -o pipefail
mkdir -p tmp/test_prof
bundle exec rails test | tee tmp/test_prof/tag_prof_type.log
- name: Run EventProf suite
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TEST_DB: sourcemon_dummy_test
SOURCE_MONITOR_SKIP_COVERAGE: "true"
SOURCE_MONITOR_TEST_WORKERS: "1"
EVENT_PROF: sql.active_record
run: |
set -o pipefail
bundle exec rails test | tee tmp/test_prof/event_prof_sql.log
- name: Run StackProf on integration tests
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TEST_DB: sourcemon_dummy_test
SOURCE_MONITOR_SKIP_COVERAGE: "true"
SOURCE_MONITOR_TEST_WORKERS: "1"
TEST_STACK_PROF: "1"
run: |
set -o pipefail
bundle exec rails test test/integration | tee tmp/test_prof/stack_prof_integration.log
- name: Enforce profiling guardrails
run: bundle exec ruby bin/check-test-prof-metrics
- name: Upload profiling artifacts
uses: actions/upload-artifact@v7
with:
name: test-prof-metrics
path: tmp/test_prof
if-no-files-found: error