From d4067a6ae60424aa0a9f76b934a7788b777c86bb Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 17 Feb 2024 16:03:19 +0100 Subject: [PATCH] ci: cache fixtures Only generate fixtures if any grammar from any parser or the parser generation itself has changed. --- .github/actions/cache/action.yml | 25 +++++++++++++++++++++++++ .github/workflows/build.yml | 11 ++++++----- .github/workflows/sanitize.yml | 8 +++++--- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .github/actions/cache/action.yml diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml new file mode 100644 index 00000000..48d50747 --- /dev/null +++ b/.github/actions/cache/action.yml @@ -0,0 +1,25 @@ +name: 'Cache' +description: "This action caches fixtures" +outputs: + cache-hit: + description: 'Cache hit' + value: ${{ steps.cache_output.outputs.cache-hit }} +runs: + using: "composite" + steps: + - uses: actions/cache@v4 + id: cache_fixtures + with: + path: | + test/fixtures/grammars + target/release/tree-sitter-*.wasm + key: fixtures-${{ join(matrix.*, '_') }}-${{ hashFiles( + '.github/workflows/builds.yml', + '.github/workflows/sanitize.yml', + 'cli/src/generate/**', + 'script/generate-fixtures*', + 'test/fixtures/grammars/*/**/src/*.c') }} + + - run: echo "cache-hit=${{ steps.cache_fixtures.outputs.cache-hit }}" >> $GITHUB_OUTPUT + shell: bash + id: cache_output diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e29aff2c..968fcba0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -156,16 +156,17 @@ jobs: - name: Build CLI run: $BUILD_CMD build --release --target=${{ matrix.target }} --features=${CLI_FEATURES} - - name: Fetch fixtures - if: ${{ !matrix.cli-only && inputs.run_test }} # Don't fetch fixtures for only CLI building targets - run: script/fetch-fixtures + - run: script/fetch-fixtures + + - uses: ./.github/actions/cache + id: cache - name: Generate fixtures - if: ${{ !matrix.cli-only && inputs.run_test }} # Can't natively run CLI on Github runner's host + if: ${{ !matrix.cli-only && inputs.run_test && steps.cache.outputs.cache-hit != 'true' }} # Can't natively run CLI on Github runner's host run: script/generate-fixtures - name: Generate WASM fixtures - if: ${{ !matrix.cli-only && !matrix.use-cross && inputs.run_test }} # See comment for the "Build wasm library" step + if: ${{ !matrix.cli-only && !matrix.use-cross && inputs.run_test && steps.cache.outputs.cache-hit != 'true' }} # See comment for the "Build wasm library" step run: script/generate-fixtures-wasm - name: Run main tests diff --git a/.github/workflows/sanitize.yml b/.github/workflows/sanitize.yml index 215bb8fa..936a9cca 100644 --- a/.github/workflows/sanitize.yml +++ b/.github/workflows/sanitize.yml @@ -27,10 +27,12 @@ jobs: - name: Build CLI run: cargo build --release - - name: Fetch fixtures - run: script/fetch-fixtures + - run: script/fetch-fixtures - - name: Generate fixtures + - uses: ./.github/actions/cache + id: cache + + - if: ${{ steps.cache.outputs.cache-hit != 'true' }} run: script/generate-fixtures - name: Run main tests with undefined behaviour sanitizer (UBSAN)