A platform for community discussion. Free, open, simple.
DEV: Cache database in GitHub actions tests (#15279)
David Tayloreb3eae2fccb3
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 7f52de106f5..c26056ece29 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -24,6 +24,7 @@ jobs:PGHOST: postgresPGUSER: discoursePGPASSWORD: discourse+ USES_PARALLEL_DATABASES: ${{ matrix.build_type == 'backend' && matrix.target == 'core' }}strategy:fail-fast: false@@ -102,17 +103,48 @@ jobs:if: matrix.target == 'plugins'run: bin/rake plugin:install_all_official- - name: Create database+ - name: Fetch app state cache+ uses: actions/cache@v2+ id: app-cache+ with:+ path: tmp/app-cache+ key: >- # postgres version, hash of migrations, "parallel?"+ ${{ runner.os }}-+ ${{ hashFiles('.github/workflows/tests.yml') }}-+ ${{ matrix.postgres }}-+ ${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}-+ ${{ env.USES_PARALLEL_DATABASES }}++ - 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:createbin/rake db:migrate- - name: Create parallel databases- if: matrix.build_type == 'backend' && matrix.target == 'core'+ - name: Create and migrate parallel databases+ if: >-+ env.USES_PARALLEL_DATABASES == 'true' &&+ steps.app-cache.outputs.cache-hit != 'true'run: |bin/rake parallel:createbin/rake parallel: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: Core RSpecif: matrix.build_type == 'backend' && matrix.target == 'core'run: bin/turbo_rspec --verbose