diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b0e6f72279..a78fbbc1aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,7 @@ on: push: branches: - 'main' + - 'nc-prepare-ci-for-rails-8' pull_request: types: [opened, synchronize, reopened] @@ -70,8 +71,28 @@ jobs: --health-retries 5 steps: - uses: actions/checkout@v4 - - uses: ./.github/actions/setup + - name: Setup the environment + run: cp .sample.env .env + - run: cp spec/example_app/config/database.yml.sample spec/example_app/config/database.yml + - name: Prepare main database schema + run: bin/generate-database-schema + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - name: Appraise Rails ${{ matrix.appraisal }} - run: bundle exec appraisal ${{ matrix.appraisal }} rspec + - name: Set up JS + uses: actions/setup-node@v4 + with: + cache: yarn + - name: Install Ruby dependencies + run: bundle install + env: + BUNDLE_GEMFILE: gemfiles/${{ matrix.appraisal }}.gemfile + - name: Install JS dependencies + run: yarn install + - name: Build assets + run: yarn run build && yarn run build:css + - name: Run tests + run: bundle exec rspec + env: + BUNDLE_GEMFILE: gemfiles/${{ matrix.appraisal }}.gemfile diff --git a/bin/generate-database-schema b/bin/generate-database-schema new file mode 100755 index 0000000000..386d479460 --- /dev/null +++ b/bin/generate-database-schema @@ -0,0 +1,34 @@ +#!/bin/sh + +set -e + +run_in_container() { + container_id=$1 + shift + cmd=$* + + docker exec --workdir /app "$container_id" bash -c "$cmd" +} + +owner=$(whoami) +# get ruby version from .ruby-version +ruby_version="3.2.2" + +echo "Starting container using Ruby $ruby_version..." +container_id=$(docker run --network="host" --env PGHOST --env PGUSER --env PGPASSWORD -d -v .:/app ruby:3.2.2 sleep infinity) + +echo "Check the environment is correct..." +run_in_container "$container_id" "env" + +echo "Run bundle install..." +run_in_container "$container_id" "bundle install" + +echo "Running db:setup..." +run_in_container "$container_id" "bundle exec rake db:setup" + +echo "Tidying up container..." +docker stop "$container_id" > /dev/null +docker rm "$container_id" > /dev/null + +echo "Restoring file permissions..." +sudo chown -R "$owner" .