I cannot actions/cache a downloaded toolchain

Hi everyone,

I am trying to build a C project using GNU ARM’s toolchain.

What normally has to be done is listed below:

name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  test:
    name: Test the Firmware
    runs-on: ubuntu-latest
    steps:
      - bla bla bla

  build:
    name: Build Firmware
    runs-on: ubuntu-latest
    env:
      TOOLCHAIN_BASE: /opt/toolchain
      GCC_ARM_NAME: gcc-arm-none-eabi-9-2020-q2-update
    steps:
      - name: Checkout current repo into workspace directory
        uses: actions/checkout@v2

      - name: Checkout submodules
        shell: bash
        run: bla bla bla

      - name: Install GNU Arm Embedded Toolchain
        id: install-toolchain
        shell: bash
        run: |
          wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/${GCC_ARM_NAME}-x86_64-linux.tar.bz2
          tar xf ${GCC_ARM_NAME}-x86_64-linux.tar.bz2
          rm -f ${GCC_ARM_NAME}-x86_64-linux.tar.bz2
          mkdir -p ${TOOLCHAIN_BASE}
          mv ${GCC_ARM_NAME} ${TOOLCHAIN_BASE}/${GCC_ARM_NAME}

      - name: Build the firmware
        env:
          TOOLCHAIN_PATH: ${TOOLCHAIN_BASE}/${GCC_ARM_NAME}/bin
        run: make GCC_PATH=${TOOLCHAIN_PATH}

Because the toolchain installation is something I don’t want to on every run, I’d like to cache it. Using actions/cache@2, I transformed the above workflow to the one below:

name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  test:
    name: Test the Firmware
    runs-on: ubuntu-latest
    steps:
      - bla bla bla

  build:
    name: Build Firmware
    runs-on: ubuntu-latest
    env:
      TOOLCHAIN_BASE: /opt/toolchain
      GCC_ARM_NAME: gcc-arm-none-eabi-9-2020-q2-update
    steps:
      - name: Checkout current repo into workspace directory
        uses: actions/checkout@v2

      - name: Checkout submodules
        shell: bash
        run: bla bla bla

      - name: Cache deps
        id: cache-build-deps
        uses: actions/cache@v2
        env:
          cache-name: cache-toolchain
          build-deps-cache-dir: ${TOOLCHAIN_BASE}
        with:
          path: ${{ env.build-deps-cache-dir }}
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.GCC_ARM_NAME }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-
      - name: Install GNU Arm Embedded Toolchain
        id: install-toolchain
        shell: bash
        run: |
          wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/${GCC_ARM_NAME}-x86_64-linux.tar.bz2
          tar xf ${GCC_ARM_NAME}-x86_64-linux.tar.bz2
          rm -f ${GCC_ARM_NAME}-x86_64-linux.tar.bz2
          mkdir -p ${TOOLCHAIN_BASE}
          mv ${GCC_ARM_NAME} ${TOOLCHAIN_BASE}/${GCC_ARM_NAME}
        if: steps.cache-build-deps.outputs.cache-hit != 'true'

      - name: Build the firmware
        env:
          TOOLCHAIN_PATH: ${TOOLCHAIN_BASE}/${GCC_ARM_NAME}/bin
        run: make GCC_PATH=${TOOLCHAIN_PATH}

The thing is that it doesn’t work. At first the toolchain is downloaded, but on the next runs, although the cache access is a hit, it cannot be found.

I am really new to Github Actions and there is lack of comprehension on how the workplace contents are changed after a actions/checkout and how the actions/cache is actually working.

What could I do to achieve this?

@gon1332,

Try to change like as this to see if it can work:

      - name: Cache deps
        id: cache-build-deps
        uses: actions/cache@v2
        env:
          cache-name: cache-toolchain
          build-deps-cache-dir: ${{ env.TOOLCHAIN_BASE }}
# Pass the value of the environment variable via the env context.
        with:
          . . .

Or directly use the environment variable “TOOLCHAIN_BASE” on the cache action.

      - name: Cache deps
        id: cache-build-deps
        uses: actions/cache@v2
        env:
          cache-name: cache-toolchain
        with:
          path: ${{ env.TOOLCHAIN_BASE }}
          . . .

@brightran Thanks for the quick reply. I did what you mentioned but there was a problem I think with the directory I’ve chosen to store the toolchain (/opt/toolchain). I tried to stored in .toolchain and everything worked.

Do you have any idea why?

P.S.: I don’t care to use /opt. I only want to learn how things work.

I’d hazard a guess that /opt doesnt exist or isn’t writeable.