From 747ad8513f20767d6f66021cc548a308e18b6326 Mon Sep 17 00:00:00 2001 From: zomars Date: Tue, 21 Feb 2023 11:27:22 -0700 Subject: [PATCH] Caches DB --- .github/actions/cache-db/action.yml | 34 ++++++++++++++++++++++++++ .github/workflows/e2e-app-store.yml | 3 +++ .github/workflows/e2e-embed.yml | 3 +++ .github/workflows/e2e.yml | 3 +++ .github/workflows/production-build.yml | 3 +++ 5 files changed, 46 insertions(+) create mode 100644 .github/actions/cache-db/action.yml diff --git a/.github/actions/cache-db/action.yml b/.github/actions/cache-db/action.yml new file mode 100644 index 0000000000..7f1768851b --- /dev/null +++ b/.github/actions/cache-db/action.yml @@ -0,0 +1,34 @@ +name: Cache databse between jobs +description: "Cache or restore if necessary" +inputs: + DATABASE_URL: + required: true + path: + required: false + default: "backups/backup.sql" +runs: + using: "composite" + steps: + - name: Cache database + id: cache-db + uses: actions/cache@v3 + env: + cache-name: cache-db + with: + path: ${{ inputs.path }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ inputs.path }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-${{ env.cache-name }}-${{ inputs.path }}- + - name: Postgres Dump Backup + if: steps.cache-db.outputs.cache-hit != 'true' + uses: tj-actions/pg-dump@v2.3 + with: + database_url: ${{ inputs.DATABASE_URL }} + path: ${{ inputs.path }} + options: "-O" + - name: Postgres Backup Restore + if: steps.cache-db.outputs.cache-hit == 'true' + uses: tj-actions/pg-restore@v4.5 + with: + database_url: ${{ inputs.DATABASE_URL }} + backup_file: ${{ inputs.path }} diff --git a/.github/workflows/e2e-app-store.yml b/.github/workflows/e2e-app-store.yml index 8f3c100763..b47214f58f 100644 --- a/.github/workflows/e2e-app-store.yml +++ b/.github/workflows/e2e-app-store.yml @@ -53,6 +53,9 @@ jobs: - run: echo 'NODE_OPTIONS="--max_old_space_size=4096"' >> $GITHUB_ENV - uses: ./.github/actions/yarn-install - uses: ./.github/actions/yarn-playwright-install + - uses: ./.github/actions/cache-db + with: + DATABASE_URL: postgresql://postgres:@localhost:5432/calendso - name: Run Tests run: yarn test-e2e:app-store diff --git a/.github/workflows/e2e-embed.yml b/.github/workflows/e2e-embed.yml index c31f438b84..2944d3b9d9 100644 --- a/.github/workflows/e2e-embed.yml +++ b/.github/workflows/e2e-embed.yml @@ -57,6 +57,9 @@ jobs: - run: echo 'NODE_OPTIONS="--max_old_space_size=4096"' >> $GITHUB_ENV - uses: ./.github/actions/yarn-install - uses: ./.github/actions/yarn-playwright-install + - uses: ./.github/actions/cache-db + with: + DATABASE_URL: postgresql://postgres:@localhost:5432/calendso - name: Run Tests run: yarn turbo run embed-tests-update-snapshots:ci --scope=@calcom/embed-react --concurrency=1 - name: Upload embed-core results diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index fd1be54951..ef9ddcbb4b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -60,6 +60,9 @@ jobs: - run: echo 'NODE_OPTIONS="--max_old_space_size=4096"' >> $GITHUB_ENV - uses: ./.github/actions/yarn-install - uses: ./.github/actions/yarn-playwright-install + - uses: ./.github/actions/cache-db + with: + DATABASE_URL: postgresql://postgres:@localhost:5432/calendso - run: yarn test-e2e - name: Upload test results if: ${{ always() }} diff --git a/.github/workflows/production-build.yml b/.github/workflows/production-build.yml index 8b9df2aded..63074dd891 100644 --- a/.github/workflows/production-build.yml +++ b/.github/workflows/production-build.yml @@ -80,3 +80,6 @@ jobs: NEXT_PUBLIC_IS_E2E: ${{ env.NEXT_PUBLIC_IS_E2E }} TURBO_TOKEN: ${{ env.TURBO_TOKEN }} TURBO_TEAM: ${{ env.TURBO_TEAM }} + - uses: ./.github/actions/cache-db + with: + DATABASE_URL: ${{ env.DATABASE_URL }}