Skip to content

Team E2563 - Review Tableau API #499

Team E2563 - Review Tableau API

Team E2563 - Review Tableau API #499

Workflow file for this run

name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
env:
DATABASE_URL: mysql2://root:expertiza@127.0.0.1:3306/expertiza_test
RAILS_ENV: test
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: expertiza
MYSQL_DATABASE: expertiza_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v3
- name: Clear Ruby cache
run: |
rm -rf ~/.ruby-version
rm -rf ~/.rbenv
rm -rf ~/.rvm
rm -rf /usr/local/rvm
rm -rf /opt/ruby
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4.5
bundler-cache: false
- name: Check Ruby Version
run: |
ruby -v
which ruby
gem env
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y netcat-traditional
- name: Install Ruby dependencies
run: |
gem update --system
gem install bundler:2.4.7
bundle config set --local deployment 'false'
bundle config set --local without ''
bundle config set --local force_ruby_platform true
bundle install --verbose
- name: Setup database
run: |
bundle exec rails db:create RAILS_ENV=test
bundle exec rails db:schema:load RAILS_ENV=test
- name: Set up code coverage
run: |
echo "SimpleCov coverage reporting is configured in spec_helper.rb"
- name: Run model tests
run: bundle exec rspec spec/models
- name: Run controller tests
run: bundle exec rspec spec/requests/
- name: Generate coverage report
run: |
echo "Coverage report generated in coverage/index.html"
ls -la coverage/ || echo "No coverage directory found"
if [ -f coverage/index.html ]; then
echo "✅ Coverage report generated successfully"
echo "📊 Coverage percentage:"
grep -o '[0-9]\+\.[0-9]\+%' coverage/index.html | head -1 || echo "Coverage percentage not found"
else
echo "❌ Coverage report not generated"
fi
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: code-coverage-artifacts
path: coverage/
- name: Comment coverage on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
try {
// Read coverage data
const coveragePath = 'coverage/coverage.json';
if (fs.existsSync(coveragePath)) {
const coverage = JSON.parse(fs.readFileSync(coveragePath, 'utf8'));
const percentage = coverage.metrics.covered_percent.toFixed(2);
const comment = `## 📊 Code Coverage Report
**Coverage: ${percentage}%**
- **Lines covered:** ${coverage.metrics.covered_lines}/${coverage.metrics.total_lines}
- **Branches covered:** ${coverage.metrics.covered_branches}/${coverage.metrics.total_branches}
📈 Coverage report generated with SimpleCov and Ruby 3.4.5
<details>
<summary>View detailed coverage report</summary>
Coverage artifacts are available in the workflow run.
</details>`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} else {
console.log('Coverage file not found');
}
} catch (error) {
console.log('Error creating coverage comment:', error.message);
}
publish_code_coverage:
needs: test # Ensures this job runs after the test job
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main' # Only run when there's a push to main branch
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v4
with:
name: code-coverage-artifacts
path: coverage/
- name: Upload code-coverage report to code-climate
run: |
export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"
gem install codeclimate-test-reporter
cc-test-reporter sum-coverage coverage/codeclimate.*.json
cc-test-reporter after-build -t simplecov -r ${{ secrets.CC_TEST_REPORTER_ID }}
docker:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
push: false
tags: expertiza-backend:latest