Skip to content

Commit

Permalink
cicd: factor out go module and build caching
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Nov 1, 2021
1 parent dc30ee3 commit 6a6df52
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 48 deletions.
22 changes: 22 additions & 0 deletions .github/actions/go-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Go cache'
description: 'cache go modules, and build artifacts'
inputs:
go:
description: 'Go version to use'
runs:
using: 'composite'
steps:
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go${{ inputs.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go${{ inputs.go }}
- shell: bash
run: |
find . -name go.mod -type f -printf '%h\n' | while read dir; do
cd "$dir"
go mod download
done
19 changes: 19 additions & 0 deletions .github/actions/go-tidy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Go tidy'
description: 'check that all modules are tidy-clean'
inputs:
go:
description: 'Go version to use'
dir:
description: 'module root directory'
default: '.'
runs:
using: 'composite'
steps:
- uses: ./.github/actions/go-cache
with:
go: ${{ inputs.go }}
- run: |
cd "${{ inputs.dir }}"
go mod tidy
git diff --exit-code
shell: bash
19 changes: 4 additions & 15 deletions .github/workflows/cut-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,9 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Cache Go Modules
uses: actions/cache@v2
- uses: ./.github/actions/go-cache
with:
path: ~/go/pkg/mod
key: go-mod-${{ needs.config.outputs.go_version }}-${{ runner.os }}-${{ hashFiles('./go.*') }}
restore-keys: |
go-mod-${{ needs.config.outputs.go_version }}-${{ runner.os }}
go-mod-${{ needs.config.outputs.go_version }}
go-mod
go: ${{ steps.config.outputs.go_version }}
- name: Create Release Archive
run: |
go mod vendor
Expand Down Expand Up @@ -129,14 +123,9 @@ jobs:
id: download
with:
name: release
- name: Cache Go Builds
uses: actions/cache@v2
- uses: ./.github/actions/go-cache
with:
path: ~/.cache/go-build
key: go-build-${{ needs.config.outputs.build_cache_key }}-${{ runner.os }}
restore-keys: |
go-build-${{ needs.config.outputs.build_cache_key }}
go-build
go: ${{ steps.config.outputs.go_version }}
- name: Unpack and Build
run: |
tar -xz -f ${{steps.download.outputs.download-path}}/clair-${{ needs.config.outputs.version }}.tar.gz --strip-components=1
Expand Down
22 changes: 5 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,10 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go${{ matrix.go }}
- uses: actions/checkout@v2
- run: go mod tidy
- run: git diff --exit-code
- uses: ./.github/actions/go-tidy
with:
go: ${{ matrix.go }}

documentation:
name: Documentation
Expand Down Expand Up @@ -104,14 +97,9 @@ jobs:
go: ['1.16', '1.17']
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: ./.github/actions/go-cache
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go${{ matrix.go }}
go: ${{ matrix.go }}
- run: go test -tags integration ./...
- uses: actions/upload-artifact@v2
if: failure()
Expand Down
18 changes: 2 additions & 16 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,9 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Cache Go Builds
uses: actions/cache@v2
with:
path: ~/.cache/go-build
key: go-build-${{ steps.setup.outputs.go_version }}-${{ runner.os }}
restore-keys: |
go-build-${{ steps.setup.outputs.go_version }}
go-build
- name: Cache Go Modules
uses: actions/cache@v2
- uses: ./.github/actions/go-cache
with:
path: ~/go/pkg/mod
key: go-mod-${{ steps.setup.outputs.go_version }}-${{ runner.os }}-${{ hashFiles('./go.*') }}
restore-keys: |
go-mod-${{ steps.setup.outputs.go_version }}-${{ runner.os }}
go-mod-${{ steps.setup.outputs.go_version }}
go-mod
go: ${{ steps.setup.outputs.go_version }}
- name: Modify module
id: mod
run: ./.github/script/nightly-module.sh
Expand Down

0 comments on commit 6a6df52

Please sign in to comment.