2

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?

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • How much speed up do you gain by having to download this cached dependency, unzipping it and installing it, vs downloading the source and building it? You may want to consider using a docker image instead. See this [answer](https://stackoverflow.com/a/60920684/2089675) – smac89 May 16 '20 at 04:55

1 Answers1

2

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.

zzarbi
  • 1,832
  • 3
  • 15
  • 29