-
Notifications
You must be signed in to change notification settings - Fork 241
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
Improve building process with cache goes dependencies #689
Changes from 8 commits
09434d0
c9e9853
641285b
2db63cf
5e738d8
e2c24a5
3988504
53a910a
7054e19
39c08c3
7872523
a64aea2
edb6da0
785c85c
a434923
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -100,6 +100,30 @@ jobs: | |||||
cat go.mod | ||||||
ls pkg | ||||||
|
||||||
#Cache go dependencies before making unit testing and build | ||||||
#Samples codes for different OS: https://github.com/actions/cache/blob/main/examples.md#go---modules | ||||||
#Since we are using Linux, the go packages are in /go/pkg/mod | ||||||
|
||||||
- name: Cache go dependencies in go.mod | ||||||
id: cached_go_dependencies | ||||||
uses: actions/cache@v2 | ||||||
env: | ||||||
cache-name: cached_go_dependencies | ||||||
with: | ||||||
path: | | ||||||
~/.cache/go-build | ||||||
~/go/pkg/mod | ||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||||||
restore-keys: | | ||||||
${{ runner.os }}-go- | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't do anything, does it? Since nothing will ever store in the cache with this key there will never be anything to restore.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it does. The restore-keys are the partial key, not the full key itself. What the flow actually is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After thinking about cache behaviors, IMO it should be removed since we don't want to cache the old modules. |
||||||
|
||||||
# Install all dependencies from go.mod and go.sum instead of source code and keep consistent to the requirements | ||||||
# instead of adding and update requirements like go get does | ||||||
# Contribute to: https://stackoverflow.com/questions/66356034/what-is-the-difference-between-go-get-command-and-go-mod-download-command | ||||||
#We shouldn't use go mod tidy since it has the same goals with go get by updating all dependencies and remove all unnecessary requirements | ||||||
- name: Install go dependencies if cache dependencies did not exist | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this step, the build will automatically download needed dependencies and they'll be cached anyways. go mod download tends to download more than actually needed for the build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting thought !!!. Will change this in the upcoming commit |
||||||
if: steps.cached_go_dependencies.outputs.cache-hit != 'true' | ||||||
run: go mod download | ||||||
- name: Cache binaries | ||||||
id: cached_binaries | ||||||
uses: actions/cache@v2 | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't only dependencies but build cache too so don't need to mention the word dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cache tests. Do we want to do that? I would say yes since tests related to changed files will rerun if files are changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only be caching unit tests I think. Not the integration tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to create conditionals to cache the build only on pr not on merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the integration tests aren't run using
go test
, so the caching wouldn't affect them. Will this cache tests though? I thought based on the documentation, the options we use withmake test
will prevent caching. https://pkg.go.dev/cmd/go/internal/testaws-otel-collector/Makefile
Line 28 in 9153ede
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right