Skip to content

Commit cc359e1

Browse files
DEV: Update CI workflows (discourse#55)
Co-authored-by: davidtaylorhq <davidtaylorhq@users.noreply.github.com>
1 parent 83d88d3 commit cc359e1

File tree

2 files changed

+47
-31
lines changed

2 files changed

+47
-31
lines changed

.github/workflows/plugin-linting.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Linting
33
on:
44
push:
55
branches:
6-
- master
76
- main
87
pull_request:
98

@@ -15,19 +14,20 @@ jobs:
1514
- uses: actions/checkout@v2
1615

1716
- name: Set up Node.js
18-
uses: actions/setup-node@v1
17+
uses: actions/setup-node@v2
1918
with:
20-
node-version: 12
19+
node-version: 16
20+
cache: yarn
21+
22+
- name: Yarn install
23+
run: yarn install
2124

2225
- name: Set up ruby
2326
uses: ruby/setup-ruby@v1
2427
with:
2528
ruby-version: 2.7
2629
bundler-cache: true
2730

28-
- name: Yarn install
29-
run: yarn install
30-
3131
- name: ESLint
3232
if: ${{ always() }}
3333
run: yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern {test,assets}/javascripts

.github/workflows/plugin-tests.yml

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ name: Plugin Tests
33
on:
44
push:
55
branches:
6-
- master
76
- main
87
pull_request:
98

109
jobs:
1110
build:
1211
name: ${{ matrix.build_type }}
1312
runs-on: ubuntu-latest
14-
container: discourse/discourse_test:release
13+
container: discourse/discourse_test:slim${{ matrix.build_type == 'frontend' && '-browsers' || '' }}
1514
timeout-minutes: 60
1615

1716
env:
1817
DISCOURSE_HOSTNAME: www.example.com
1918
RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072
2019
RAILS_ENV: test
21-
PGHOST: postgres
2220
PGUSER: discourse
2321
PGPASSWORD: discourse
2422

@@ -27,23 +25,6 @@ jobs:
2725

2826
matrix:
2927
build_type: ["backend", "frontend"]
30-
ruby: ["2.7"]
31-
postgres: ["13"]
32-
33-
services:
34-
postgres:
35-
image: postgres:${{ matrix.postgres }}
36-
ports:
37-
- 5432:5432
38-
env:
39-
POSTGRES_USER: discourse
40-
POSTGRES_PASSWORD: discourse
41-
options: >-
42-
--mount type=tmpfs,destination=/var/lib/postgresql/data
43-
--health-cmd pg_isready
44-
--health-interval 10s
45-
--health-timeout 5s
46-
--health-retries 5
4728

4829
steps:
4930
- uses: actions/checkout@v2
@@ -65,14 +46,20 @@ jobs:
6546
- name: Start redis
6647
run: |
6748
redis-server /etc/redis/redis.conf &
49+
50+
- name: Start Postgres
51+
run: |
52+
chown -R postgres /var/run/postgresql
53+
sudo -E -u postgres script/start_test_db.rb
54+
sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';"
6855
6956
- name: Bundler cache
7057
uses: actions/cache@v2
7158
with:
7259
path: vendor/bundle
73-
key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
60+
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
7461
restore-keys: |
75-
${{ runner.os }}-${{ matrix.ruby }}-gem-
62+
${{ runner.os }}-gem-
7663
7764
- name: Setup gems
7865
run: |
@@ -95,18 +82,47 @@ jobs:
9582
id: yarn-cache
9683
with:
9784
path: ${{ steps.yarn-cache-dir.outputs.dir }}
98-
key: ${{ runner.os }}-${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
85+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
9986
restore-keys: |
100-
${{ runner.os }}-${{ matrix.os }}-yarn-
87+
${{ runner.os }}-yarn-
10188
10289
- name: Yarn install
10390
run: yarn install
10491

105-
- name: Migrate database
92+
- name: Fetch app state cache
93+
uses: actions/cache@v2
94+
id: app-cache
95+
with:
96+
path: tmp/app-cache
97+
key: >- # postgres version, hash of migrations, "parallel?"
98+
${{ runner.os }}-
99+
${{ hashFiles('.github/workflows/tests.yml') }}-
100+
${{ matrix.postgres }}-
101+
${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}-
102+
${{ env.USES_PARALLEL_DATABASES }}
103+
104+
- name: Restore database from cache
105+
if: steps.app-cache.outputs.cache-hit == 'true'
106+
run: psql -f tmp/app-cache/cache.sql postgres
107+
108+
- name: Restore uploads from cache
109+
if: steps.app-cache.outputs.cache-hit == 'true'
110+
run: rm -rf public/uploads && cp -r tmp/app-cache/uploads public/uploads
111+
112+
- name: Create and migrate database
113+
if: steps.app-cache.outputs.cache-hit != 'true'
106114
run: |
107115
bin/rake db:create
108116
bin/rake db:migrate
109117
118+
- name: Dump database for cache
119+
if: steps.app-cache.outputs.cache-hit != 'true'
120+
run: mkdir -p tmp/app-cache && pg_dumpall > tmp/app-cache/cache.sql
121+
122+
- name: Dump uploads for cache
123+
if: steps.app-cache.outputs.cache-hit != 'true'
124+
run: rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads
125+
110126
- name: Check spec existence
111127
id: check_spec
112128
shell: bash

0 commit comments

Comments
 (0)