@@ -3,22 +3,20 @@ name: Plugin Tests
3
3
on :
4
4
push :
5
5
branches :
6
- - master
7
6
- main
8
7
pull_request :
9
8
10
9
jobs :
11
10
build :
12
11
name : ${{ matrix.build_type }}
13
12
runs-on : ubuntu-latest
14
- container : discourse/discourse_test:release
13
+ container : discourse/discourse_test:slim${{ matrix.build_type == 'frontend' && '-browsers' || '' }}
15
14
timeout-minutes : 60
16
15
17
16
env :
18
17
DISCOURSE_HOSTNAME : www.example.com
19
18
RUBY_GLOBAL_METHOD_CACHE_SIZE : 131072
20
19
RAILS_ENV : test
21
- PGHOST : postgres
22
20
PGUSER : discourse
23
21
PGPASSWORD : discourse
24
22
27
25
28
26
matrix :
29
27
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
47
28
48
29
steps :
49
30
- uses : actions/checkout@v2
@@ -65,14 +46,20 @@ jobs:
65
46
- name : Start redis
66
47
run : |
67
48
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';"
68
55
69
56
- name : Bundler cache
70
57
uses : actions/cache@v2
71
58
with :
72
59
path : vendor/bundle
73
- key : ${{ runner.os }}-${{ matrix.ruby }}- gem-${{ hashFiles('**/Gemfile.lock') }}
60
+ key : ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
74
61
restore-keys : |
75
- ${{ runner.os }}-${{ matrix.ruby }}- gem-
62
+ ${{ runner.os }}-gem-
76
63
77
64
- name : Setup gems
78
65
run : |
@@ -95,18 +82,47 @@ jobs:
95
82
id : yarn-cache
96
83
with :
97
84
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') }}
99
86
restore-keys : |
100
- ${{ runner.os }}-${{ matrix.os }}- yarn-
87
+ ${{ runner.os }}-yarn-
101
88
102
89
- name : Yarn install
103
90
run : yarn install
104
91
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'
106
114
run : |
107
115
bin/rake db:create
108
116
bin/rake db:migrate
109
117
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
+
110
126
- name : Check spec existence
111
127
id : check_spec
112
128
shell : bash
0 commit comments