name: "build protobufs"

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
  schedule:
    - cron: "0 0 * * *"

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      BAZEL: bazelisk-linux-amd64
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    
    - name: Mount bazel cache
      uses: actions/cache@v2
      with:
        path: "~/.cache/bazel"  # See https://docs.bazel.build/versions/master/output_directories.html
        key: bazel

    - name: Install bazelisk
      run: |
        curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.4.0/$BAZEL"
        chmod +x $BAZEL
        sudo mv $BAZEL /usr/local/bin/bazel

    - name: Build proto/
      run: cd proto && bazel build //...

    - name: Build bazel/example/
      run: cd bazel/example/ && bazel build //...

name: "build protobufs"

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
  schedule:
    - cron: "0 0 * * *"

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      BAZEL: bazelisk-linux-amd64
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    
    - name: Mount bazel cache
      uses: actions/cache@v2
      with:
        # See https://docs.bazel.build/versions/master/output_directories.html
        path: "~/.cache/bazel"
        # Create a new cache entry whenever Bazel files change.
        # See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
        key: ${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }}
        restore-keys: |
          ${{ runner.os }}-build-

    - name: Install bazelisk
      run: |
        curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.4.0/$BAZEL"
        chmod +x $BAZEL
        sudo mv $BAZEL /usr/local/bin/bazel

    - name: Build proto/
      run: cd proto && bazel build //...

    - name: Build bazel/example/
      run: cd bazel/example/ && bazel build //...

Improve CI build times through smarter caching
Improve CI build times through smarter caching

GitHub's caching mechanism never overwrites cache entries for existing keys. Since we were using a static key, this caused our cache to never be refreshed. With this PR, a new cache entry is generated whenever any Bazel files (including dependencies) change.