Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): various optimizations for build processing, caching and concurrency #996

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
adb5ab6
chore(ci): optimize build to only save cache on build in main, all ot…
jakobmoellerdev Oct 21, 2024
a5028cb
chore(ci): optimize build to run go builds concurrently for archs
jakobmoellerdev Oct 21, 2024
2aa31b0
chore(ci): disable vet for pure test runs since its part of golangci-…
jakobmoellerdev Oct 21, 2024
34cd03f
chore(ci): adjust parallel compile to wait until touch of build
jakobmoellerdev Oct 21, 2024
7a1aaa0
chore(ci): ensure that cli is only built once
jakobmoellerdev Oct 21, 2024
7dab153
chore(ci): optimize OCM meta binary used
jakobmoellerdev Oct 21, 2024
c837447
chore(ci): optimize parallel builds for Makefile
jakobmoellerdev Oct 21, 2024
6f07e3a
chore(ci): ensure ocm cli gets built
jakobmoellerdev Oct 21, 2024
33dcc66
chore(ci): change cache to biggest
jakobmoellerdev Oct 21, 2024
1146100
chore(ci): correctly pass go cache envs
jakobmoellerdev Oct 21, 2024
3438c78
chore(ci): attempt to correct check diff
jakobmoellerdev Oct 21, 2024
b026f78
chore(ci): move back to dedicated test cache
jakobmoellerdev Oct 21, 2024
3fcd424
chore(ci): remove nonworking mounts
jakobmoellerdev Oct 22, 2024
355ea39
chore(ci): on release cache condition on main
jakobmoellerdev Oct 22, 2024
b36ffe9
chore(ci): ensure correct caches and notes
jakobmoellerdev Oct 22, 2024
d590498
Merge branch 'main' into chore/optimize-cache-restore-and-save
jakobmoellerdev Oct 22, 2024
5c6c296
Merge branch 'main' into chore/optimize-cache-restore-and-save
jakobmoellerdev Oct 23, 2024
2163040
Merge remote-tracking branch 'upstream/HEAD' into chore/optimize-cach…
jakobmoellerdev Oct 24, 2024
e7a7c1f
Merge branch 'main' into chore/optimize-cache-restore-and-save
jakobmoellerdev Oct 25, 2024
7a7b30e
Merge branch 'main' into chore/optimize-cache-restore-and-save
hilmarf Oct 29, 2024
d8f4ce3
Update .github/workflows/lint_and_test.yaml
jakobmoellerdev Oct 29, 2024
d1a2b8a
Update .github/workflows/lint_and_test.yaml
jakobmoellerdev Oct 29, 2024
975a937
Merge branch 'main' into chore/optimize-cache-restore-and-save
hilmarf Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/blackduck_scan_scheduled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: '${{ github.workspace }}/go.mod'
cache: false

# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
${{ env.go_modcache }}
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: Blackduck Full Scan
uses: mercedesbenzio/detect-action@v2
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/buildcomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ jobs:
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: |
${{ env.go_cache }}
${{ env.go_modcache }}
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
key: ${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: buildcomponents-go-cache
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: Push OCM Components
if: inputs.ocm_push == true
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/check_diff_action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4

# This step will only reuse the go mod and build cache from main made during the Build,
# see lint_and_test.yaml => "test" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -32,7 +37,7 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: diff-check-go-cache
cache_name: run-tests-go-cache # needs to be the same key in the end as in the build step

- name: Make generate and deepcopy
run: |
Expand Down
56 changes: 39 additions & 17 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
# - ADDENDUM: We moved this to a larger runner for faster analysis
runs-on: large_runner
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
# required for all workflows
Expand All @@ -45,7 +46,7 @@ jobs:
matrix:
include:
- language: go
build-mode: autobuild
build-mode: manual
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
Expand All @@ -61,7 +62,39 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.

- name: Setup Go
uses: actions/setup-go@v5
if: matrix.build-mode == 'manual'
with:
go-version-file: '${{ github.workspace }}/go.mod'
cache: false

- name: Get go environment for use with cache
if: matrix.build-mode == 'manual'
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV

# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
if: matrix.build-mode == 'manual'
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
${{ env.go_modcache }}
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand All @@ -74,20 +107,9 @@ jobs:
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Build
if: matrix.build-mode == 'manual'
run: make build -j

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
Expand Down
64 changes: 44 additions & 20 deletions .github/workflows/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4
# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -39,7 +43,7 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: cli-go-cache
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: CTF
run: |
Expand All @@ -62,9 +66,14 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4

# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -73,7 +82,7 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: helminstaller-go-cache
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: CTF
run: |
Expand All @@ -96,9 +105,14 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4

# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -107,7 +121,7 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: helmdemo-go-cache
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: CTF
run: |
Expand All @@ -130,9 +144,14 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4

# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -141,7 +160,7 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: helm-subchart-go-cache
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: CTF
run: |
Expand All @@ -167,9 +186,14 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4

# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -178,7 +202,7 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: ecr-plugin-go-cache
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: CTF
run: |
Expand Down
48 changes: 39 additions & 9 deletions .github/workflows/lint_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4

# This step will only reuse the go mod and build cache from main made during the Build,
# see lint_and_test.yaml => "test" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
#
# NOTE: This is different from our regular build cache (which contains all archs and is built in a different job)
# This is because it requires caching of test dependencies, which are compiled only for linux-amd64 for test runs in CI.
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -41,10 +49,27 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: run-tests-go-cache
cache_name: run-tests-go-cache # needs to be the same key in the end as in the build step

- name: Build
run: make build -j
- name: Test
run: make build install-requirements test
run: make install-requirements test
hilmarf marked this conversation as resolved.
Show resolved Hide resolved

# NOTE: This is different from our regular build cache (which contains all archs and is built in a different job)
# This is because it requires caching of test dependencies, which are compiled only for linux-amd64 for test runs in CI.
- name: Save Cache of Build (only on main)
id: cache-golang-save
if: github.ref == 'refs/heads/main' # Only run on main, never in PR
uses: actions/cache/save@v4 # Only saves cache build-test (linux-amd64)
with:
path: |
${{ env.go_cache }}
${{ env.go_modcache }}
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
upload-chunk-size: 256000000 # default of 32MB is not really optimal for our large cache, choose 256MB instead
env:
cache_name: run-tests-go-cache # needs to be the same key in the end as in the build step

go-lint:
name: Lint Golang
Expand All @@ -64,9 +89,14 @@ jobs:
run: |
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
# https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs
uses: actions/cache@v4

# This step will only reuse the go mod and build cache from main made during the Build,
# see push_ocm.yaml => "ocm-cli-latest" Job
# This means it never caches by itself and PRs cannot cause cache pollution / thrashing
# This is because we have huge storage requirements for our cache because of the mass of dependencies
- name: Restore / Reuse Cache from central build
id: cache-golang-restore
uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big)
with:
path: |
${{ env.go_cache }}
Expand All @@ -75,7 +105,7 @@ jobs:
restore-keys: |
${{ env.cache_name }}-${{ runner.os }}-go-
env:
cache_name: golint-go-cache
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step

- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
Expand Down
Loading