From 0cfc6dadad56bfb163a32453ad58ea46cde07411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sun, 27 Sep 2026 14:58:40 +0200 Subject: [PATCH] Add caching in CI --- .gitea/workflows/ci.yml | 53 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index f91ee9e..b6011d2 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -59,6 +59,40 @@ jobs: - name: Install plugin run: cp -r plugin core/plugins/hledger + - name: Container envs + id: container-envs + run: | + echo "ruby_version=$RUBY_VERSION" >> "$GITHUB_OUTPUT" + echo "debian_release=$DEBIAN_RELEASE" >> "$GITHUB_OUTPUT" + + - name: Bundler cache + uses: actions/cache@v4 + with: + path: core/vendor/bundle + key: ${{ runner.os }}-${{ steps.container-envs.outputs.ruby_version }}-${{ steps.container-envs.outputs.debian_release }}-gems-${{ hashFiles('core/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-${{ steps.container-envs.outputs.ruby_version }}-${{ steps.container-envs.outputs.debian_release }}-gems- + + - name: Get pnpm store directory + id: pnpm-store + working-directory: core + run: echo "dir=$(pnpm store path)" >> "$GITHUB_OUTPUT" + + - name: pnpm cache + uses: actions/cache@v4 + with: + path: ${{ steps.pnpm-store.outputs.dir }} + key: ${{ runner.os }}-pnpm-${{ hashFiles('core/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm- + + - name: App state cache + id: app-cache + uses: actions/cache@v4 + with: + path: core/tmp/app-cache + key: ${{ runner.os }}-app-v1-${{ hashFiles('core/db/**/*', 'core/plugins/hledger/db/**/*', 'plugin/.gitea/workflows/ci.yml') }} + - name: Install hledger run: | apt-get update @@ -77,17 +111,32 @@ jobs: - name: Setup gems working-directory: core - run: bundle install + run: | + bundle config set --local path vendor/bundle + bundle config set --local without development + bundle config set --local deployment true + bundle install - name: Install JS dependencies working-directory: core run: pnpm install --frozen-lockfile - - name: Prepare database + - name: Restore database from cache + if: steps.app-cache.outputs.cache-hit == 'true' + working-directory: core + run: | + psql -f tmp/app-cache/cache.sql postgres + 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' working-directory: core run: | bin/rake db:create bin/rake db:migrate + mkdir -p tmp/app-cache + pg_dumpall > tmp/app-cache/cache.sql + rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads - name: Plugin RSpec working-directory: core