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: - name: Install system dependencies run: | # Detect OS 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 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 elif command -v yum >/dev/null 2>&1; then # CentOS/RHEL yum install -y gcc make libffi-devel postgresql-devel git curl tzdata elif command -v dnf >/dev/null 2>&1; then # Fedora dnf install -y gcc make libffi-devel postgresql-devel git curl tzdata fi - name: Clone repository run: | git clone ${{ github.server_url }}/${{ github.repository }}.git . git checkout ${{ github.sha }} - name: Install bundler run: | cd app gem install bundler -v 2.6.7 - name: Install Ruby dependencies run: | cd app bundle config path vendor/bundle bundle install --jobs 4 --retry 3 - name: Run RSpec tests run: | cd app mkdir -p tmp bundle exec rspec --format progress - name: Test status run: | if [ $? -eq 0 ]; then echo "โœ… All tests passed!" else echo "โŒ Tests failed" exit 1 fi build: needs: test runs-on: docker if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) steps: - name: Install Docker and git run: | if command -v apk >/dev/null 2>&1; then apk add --no-cache docker git elif command -v apt-get >/dev/null 2>&1; then apt-get update && apt-get install -y docker.io git elif command -v yum >/dev/null 2>&1; then yum install -y docker git elif command -v dnf >/dev/null 2>&1; then dnf install -y docker git fi - name: Clone repository run: | git clone ${{ github.server_url }}/${{ github.repository }}.git . git checkout ${{ github.sha }} - name: Build Docker image run: | docker build -t baktainer-test . - name: Test Docker image run: | docker run --rm baktainer-test ruby --version - name: Login to Docker Hub run: | echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - name: Tag and push image run: | IMAGE_NAME="${{ secrets.DOCKER_IMAGE_NAME }}" # Check if IMAGE_NAME is set if [ -z "${IMAGE_NAME}" ]; then echo "โŒ Error: DOCKER_IMAGE_NAME secret is not set" echo "Please configure the DOCKER_IMAGE_NAME secret in your repository settings" echo "Example: jamez001/baktainer" exit 1 fi echo "๐Ÿ“ฆ Pushing to Docker Hub as ${IMAGE_NAME}" # Tag as latest docker tag baktainer-test "${IMAGE_NAME}:latest" docker push "${IMAGE_NAME}:latest" echo "โœ… Pushed ${IMAGE_NAME}:latest" # Tag with version if it's a tag if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then VERSION_TAG="${GITHUB_REF#refs/tags/}" docker tag baktainer-test "${IMAGE_NAME}:${VERSION_TAG}" docker push "${IMAGE_NAME}:${VERSION_TAG}" echo "โœ… Pushed ${IMAGE_NAME}:${VERSION_TAG}" fi echo "โœ… Docker image pushed successfully" 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