DEV: Add smoke tests to GH CI #107
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Smoke test | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
- beta | |
- stable | |
concurrency: | |
group: smoke-test-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
jobs: | |
build: | |
if: "!(github.event_name == 'push' && github.repository == 'discourse/discourse-private-mirror')" | |
name: Smoke test | |
runs-on: ubuntu-20.04-8core | |
container: discourse/discourse_test:release | |
timeout-minutes: 20 | |
env: | |
DISCOURSE_HOSTNAME: example.com | |
RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072 | |
RAILS_ENV: production | |
PGUSER: discourse | |
PGPASSWORD: discourse | |
UNICORN_WORKERS: 2 | |
UNICORN_SIDEKIQS: 1 | |
UNICORN_PORT: 80 | |
DISCOURSE_SERVE_STATIC_ASSETS: true | |
steps: | |
- name: Set working directory owner | |
run: chown root:root . | |
- uses: actions/checkout@v3 | |
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';" | |
- name: Bundler cache | |
uses: actions/cache@v3 | |
with: | |
path: vendor/bundle | |
key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-${{ matrix.ruby }}-gem- | |
- 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 | |
bundle install --jobs 4 | |
bundle clean | |
- name: Get yarn cache directory | |
id: yarn-cache-dir | |
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- name: Yarn cache | |
uses: actions/cache@v3 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Yarn install | |
run: yarn install | |
# - name: Checkout official plugins | |
# run: bin/rake plugin:install_all_official | |
# - name: Pull compatible versions of plugins | |
# run: bin/rake plugin:pull_compatible_all | |
- name: Fetch app state cache | |
uses: actions/cache@v3 | |
id: app-cache | |
with: | |
path: tmp/app-cache | |
key: >- # postgres version, hash of migrations, "parallel?" | |
${{ runner.os }}- | |
${{ hashFiles('.github/workflows/smoke.yml') }}- | |
${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }} | |
- name: Restore database from cache | |
if: steps.app-cache.outputs.cache-hit == 'true' | |
run: psql -f tmp/app-cache/cache.sql postgres | |
- 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 | |
bin/rake db:migrate | |
- 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 | |
- name: Assets | |
run: bin/rails themes:update assets:precompile | |
- name: Setup env | |
id: setup_env | |
shell: ruby {0} | |
run: | | |
Dir.chdir(ENV["GITHUB_WORKSPACE"]) do | |
require "./config/environment" | |
user = User.create!(username: "jane", password: "P4ssw0rdUser", email: "jane@example.com") | |
user.activate | |
user.change_trust_level!(4) | |
admin = User.create!(username: "kim", password: "Adm1N_P4ssw0rd", email: "kim@example.com") | |
admin.activate | |
api_key = ApiKey.create!(user: admin) | |
File.write(ENV["GITHUB_OUTPUT"], "api_key=#{api_key.key}\n", mode: "a+") | |
ThemesInstallTask.install({ | |
"unformatted-code-detector": { | |
url: "https://github.com/discourse/unformatted-code-detector" | |
} | |
}) | |
SiteSetting.wizard_enabled = false | |
end | |
- name: Setup host | |
run: echo "127.0.0.1 ${{ env.DISCOURSE_HOSTNAME }}" >> /etc/hosts | |
- name: Start server | |
run: bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb & | |
- name: Warmup | |
run: | | |
curl -s -A "Chrome" --retry 15 --retry-delay 5 --retry-all-errors --max-time 90 http://example.com | |
- name: Smoke test | |
env: | |
URL: http://${{ env.DISCOURSE_HOSTNAME }} | |
WAIT_FOR_URL: 60 | |
DISCOURSE_USERNAME: jane@example.com | |
DISCOURSE_PASSWORD: P4ssw0rd | |
ADMIN_API_USERNAME: kim | |
ADMIN_API_KEY: ${{ steps.setup_env.outputs.api_key }} | |
SMOKE_TEST_THEME_URL: https://github.com/discourse/unformatted-code-detector | |
run: bin/rails smoke:test | |
- name: Print debug output | |
if: ${{ !cancelled() }} | |
run: | | |
tail -n 250 log/production.log | |
tail -n 250 log/unicorn.stderr.log || true |