diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6d6bb84 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + pull_request: + push: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + env: + PGHOST: localhost + PGUSER: postgres + PGPASSWORD: password + PGDATABASE: scavinator_test + + services: + postgres: + image: postgres:18 + env: + POSTGRES_PASSWORD: password + POSTGRES_DB: scavinator_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Install packages + run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config postgresql-client + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Databases + run: | + bash script/pg_ci_setup.sh + bash script/pg_parallel_test_setup.sh + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Configuration + run: | + cp config/database.sample.yml config/database.yml + cp config/storage.sample.yml config/storage.yml + + - name: Run tests + env: + RAILS_ENV: test + run: bin/rails test diff --git a/config/credentials.sample.yaml b/config/credentials.sample.yml similarity index 99% rename from config/credentials.sample.yaml rename to config/credentials.sample.yml index 58dcec0..73db627 100644 --- a/config/credentials.sample.yaml +++ b/config/credentials.sample.yml @@ -4,4 +4,3 @@ secret_key_base: discord_token: "DISCORD_TOKEN" discord_client_id: "123456789" discord_client_secret: "DISCORD_SECRET" - diff --git a/config/credentials/test.key b/config/credentials/test.key new file mode 100644 index 0000000..5110281 --- /dev/null +++ b/config/credentials/test.key @@ -0,0 +1 @@ +b7f100a8d3f6bf8b2e1068744ce24802 \ No newline at end of file diff --git a/config/credentials/test.yml.enc b/config/credentials/test.yml.enc new file mode 100644 index 0000000..770f759 --- /dev/null +++ b/config/credentials/test.yml.enc @@ -0,0 +1 @@ +Dw79mBAUDu35Z8TAVCFYt+hL7igbNGW53LukZbYoGshNSDhfvkL6s2Let07UQIo0ZeNM7CQM7vkznwT5yDdid2bwh0Ifsvx2xKIDfEAvkrcrE9TkJHDEAlP5QH0jhOodS5MceFhxsCSZFs+NrJLp35IOfXNrQxENWojnu+2SG/F+O6LMWHT1SLQrlwZdnFpglTlgFIhfZ59IQroH5FaIBQ5EXnN5KLcHv0649O7bbcshRLWEQLAy0zavQEQfqcbIlFQVaJ7mlhlcjIo7O8zA/RNMRV3zVbJJa+uEQWzYR94gMUeuj4kytgj9YlHGmHAMV0KenbSaOVOTnWlihgXSBm93SZYArXzp3i76M3khvyFU6WebqiZetZLfJmvpdSg=--DVFlZgusfW7hWmha--hFuBNq+DTZ34xLTphjYdXw== \ No newline at end of file diff --git a/config/database.sample.yml b/config/database.sample.yml index 69b7811..69a3a3e 100644 --- a/config/database.sample.yml +++ b/config/database.sample.yml @@ -19,8 +19,9 @@ development: # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: - <<: *default - database: storage/test.sqlite3 + adapter: postgresql + database: scavinator_test + password: password # Store production database in the storage/ directory, which by default diff --git a/script/pg_ci_setup.sh b/script/pg_ci_setup.sh new file mode 100644 index 0000000..14d7da2 --- /dev/null +++ b/script/pg_ci_setup.sh @@ -0,0 +1 @@ +curl https://raw.githubusercontent.com/Scavinator/scavinator-database/refs/heads/main/schema.sql | psql -d scavinator_test diff --git a/script/pg_parallel_test_setup.sh b/script/pg_parallel_test_setup.sh new file mode 100644 index 0000000..fb217d3 --- /dev/null +++ b/script/pg_parallel_test_setup.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -x + +FILE=$(mktemp) +for i in {0..32}; do + printf "%s\n" "CREATE DATABASE \"scavinator_test_$i\" WITH TEMPLATE scavinator_test;" >> $FILE +done +psql -f $FILE