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