def

def

Github actions compilation/caching issues

Hey folks!

Been through it all with elixir compilation. We were using Concourse for a bit, which allowed me to run images that had our application pre-compiled. I would rsync the files into the cloned branch, and only the changed files would compile.

For many reasons we moved to github actions, and since then I have been unable to create a setup that doesn’t compile/get dependencies every time. We also have issues with branches that change our structure.sql file, as the test runs depend on seeding a database, and new relations tend to not be applied unless we we “bust the cache” by incrementing a version number in the build cache string.

This all has created the headache of using up our minutes quite rapidly as our team (or a pull request) grows, and dipping deeply into our actions overage budget.

Below is part of a sample action

jobs:
  ingest:
    runs-on: ubuntu-18.04
    services:
      redis:
        image: redis
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 6379:6379
      postgres:
        image: postgres:11.5
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
    - uses: actions/checkout@v2

    - name: Setup elixir
      uses: erlef/setup-elixir@v1
      with:
        elixir-version: ${{ env.ELIXIR_VERSION }}
        otp-version: ${{ env.OTP_VERSION }}

    - name: Retrieve Mix Dependencies Cache
      uses: actions/cache@v2
      id: mix-cache
      with:
        path: backend/deps
        key: ${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-test-deps-cache-{{ hashFiles('**/mix.lock') }}
        restore-keys: |
          ${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-test-deps-cache-
    - name: Retrieve Build Cache
      uses: actions/cache@v2
      id: build-cache
      with:
        path: backend/_build/**
        key: ${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-app-build-cache-v5-${{ hashFiles('**/mix.lock','**/structure.sql') }}
        restore-keys: |
          ${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-app-build-cache-v5-
    - name: Install Mix Dependencies
      run: |
        cd backend/
        mix local.rebar --force
        mix local.hex --force
        MIX_ENV=test mix deps.get
    - name: Compile Dependencies
      if: steps.build-cache.outputs.cache-hit != 'true'
      run: |
        cd backend
        MIX_ENV=test mix compile
    - name: Run Tests
      run: |
        cd backend/
        MIX_ENV=test mix ecto.reset
        mix cmd --app app mix test --color

Other examples I’ve found around the forums don’t seem to improve anything.

Does anything stand out here? How can I make these not get deps/compile on every run?

Finally, we also split our tests up so that each have their own actions file. If a PR is open and X app has files changed, the related action runs. If multiple apps have changes, those tests run. Our main package, all of the tests run. Is there possibly a way for a PR to not run all of these tests if a subsequent commit to that PR doesn’t change the apps that have already been tested?

Happy to share more details/clarify, apologies for any longwindedness or confusion.

Most Liked

begedin

begedin

The following combination of steps ensures there is no recompilation happening in my case

 - name: Set up Elixir
        uses: erlef/setup-beam@v1
        with:
          elixir-version: ${{ matrix.elixir }} # Define the elixir version [required]
          otp-version: ${{ matrix.otp }} # Define the OTP version [required]

- name: Restore elixir dependencies cache
        id: mix-cache
        uses: actions/cache@v2
        with:
          path: deps
          key: ${{ runner.os }}-mix-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}

 - name: Restore build cache
        id: build-cache
        uses: actions/cache@v1
        with:
          path: _build
          key: cache-${{ runner.os }}-dialyzer_build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}

      - name: Install Mix Dependencies
        if: steps.mix-cache.outputs.cache-hit != 'true'
        run: |
          mix local.rebar --force
          mix local.hex --force
          mix deps.get

      - name: Compile
        if: steps.build-cache.outputs.cache-hit != 'true'
        env:
          MIX_ENV: test
        run: mix deps.compile; mix compile --force --warnings-as-errors

I also had the two caches combined into one in the past, which worked just as well.

Note that I also do a --warnings-as-errors here for an additional check.

The differences to your setup that I’m seeing are,

  • no structure.sql in the hash
  • i use matrix, not env for versioning
  • my build path is just _build, not _build/**
  • all the critical steps run in test env using the env option in the config
dimitarvp

dimitarvp

Probably try replacing that with uses: erlef/setup-beam@v1? That’s the only thing that kind of stands out to me because in our projects that’s what we use for our GitHub actions setup.

def

def

Thanks for your input, we still end up compiling our applications on every run.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement