From 7c455b86b6807062902091ce3660f3429cd42fc7 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 27 Sep 2021 20:50:27 -0300 Subject: [PATCH] feat(ci): cache cli.js's template test (#2670) --- .github/workflows/artifacts-updater.yml | 2 +- .github/workflows/bench.yml | 2 +- .github/workflows/test-bundler.yml | 2 +- .github/workflows/test-core.yml | 15 +++++++++++++-- .../cli.js/test/jest/__tests__/template.spec.js | 14 +++++++++++++- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/artifacts-updater.yml b/.github/workflows/artifacts-updater.yml index 037106b1c..85865e170 100644 --- a/.github/workflows/artifacts-updater.yml +++ b/.github/workflows/artifacts-updater.yml @@ -83,7 +83,7 @@ jobs: with: path: tooling/cli.rs/target # Add date to the cache to keep it up to date - key: ubuntu-latest-nightly-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }}-${{ env.CURRENT_DATE }} + key: ${{ matrix.platform }}-stable-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }}-${{ env.CURRENT_DATE }} # Restore from outdated cache for speed restore-keys: | ${{ matrix.platform }}-stable-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }} diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index c6ec05db4..878b3745b 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -84,7 +84,7 @@ jobs: with: path: tooling/bench/tests/target # Add date to the cache to keep it up to date - key: ubuntu-latest-nightly-cargo-benches-${{ hashFiles('tooling/bench/tests/Cargo.lock') }}-${{ env.CURRENT_DATE }} + key: ${{ matrix.platform }}-nightly-cargo-benches-${{ hashFiles('tooling/bench/tests/Cargo.lock') }}-${{ env.CURRENT_DATE }} # Restore from outdated cache for speed restore-keys: | ${{ matrix.platform }}-nightly-cargo-benches-${{ hashFiles('tooling/bench/tests/Cargo.lock') }} diff --git a/.github/workflows/test-bundler.yml b/.github/workflows/test-bundler.yml index 6f88392d8..ffa64df68 100644 --- a/.github/workflows/test-bundler.yml +++ b/.github/workflows/test-bundler.yml @@ -72,7 +72,7 @@ jobs: with: path: tooling/bundler/target # Add date to the cache to keep it up to date - key: ubuntu-latest-stable-cargo-bundler-${{ hashFiles('tooling/bundler/Cargo.lock') }}-${{ env.CURRENT_DATE }} + key: ${{ matrix.platform }}-stable-cargo-bundler-${{ hashFiles('tooling/bundler/Cargo.lock') }}-${{ env.CURRENT_DATE }} # Restore from outdated cache for speed restore-keys: | ${{ matrix.platform }}-stable-cargo-bundler-${{ hashFiles('tooling/bundler/Cargo.lock') }} diff --git a/.github/workflows/test-core.yml b/.github/workflows/test-core.yml index 6a8967dac..b33b1bad2 100644 --- a/.github/workflows/test-core.yml +++ b/.github/workflows/test-core.yml @@ -135,7 +135,7 @@ jobs: with: path: tooling/cli.rs/target # Add date to the cache to keep it up to date - key: ubuntu-latest-nightly-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }}-${{ env.CURRENT_DATE }} + key: ${{ matrix.platform }}-stable-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }}-${{ env.CURRENT_DATE }} # Restore from outdated cache for speed restore-keys: | ${{ matrix.platform }}-stable-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }} @@ -198,12 +198,23 @@ jobs: with: path: tooling/cli.rs/target # Add date to the cache to keep it up to date - key: ubuntu-latest-nightly-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }}-${{ env.CURRENT_DATE }} + key: ${{ matrix.platform }}-stable-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }}-${{ env.CURRENT_DATE }} # Restore from outdated cache for speed restore-keys: | ${{ matrix.platform }}-stable-cargo-cli-${{ hashFiles('tooling/cli.rs/Cargo.lock') }} ${{ matrix.platform }}-stable-cargo-cli- + - name: Cache template cargo target + uses: actions/cache@v2 + with: + path: tooling/cli.js/test/jest/fixtures/empty/src-tauri/target + # Add date to the cache to keep it up to date + key: ${{ matrix.platform }}-stable-template-${{ hashFiles('tooling/cli.rs/templates/app/**') }}-${{ env.CURRENT_DATE }} + # Restore from outdated cache for speed + restore-keys: | + ${{ matrix.platform }}-stable-template-${{ hashFiles('tooling/cli.rs/templates/app/**') }} + ${{ matrix.platform }}-stable-template- + - name: test timeout-minutes: 30 run: | diff --git a/tooling/cli.js/test/jest/__tests__/template.spec.js b/tooling/cli.js/test/jest/__tests__/template.spec.js index c05d87c1d..019244e0d 100644 --- a/tooling/cli.js/test/jest/__tests__/template.spec.js +++ b/tooling/cli.js/test/jest/__tests__/template.spec.js @@ -1,6 +1,7 @@ import * as fixtureSetup from '../fixtures/app-test-setup.js' import { resolve, dirname } from 'path' -import { writeFileSync, readFileSync } from 'fs' +import { existsSync, readFileSync, writeFileSync } from 'fs' +import { move } from 'fs-extra' import { init, build } from 'dist/api/cli' import { fileURLToPath } from 'url' @@ -11,11 +12,18 @@ describe('[CLI] cli.js template', () => { const cwd = process.cwd() const fixturePath = resolve(currentDirName, '../fixtures/empty') const tauriFixturePath = resolve(fixturePath, 'src-tauri') + const outPath = resolve(tauriFixturePath, 'target') + const cacheOutPath = resolve(fixturePath, 'target') fixtureSetup.initJest('empty') process.chdir(fixturePath) + const outExists = existsSync(outPath) + if (outExists) { + await move(outPath, cacheOutPath) + } + const { promise } = await init({ directory: process.cwd(), force: true, @@ -24,6 +32,10 @@ describe('[CLI] cli.js template', () => { }) await promise + if (outExists) { + await move(cacheOutPath, outPath) + } + process.chdir(tauriFixturePath) const manifestPath = resolve(tauriFixturePath, 'Cargo.toml')