Skip to content

Commit

Permalink
.github: recreate caches on push to main
Browse files Browse the repository at this point in the history
Using push to main events to recreate the caches will allow branches /
PRs to reuse those caches when building the code. As the diff between
the main branch and the PR is minimal, the caches will speed up the
building process.

Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed Sep 26, 2024
1 parent d786302 commit cf81ac0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
48 changes: 19 additions & 29 deletions .github/workflows/hubble-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ on:
- 'cilium-cli/**'
- 'Documentation/**'
- 'test/**'
# The push event is only used to recreate the golang cache for hubble-cli
push:
branches:
- main
- ft/main/**
paths-ignore:
- 'cilium-cli/**'
- 'Documentation/**'
- 'test/**'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
cancel-in-progress: true

jobs:
Expand All @@ -32,40 +41,21 @@ jobs:
id: cache
with:
path: /tmp/.cache/hubble-cli
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-hubble-cli-${{ github.sha }}
key: ${{ runner.os }}-go-hubble-cli-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-hubble-cli-
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-
${{ runner.os }}-go-hubble-cli-cache-
${{ runner.os }}-go-
- name: Import cache directory
- name: Create cache directories if they don't exist
if: ${{ steps.go-cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
mkdir -p /home/runner/.cache/
mkdir -p /home/runner/go/
if [ -d "/tmp/.cache/hubble-cli/go-build/" ]; then
cp -r /tmp/.cache/hubble-cli/go-build/ /home/runner/.cache/
fi
if [ -d "/tmp/.cache/hubble-cli/pkg/" ]; then
cp -r /tmp/.cache/hubble-cli/pkg/ /home/runner/go/
fi
mkdir -p /tmp/.cache/hubble-cli/.cache/go-build
mkdir -p /tmp/.cache/hubble-cli/pkg
- name: Build hubble CLI release binaries
env:
GOCACHE: "/tmp/.cache/hubble-cli/.cache/go-build"
GOMODCACHE: "/tmp/.cache/hubble-cli/pkg"
run: |
make -C hubble local-release
- name: Export cache directory
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
mkdir -p /tmp/.cache/hubble-cli
if [ -d "/home/runner/.cache/go-build/" ]; then
cp -r /home/runner/.cache/go-build/ /tmp/.cache/hubble-cli/
fi
if [ -d "/home/runner/go/pkg/" ]; then
cp -r /home/runner/go/pkg/ /tmp/.cache/hubble-cli/
fi
9 changes: 7 additions & 2 deletions .github/workflows/lint-build-commits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ name: Build Commits
# Any change in triggers needs to be reflected in the concurrency group.
on:
pull_request: {}
push:
branches:
- main
- ft/main/**

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -46,8 +50,9 @@ jobs:
id: go-cache
with:
path: /tmp/.cache/go
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-all-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-all-cache-
${{ runner.os }}-go-
# Load CCache build from GitHub
Expand Down

0 comments on commit cf81ac0

Please sign in to comment.