2023-10-13 21:44:11 +08:00
|
|
|
name: Migration Tests
|
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
paths:
|
2024-03-29 02:46:55 +08:00
|
|
|
- ".github/workflows/migration-tests.yml"
|
2023-10-13 21:44:11 +08:00
|
|
|
- "migrations/**"
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
- stable
|
|
|
|
paths:
|
2024-03-29 02:46:55 +08:00
|
|
|
- ".github/workflows/migration-tests.yml"
|
2023-10-13 21:44:11 +08:00
|
|
|
- "migrations/**"
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
group: migration-tests-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
tests:
|
2024-03-29 03:33:06 +08:00
|
|
|
if: github.event_name == 'pull_request' || github.repository != 'discourse/discourse-private-mirror'
|
2024-04-16 00:47:40 +08:00
|
|
|
name: Tests with Ruby ${{ matrix.ruby }}
|
2023-10-13 21:44:11 +08:00
|
|
|
runs-on: 'ubuntu-latest'
|
|
|
|
container: discourse/discourse_test:slim
|
|
|
|
timeout-minutes: 20
|
|
|
|
|
|
|
|
env:
|
|
|
|
RAILS_ENV: test
|
|
|
|
PGUSER: discourse
|
|
|
|
PGPASSWORD: discourse
|
|
|
|
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
|
|
|
|
matrix:
|
2024-09-09 23:14:39 +08:00
|
|
|
ruby: ["3.3"]
|
2023-10-13 21:44:11 +08:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Set working directory owner
|
|
|
|
run: chown root:root .
|
|
|
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
with:
|
|
|
|
fetch-depth: 1
|
|
|
|
|
|
|
|
- name: Setup Git
|
|
|
|
run: |
|
|
|
|
git config --global user.email "ci@ci.invalid"
|
|
|
|
git config --global user.name "Discourse CI"
|
|
|
|
|
|
|
|
- name: Start redis
|
|
|
|
run: |
|
|
|
|
redis-server /etc/redis/redis.conf &
|
|
|
|
|
|
|
|
- name: Start Postgres
|
|
|
|
run: |
|
|
|
|
chown -R postgres /var/run/postgresql
|
|
|
|
sudo -E -u postgres script/start_test_db.rb
|
|
|
|
sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';"
|
|
|
|
|
2024-03-29 03:33:06 +08:00
|
|
|
- name: Container envs
|
|
|
|
id: container-envs
|
|
|
|
run: |
|
|
|
|
echo "ruby_version=$RUBY_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
echo "debian_release=$DEBIAN_RELEASE" >> $GITHUB_OUTPUT
|
|
|
|
shell: bash
|
|
|
|
|
2023-10-13 21:44:11 +08:00
|
|
|
- name: Bundler cache
|
2024-01-22 18:50:56 +08:00
|
|
|
uses: actions/cache@v4
|
2023-10-13 21:44:11 +08:00
|
|
|
with:
|
|
|
|
path: vendor/bundle
|
2024-04-16 00:47:40 +08:00
|
|
|
key: >-
|
|
|
|
${{ runner.os }}-
|
|
|
|
${{ steps.container-envs.outputs.ruby_version }}-
|
|
|
|
${{ steps.container-envs.outputs.debian_release }}-
|
|
|
|
${{ hashFiles('**/Gemfile.lock') }}-
|
2024-09-09 23:14:39 +08:00
|
|
|
migrations-tooling
|
2023-10-13 21:44:11 +08:00
|
|
|
|
|
|
|
- name: Setup gems
|
|
|
|
run: |
|
|
|
|
gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' Gemfile.lock)
|
|
|
|
bundle config --local path vendor/bundle
|
|
|
|
bundle config --local deployment true
|
|
|
|
bundle config --local without development
|
2024-09-09 23:14:39 +08:00
|
|
|
bundle config --local with migrations
|
2024-03-29 03:33:06 +08:00
|
|
|
bundle install --jobs $(($(nproc) - 1))
|
2024-09-09 23:14:39 +08:00
|
|
|
bundle clean
|
2023-10-13 21:44:11 +08:00
|
|
|
|
2024-09-03 17:51:07 +08:00
|
|
|
- name: pnpm install
|
|
|
|
run: pnpm install --frozen-lockfile
|
2023-10-13 21:44:11 +08:00
|
|
|
|
|
|
|
- name: Fetch app state cache
|
2024-01-22 18:50:56 +08:00
|
|
|
uses: actions/cache@v4
|
2023-10-13 21:44:11 +08:00
|
|
|
id: app-cache
|
|
|
|
with:
|
|
|
|
path: tmp/app-cache
|
|
|
|
key: >-
|
|
|
|
${{ runner.os }}-
|
|
|
|
${{ hashFiles('.github/workflows/tests.yml') }}-
|
|
|
|
${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}-
|
2024-03-29 03:33:06 +08:00
|
|
|
${{ hashFiles('config/environments/test.rb') }}
|
2023-10-13 21:44:11 +08:00
|
|
|
|
|
|
|
- name: Restore database from cache
|
|
|
|
if: steps.app-cache.outputs.cache-hit == 'true'
|
2024-03-29 03:33:06 +08:00
|
|
|
run: script/silence_successful_output psql --quiet -o /dev/null -f tmp/app-cache/cache.sql postgres
|
2023-10-13 21:44:11 +08:00
|
|
|
|
|
|
|
- name: Restore uploads from cache
|
|
|
|
if: steps.app-cache.outputs.cache-hit == 'true'
|
|
|
|
run: rm -rf public/uploads && cp -r tmp/app-cache/uploads public/uploads
|
|
|
|
|
|
|
|
- name: Create and migrate database
|
|
|
|
if: steps.app-cache.outputs.cache-hit != 'true'
|
|
|
|
run: |
|
|
|
|
bin/rake db:create
|
2024-03-29 03:33:06 +08:00
|
|
|
script/silence_successful_output bin/rake db:migrate
|
2023-10-13 21:44:11 +08:00
|
|
|
|
|
|
|
- name: Dump database for cache
|
|
|
|
if: steps.app-cache.outputs.cache-hit != 'true'
|
|
|
|
run: mkdir -p tmp/app-cache && pg_dumpall > tmp/app-cache/cache.sql
|
|
|
|
|
|
|
|
- name: Dump uploads for cache
|
|
|
|
if: steps.app-cache.outputs.cache-hit != 'true'
|
|
|
|
run: rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads
|
|
|
|
|
2024-04-16 00:47:40 +08:00
|
|
|
# - name: Check core database drift
|
|
|
|
# run: |
|
|
|
|
# mkdir /tmp/intermediate_db
|
|
|
|
# ./migrations/scripts/schema_generator /tmp/intermediate_db/base_migration.sql
|
|
|
|
# diff -u migrations/common/intermediate_db_schema/000_base_schema.sql /tmp/intermediate_db/base_migration.sql
|
2024-01-23 01:45:52 +08:00
|
|
|
|
2023-10-13 21:44:11 +08:00
|
|
|
- name: RSpec
|
2024-04-16 00:47:40 +08:00
|
|
|
run: bin/rspec --default-path migrations/spec
|