diff --git a/.github/workflows/matrix-build.yml b/.github/workflows/matrix-build.yml new file mode 100644 index 0000000..4e26b46 --- /dev/null +++ b/.github/workflows/matrix-build.yml @@ -0,0 +1,67 @@ +name: Matrix Build Workflow + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + ruby: ["3.0.3"] + # ruby: ["3.0.3", "3.1.0"] + + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: ${{ secrets.DATABASE_USERNAME }} + POSTGRES_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} + POSTGRES_DB: myapp_test + options: >- + --mount type=tmpfs,destination=/var/lib/postgresql/data + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + + # Install dependencies + - name: Install dependencies + run: | + gem install bundler + bundle install + + # Set environment variables for database connection + - name: Set database connection environment variables + run: | + echo "DATABASE_URL=postgres://${{ secrets.DATABASE_USERNAME }}:${{ secrets.DATABASE_PASSWORD }}@localhost:5432/myapp_test" >> $GITHUB_ENV + echo "RAILS_ENV=test" >> $GITHUB_ENV + + # Create the database + - name: Create the database + run: | + bin/rails db:create + + # Run migrations + - name: Run migrations + run: | + bin/rails db:migrate + + # Run Tests + - name: Run tests + run: | + bin/rails test