From 3eafe7ff86d4a355a2d12bd331d7013add7d29a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 4 Dec 2024 10:41:56 +0100 Subject: [PATCH] Build assets on CI and add caching (#461) --- .github/workflows/assets.yml | 60 ++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 28 +++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/workflows/assets.yml diff --git a/.github/workflows/assets.yml b/.github/workflows/assets.yml new file mode 100644 index 00000000..24a65e2c --- /dev/null +++ b/.github/workflows/assets.yml @@ -0,0 +1,60 @@ +name: Assets + +on: + push: + branches: + - main + - "v*.*" + +jobs: + build: + runs-on: ubuntu-22.04 + env: + elixir: 1.14.0 + otp: 24.3 + steps: + - uses: actions/checkout@v4 + + - uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ env.elixir }} + otp-version: ${{ env.otp }} + + - name: Cache Mix + uses: actions/cache@v4 + with: + path: | + deps + _build + key: ${{ runner.os }}-mix-${{ env.elixir }}-${{ env.otp }}-${{ hashFiles('**/mix.lock') }}-dev + restore-keys: | + ${{ runner.os }}-mix-${{ env.elixir }}-${{ env.otp }}- + + - name: Install Dependencies + run: mix deps.get --only dev + + - name: Setup Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Cache npm dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install npm dependencies + run: npm ci --prefix assets + + - name: Build assets + run: mix assets.build + + - name: Push updated assets + id: push_assets + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Update assets + file_pattern: dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a81936b6..c12574c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,16 @@ jobs: otp-version: ${{matrix.pair.otp}} elixir-version: ${{matrix.pair.elixir}} + - name: Cache Mix + uses: actions/cache@v4 + with: + path: | + deps + _build + key: ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}-test + restore-keys: | + ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}- + - name: Install Dependencies run: mix deps.get --only test @@ -78,6 +88,16 @@ jobs: elixir-version: 1.14.0 otp-version: 24.3 + - name: Cache Mix + uses: actions/cache@v4 + with: + path: | + deps + _build + key: ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}-test + restore-keys: | + ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}- + - name: Install Dependencies run: mix deps.get --only test @@ -86,6 +106,14 @@ jobs: with: node-version: 18 + - name: Cache npm dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: npm install and test run: | cd assets