Stefan Falk
Stefan Falk

Reputation: 25357

How to cache a dependency insallation?

I am currently trying to implement a workflow which requires protobuf to be installed. However, on Ubuntu I have to compile this myself. The problem is that this takes quite some time to do so I figured caching this step is the thing to do.

However, I am not sure how I can use actions/cache for this, if at all possible.

The following is how I am installing protobuf and my Python dependencies:

name: Service

on:
  push:
    branches: [develop, master]

jobs:
  test:
    runs-on: ubuntu-18.04
    steps:
      - name: Install protobuf-3.6.1
        run: |
          wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz
          tar -xvf protobuf-all-3.6.1.tar.gz
          cd protobuf-3.6.1
          ./configure
          make
          make check
          sudo make install
          sudo ldconfig
      - uses: actions/checkout@v2
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip setuptools
          pip install -r requirements.txt

How can I cache these run steps s.t. they don't have to run each time?

Upvotes: 2

Views: 1514

Answers (1)

zzarbi
zzarbi

Reputation: 1852

I tested the following:

name: Service
on:
  push:
    branches: [develop, master]

jobs:
  test:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - name: Load from cache
        id: protobuf
        uses: actions/cache@v1
        with:
          path: protobuf-3.6.1
          key: protobuf3
      - name: Compile protobuf-3.6.1
        if: steps.protobuf.outputs.cache-hit != 'true'
        run: |
          wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz
          tar -xvf protobuf-all-3.6.1.tar.gz
          cd protobuf-3.6.1
          ./configure
          make
          make check
      - name: Install protobuf
        run: |
          cd protobuf-3.6.1
          sudo make install
          sudo ldconfig
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip setuptools
          pip install -r requirements.txt

I would also delete all the source files once it's built.

Upvotes: 2

Related Questions