|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: plugin-tests-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + check: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + tests_exist: ${{ steps.check_tests.outputs.tests_exist }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Install component |
| 21 | + uses: actions/checkout@v3 |
| 22 | + with: |
| 23 | + path: tmp/component |
| 24 | + fetch-depth: 1 |
| 25 | + |
| 26 | + - name: Check QUnit existence |
| 27 | + id: check_tests |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + if [ 0 -lt $(find tmp/component/test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then |
| 31 | + echo "::set-output name=tests_exist::true" |
| 32 | + fi |
| 33 | +
|
| 34 | + test: |
| 35 | + needs: check |
| 36 | + if: ${{ needs.check.outputs.tests_exist }} |
| 37 | + runs-on: ubuntu-latest |
| 38 | + container: discourse/discourse_test:slim-browsers |
| 39 | + timeout-minutes: 15 |
| 40 | + |
| 41 | + env: |
| 42 | + DISCOURSE_HOSTNAME: www.example.com |
| 43 | + RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072 |
| 44 | + RAILS_ENV: development |
| 45 | + PGUSER: discourse |
| 46 | + PGPASSWORD: discourse |
| 47 | + |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v3 |
| 50 | + with: |
| 51 | + repository: discourse/discourse |
| 52 | + fetch-depth: 1 |
| 53 | + |
| 54 | + - name: Install component |
| 55 | + uses: actions/checkout@v3 |
| 56 | + with: |
| 57 | + path: tmp/component |
| 58 | + fetch-depth: 1 |
| 59 | + |
| 60 | + - name: Setup Git |
| 61 | + run: | |
| 62 | + git config --global user.email "[email protected]" |
| 63 | + git config --global user.name "Discourse CI" |
| 64 | +
|
| 65 | + - name: Start redis |
| 66 | + run: | |
| 67 | + redis-server /etc/redis/redis.conf & |
| 68 | +
|
| 69 | + - name: Start Postgres |
| 70 | + run: | |
| 71 | + chown -R postgres /var/run/postgresql |
| 72 | + sudo -E -u postgres script/start_test_db.rb |
| 73 | + sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';" |
| 74 | +
|
| 75 | + - name: Bundler cache |
| 76 | + uses: actions/cache@v3 |
| 77 | + with: |
| 78 | + path: vendor/bundle |
| 79 | + key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }} |
| 80 | + restore-keys: | |
| 81 | + ${{ runner.os }}-gem- |
| 82 | +
|
| 83 | + - name: Setup gems |
| 84 | + run: | |
| 85 | + gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' Gemfile.lock) |
| 86 | + bundle config --local path vendor/bundle |
| 87 | + bundle config --local deployment true |
| 88 | + bundle config --local without development |
| 89 | + bundle install --jobs 4 |
| 90 | + bundle clean |
| 91 | +
|
| 92 | + - name: Lint English locale |
| 93 | + run: bundle exec ruby script/i18n_lint.rb "tmp/component/locales/en.yml" |
| 94 | + |
| 95 | + - name: Get yarn cache directory |
| 96 | + id: yarn-cache-dir |
| 97 | + run: echo "::set-output name=dir::$(yarn cache dir)" |
| 98 | + |
| 99 | + - name: Yarn cache |
| 100 | + uses: actions/cache@v3 |
| 101 | + id: yarn-cache |
| 102 | + with: |
| 103 | + path: ${{ steps.yarn-cache-dir.outputs.dir }} |
| 104 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 105 | + restore-keys: | |
| 106 | + ${{ runner.os }}-yarn- |
| 107 | +
|
| 108 | + - name: Yarn install |
| 109 | + run: yarn install |
| 110 | + |
| 111 | + - name: Fetch app state cache |
| 112 | + uses: actions/cache@v3 |
| 113 | + id: app-cache |
| 114 | + with: |
| 115 | + path: tmp/app-cache |
| 116 | + key: >- |
| 117 | + ${{ hashFiles('.github/workflows/tests.yml') }}- |
| 118 | + ${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}- |
| 119 | +
|
| 120 | + - name: Restore database from cache |
| 121 | + if: steps.app-cache.outputs.cache-hit == 'true' |
| 122 | + run: psql -f tmp/app-cache/cache.sql postgres |
| 123 | + |
| 124 | + - name: Restore uploads from cache |
| 125 | + if: steps.app-cache.outputs.cache-hit == 'true' |
| 126 | + run: rm -rf public/uploads && cp -r tmp/app-cache/uploads public/uploads |
| 127 | + |
| 128 | + - name: Create and migrate database |
| 129 | + if: steps.app-cache.outputs.cache-hit != 'true' |
| 130 | + run: | |
| 131 | + bin/rake db:create |
| 132 | + bin/rake db:migrate |
| 133 | +
|
| 134 | + - name: Dump database for cache |
| 135 | + if: steps.app-cache.outputs.cache-hit != 'true' |
| 136 | + run: mkdir -p tmp/app-cache && pg_dumpall > tmp/app-cache/cache.sql |
| 137 | + |
| 138 | + - name: Dump uploads for cache |
| 139 | + if: steps.app-cache.outputs.cache-hit != 'true' |
| 140 | + run: rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads |
| 141 | + |
| 142 | + - name: Component QUnit |
| 143 | + run: | |
| 144 | + THEME_NAME=$(ruby -e 'require "json"; puts JSON.parse(File.read("tmp/component/about.json"))["name"]') |
| 145 | + bundle exec rake themes:install -- "--{\"$THEME_NAME\": \"tmp/component\"}" |
| 146 | + UNICORN_TIMEOUT=120 bundle exec rake "themes:qunit[name,$THEME_NAME]" |
| 147 | + timeout-minutes: 10 |
0 commit comments