2025-07-15 11:02:58 -04:00
|
|
|
name: CI Pipeline
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
tags:
|
|
|
|
- 'v*.*.*'
|
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: docker
|
|
|
|
container:
|
|
|
|
image: ruby:3.3-alpine
|
|
|
|
|
|
|
|
steps:
|
2025-07-15 11:25:02 -04:00
|
|
|
- name: Install system dependencies including Node.js
|
2025-07-15 11:02:58 -04:00
|
|
|
run: |
|
2025-07-15 11:29:20 -04:00
|
|
|
# Detect package manager and install dependencies
|
|
|
|
if command -v apk >/dev/null 2>&1; then
|
|
|
|
# Alpine Linux
|
|
|
|
apk add --no-cache build-base libffi-dev linux-headers postgresql-dev git curl tzdata nodejs npm
|
|
|
|
elif command -v apt-get >/dev/null 2>&1; then
|
|
|
|
# Debian/Ubuntu
|
|
|
|
apt-get update && apt-get install -y build-essential libffi-dev libpq-dev git curl tzdata nodejs npm
|
|
|
|
elif command -v yum >/dev/null 2>&1; then
|
|
|
|
# CentOS/RHEL
|
|
|
|
yum install -y gcc make libffi-devel postgresql-devel git curl tzdata nodejs npm
|
|
|
|
elif command -v dnf >/dev/null 2>&1; then
|
|
|
|
# Fedora
|
|
|
|
dnf install -y gcc make libffi-devel postgresql-devel git curl tzdata nodejs npm
|
|
|
|
else
|
|
|
|
echo "Package manager not found. Installing Node.js manually..."
|
|
|
|
# Try to install Node.js from NodeSource if available
|
|
|
|
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
|
|
|
apt-get install -y nodejs || echo "Failed to install Node.js"
|
|
|
|
fi
|
2025-07-15 11:02:58 -04:00
|
|
|
|
2025-07-15 11:25:02 -04:00
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2025-07-15 11:02:58 -04:00
|
|
|
- name: Install bundler
|
2025-07-15 11:40:10 -04:00
|
|
|
run: |
|
|
|
|
cd app
|
|
|
|
gem install bundler -v 2.6.7
|
2025-07-15 11:02:58 -04:00
|
|
|
|
|
|
|
- name: Cache Ruby gems
|
|
|
|
uses: actions/cache@v4
|
|
|
|
with:
|
|
|
|
path: app/vendor/bundle
|
|
|
|
key: ${{ runner.os }}-gems-${{ hashFiles('app/Gemfile.lock') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-gems-
|
|
|
|
|
|
|
|
- name: Install Ruby dependencies
|
|
|
|
run: |
|
2025-07-15 11:40:10 -04:00
|
|
|
cd app
|
2025-07-15 11:02:58 -04:00
|
|
|
bundle config path vendor/bundle
|
|
|
|
bundle install --jobs 4 --retry 3
|
|
|
|
|
|
|
|
- name: Run RSpec tests
|
|
|
|
run: |
|
2025-07-15 11:40:10 -04:00
|
|
|
cd app
|
2025-07-15 11:02:58 -04:00
|
|
|
mkdir -p tmp
|
|
|
|
bundle exec rspec \
|
|
|
|
--format progress \
|
|
|
|
--format RspecJunitFormatter \
|
|
|
|
--out tmp/rspec_results.xml
|
|
|
|
|
|
|
|
- name: Upload test results
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
if: always()
|
|
|
|
with:
|
|
|
|
name: rspec-results
|
|
|
|
path: app/tmp/rspec_results.xml
|
|
|
|
|
|
|
|
build:
|
|
|
|
needs: test
|
|
|
|
runs-on: docker
|
|
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
|
|
|
|
|
|
|
|
steps:
|
2025-07-15 11:25:02 -04:00
|
|
|
- name: Install Node.js for actions
|
|
|
|
run: |
|
2025-07-15 11:29:20 -04:00
|
|
|
# Detect package manager and install Node.js
|
|
|
|
if command -v apk >/dev/null 2>&1; then
|
|
|
|
apk add --no-cache nodejs npm
|
|
|
|
elif command -v apt-get >/dev/null 2>&1; then
|
|
|
|
apt-get update && apt-get install -y nodejs npm
|
|
|
|
elif command -v yum >/dev/null 2>&1; then
|
|
|
|
yum install -y nodejs npm
|
|
|
|
elif command -v dnf >/dev/null 2>&1; then
|
|
|
|
dnf install -y nodejs npm
|
|
|
|
else
|
|
|
|
echo "Package manager not found. Installing Node.js manually..."
|
|
|
|
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
|
|
|
apt-get install -y nodejs || echo "Failed to install Node.js"
|
|
|
|
fi
|
2025-07-15 11:25:02 -04:00
|
|
|
|
2025-07-15 11:02:58 -04:00
|
|
|
- name: Checkout repository
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- name: Log in to Docker Hub
|
|
|
|
uses: docker/login-action@v3
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
|
|
|
|
- name: Extract version tag
|
|
|
|
id: version
|
|
|
|
run: |
|
|
|
|
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
|
|
|
|
echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Set image tags
|
|
|
|
id: tags
|
|
|
|
run: |
|
|
|
|
IMAGE_NAME=${{ secrets.DOCKER_IMAGE_NAME }}
|
|
|
|
TAGS="${IMAGE_NAME}:latest"
|
|
|
|
if [ -n "${{ steps.version.outputs.VERSION_TAG }}" ]; then
|
|
|
|
TAGS="$TAGS,${IMAGE_NAME}:${{ steps.version.outputs.VERSION_TAG }}"
|
|
|
|
fi
|
|
|
|
echo "tags=$TAGS" >> $GITHUB_OUTPUT
|
|
|
|
|
|
|
|
- name: Build and push Docker image
|
|
|
|
uses: docker/build-push-action@v5
|
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
push: true
|
|
|
|
tags: ${{ steps.tags.outputs.tags }}
|
|
|
|
|
|
|
|
notify:
|
|
|
|
needs: [test, build]
|
|
|
|
runs-on: docker
|
|
|
|
if: always()
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Notify pipeline status
|
|
|
|
run: |
|
|
|
|
echo "📊 Pipeline Status Report:"
|
|
|
|
echo "🧪 Tests: ${{ needs.test.result }}"
|
|
|
|
if [ "${{ needs.build.result }}" != "skipped" ]; then
|
|
|
|
echo "🐳 Build: ${{ needs.build.result }}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${{ needs.test.result }}" == "success" ]; then
|
|
|
|
echo "✅ All tests passed!"
|
|
|
|
else
|
|
|
|
echo "❌ Tests failed"
|
|
|
|
fi
|