baktainer/.forgejo/workflows/shell-only.yml

141 lines
4.2 KiB
YAML
Raw Normal View History

name: Shell-Only CI (No Actions)
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
jobs:
test:
runs-on: docker
container:
image: ruby:3.3-alpine
defaults:
run:
working-directory: ./app
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 /workspace
cd /workspace
git checkout ${{ github.sha }}
cp -r /workspace/* .
cp -r /workspace/.* . 2>/dev/null || true
- name: Install bundler
run: gem install bundler -v 2.6.7
- name: Install Ruby dependencies
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Run RSpec tests
run: |
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 }}"
# Tag as latest
docker tag baktainer-test "${IMAGE_NAME}:latest"
docker push "${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