diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml deleted file mode 100644 index 44a3513dbf..0000000000 --- a/.github/actions/setup/action.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -name: Setup -description: Shared setup steps -inputs: - ruby-version: - required: true -runs: - using: composite - steps: - - name: Set up Ruby ${{ inputs.ruby-version }} - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ inputs.ruby-version }} - bundler-cache: true - - name: Set up JS - uses: actions/setup-node@v4 - with: - cache: yarn - - name: Install Ruby dependencies - run: bundle install - shell: bash - - name: Install Appraisal dependencies - run: bundle exec appraisal install - shell: bash - - name: Install JS dependencies - run: yarn install - shell: bash - - name: Setup the environment - run: cp .sample.env .env - shell: bash - - run: cp spec/example_app/config/database.yml.sample spec/example_app/config/database.yml - shell: bash - - name: Setup the database - run: bundle exec rake db:setup - shell: bash - - name: Build assets - run: yarn run build && yarn run build:css - shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b0e6f72279..5adc4ed783 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,9 +34,28 @@ jobs: --health-retries 5 steps: - uses: actions/checkout@v4 - - uses: ./.github/actions/setup + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Set up JS + uses: actions/setup-node@v4 + with: + cache: yarn + - name: Install Ruby dependencies + run: bundle install + - name: Install Appraisal dependencies + run: bundle exec appraisal install + - name: Install JS dependencies + run: yarn install + - 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: Setup the database + run: bundle exec rake db:setup + - name: Build assets + run: yarn run build && yarn run build:css - name: Run tests run: bundle exec rspec @@ -70,8 +89,30 @@ 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: Remove Ruby version specification + run: sed -i 's/^ruby\(.*\)//g' gemfiles/${{ matrix.appraisal }}.gemfile + - 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..948590899c --- /dev/null +++ b/bin/generate-database-schema @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +run_in_container() { + container_id=$1 + shift + cmd=$* + + docker exec --workdir /app "$container_id" bash -c "$cmd" +} + +ruby_version=$(cat .ruby-version) +owner=$(whoami) + +echo "Starting container using Ruby $ruby_version..." +container_id=$( + docker run --network="host" \ + --env PGHOST --env PGUSER --env PGPASSWORD \ + -d -v .:/app ruby:"$ruby_version" 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" .