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

all: cache go module downloads and other build and test artifacts #3727

Merged
merged 80 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
a4a6afa
all: cache go module downloads and other build and test artifacts
leighmcculloch Jun 25, 2021
0c4c8b1
empty commit
leighmcculloch Jun 25, 2021
39da1f1
try test caching
leighmcculloch Jul 1, 2021
df8e6a1
fix test opts
leighmcculloch Jul 1, 2021
5ca6b09
include matrix in cache key
leighmcculloch Jul 1, 2021
2668a1b
jsonify matrix in cache key
leighmcculloch Jul 1, 2021
e4cbe6b
fix matrix
leighmcculloch Jul 1, 2021
81dfed0
less tests
leighmcculloch Jul 1, 2021
605d65e
remove github ref from key of mod cache
leighmcculloch Jul 1, 2021
9c8c345
skip build/test caches on master
leighmcculloch Jul 1, 2021
b00c6ef
Merge branch 'master' into githubactionscachegothings
leighmcculloch Jul 6, 2021
2a3a19e
Merge branch 'master' into githubactionscachegothings
leighmcculloch Jul 7, 2021
6a9efbb
Merge branch 'master' into githubactionscachegothings
leighmcculloch Jul 8, 2021
7b12462
Merge branch 'master' into githubactionscachegothings
leighmcculloch Jul 14, 2021
0f9d7f7
Cache across branches on initial runs
leighmcculloch Jul 14, 2021
0c1a1d1
Merge branch 'master' into githubactionscachegothings
leighmcculloch Feb 23, 2022
da834c9
Merge branch 'master' into githubactionscachegothings
2opremio Feb 23, 2022
5db26e1
Add caching to integration test
leighmcculloch Feb 23, 2022
189950c
empty
leighmcculloch Feb 23, 2022
ca3ec4e
Try to factor out go caching
2opremio Feb 23, 2022
b6feaf6
Factor out the rest of the actions
2opremio Feb 23, 2022
3fc5d94
Include full matrix in cache keys
leighmcculloch Feb 24, 2022
21638af
Make matrix json
leighmcculloch Feb 24, 2022
5264d40
Try serializing matrix manually
leighmcculloch Feb 24, 2022
7e8545f
Fix
leighmcculloch Feb 24, 2022
35ec250
test
leighmcculloch Feb 24, 2022
c4dded0
test
leighmcculloch Feb 24, 2022
aead14d
test
leighmcculloch Feb 24, 2022
3623a9a
test
leighmcculloch Feb 24, 2022
4296ac3
filter
leighmcculloch Feb 24, 2022
7351150
test
leighmcculloch Feb 24, 2022
f9e0bd6
prefix
leighmcculloch Feb 24, 2022
c927412
fix
leighmcculloch Feb 24, 2022
7f4fff2
sep
leighmcculloch Feb 24, 2022
63a338b
line
leighmcculloch Feb 24, 2022
1f5e7bb
comment
leighmcculloch Feb 24, 2022
1081bd0
safer
leighmcculloch Feb 24, 2022
76c6f09
comments
leighmcculloch Feb 24, 2022
4797ad3
comment
leighmcculloch Feb 24, 2022
8606b78
Move captive core version to the matrix
2opremio Feb 24, 2022
f3f67b6
Add integration test caching debug logging
2opremio Feb 24, 2022
444717a
Also print test caching output for integration tests
2opremio Feb 24, 2022
62fe98c
Restore modification times to see if that helps
2opremio Feb 24, 2022
38c7632
Also restore the modification time when running normal tests
2opremio Feb 24, 2022
5dab081
Clarify why restoring the modification time is needed
2opremio Feb 24, 2022
10367b4
Remove cache debug noise from normal tests
2opremio Feb 24, 2022
2abb7ff
Debug why the ingest test isn't cache
2opremio Feb 24, 2022
8bd0c36
Remove debugging info in normal tests
2opremio Feb 24, 2022
e795c91
Add comment
2opremio Feb 24, 2022
ca33d9c
Refine comments
2opremio Feb 24, 2022
db04947
Check whether restore-mtime is doing its job
2opremio Feb 24, 2022
56761cc
Debug modification times futher
2opremio Feb 24, 2022
7b8c4a1
It seems git-restore-mtime didn't work, use a simpler approach
2opremio Feb 24, 2022
962c08b
Clarify comment
2opremio Feb 24, 2022
3c536a1
Try to figure out where we create the captive-core directory
2opremio Feb 24, 2022
e46f5aa
Run a single integration test to debug things faster
2opremio Feb 24, 2022
3d2dd72
Move mtime to cache-go
leighmcculloch Feb 24, 2022
de37391
Use /tmp for the captive-core storage path in integration tests
2opremio Feb 24, 2022
2d16f5f
Remove debug
leighmcculloch Feb 24, 2022
18e25de
empty
leighmcculloch Feb 24, 2022
8090eb9
Merge branch 'master' into githubactionscachegothings
leighmcculloch Feb 24, 2022
8cb5d98
Add comment about why we set the storage path outside of the package
2opremio Feb 24, 2022
d2cc3d4
Yet another storage path out of the repo
2opremio Feb 25, 2022
1805e12
Reenable debug info
2opremio Feb 25, 2022
7c6960c
Use git-restore-mtime again
2opremio Feb 25, 2022
1970534
See if the depth is accepted now
2opremio Feb 25, 2022
940de19
Factor out the full Go setup
2opremio Feb 25, 2022
1786d0a
Remove debug
2opremio Feb 25, 2022
8ac9906
Minor layout fix
2opremio Feb 25, 2022
57d6f09
Cache is not working, again, re-enabling debug
2opremio Feb 25, 2022
0a90371
Set base modification time of directories
2opremio Feb 25, 2022
d396b4c
parameterize go versiongp
leighmcculloch Feb 25, 2022
6ac58c6
include go version in prefix
leighmcculloch Feb 25, 2022
fcc00d6
comments
leighmcculloch Feb 25, 2022
bd48cbb
comment
leighmcculloch Feb 25, 2022
bbec97e
comments
leighmcculloch Feb 25, 2022
c6d48b5
comment
leighmcculloch Feb 25, 2022
f723a8e
comment
2opremio Feb 25, 2022
84a86eb
Remove debug output
2opremio Feb 25, 2022
ba651c3
empty
leighmcculloch Feb 25, 2022
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
52 changes: 52 additions & 0 deletions .github/actions/setup-go/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: 'Setup the Go environment'
description: 'Installs go and restores/saves the build/module cache'
inputs:
go-version:
required: true
runs:
using: "composite"
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ inputs.go-version }}
stable: ${{ !(contains(inputs.go-version, 'beta') || contains(inputs.go-version, 'rc')) }}

# Restore original modification time of files based on the date of the most recent commit that modified them.
# `git clone` sets the modification time to the current time, but Go tests that access fixtures get
# invalidated if their modification times change.
- name: Restore modification time of checkout files
shell: bash
run: |
# Set a base, fixed modification time of all directories.
# git-restore-mtime doesn't set the mtime of directories that contain only
# subdirectories because there's no files to infer an mtime and git
leighmcculloch marked this conversation as resolved.
Show resolved Hide resolved
# doesn't store directories, but changing mtimes of directories can
leighmcculloch marked this conversation as resolved.
Show resolved Hide resolved
# invalidate the go test cache.
touch -m -t '201509301646' $(find . -type d -not -path '.git/*')
# Restore original modification time from git.
sudo apt-get install -y git-restore-mtime
git restore-mtime -v

# The PREFIX must uniquely identify the specific instance of a job executing.
- shell: bash
run: echo 'PREFIX=${{ github.workflow }}-${{ github.job }}-${{ runner.os }}-${{ inputs.go-version }}-matrix(${{ join(matrix.*,'|') }})' >> $GITHUB_ENV

# Cache the Go Modules downloaded during the job.
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ env.PREFIX }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ env.PREFIX }}-go-mod

# Cache any build and test artifacts during the job, which will speed up
# rebuilds and cause test runs to skip tests that have no reason to rerun.
# Don't run this for protected branches like master/main.
- uses: actions/cache@v2
if: ${{ github.ref_protected || github.ref != 'master' || github.ref != 'main' }}
with:
path: ~/.cache/go-build
key: ${{ env.PREFIX }}-go-build-${{ github.ref }}-${{ hashFiles('**', '!.git') }}
restore-keys: |
${{ env.PREFIX }}-go-build-${{ github.ref }}
${{ env.PREFIX }}-go-build
16 changes: 7 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go }}
stable: ${{ !contains(matrix.go, 'rc') }}
- run: ./gomod.sh
- run: ./gofmt.sh
- run: ./gogenerate.sh
Expand All @@ -34,11 +32,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go }}
stable: ${{ !contains(matrix.go, 'rc') }}
- run: go build ./...

test:
Expand Down Expand Up @@ -81,9 +77,11 @@ jobs:
REDIS_PORT: 6379
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
# We need to full history for git-restore-mtime to know what modification dates to use.
# Otherwise, the Go test cache will fail (due to the modification time of fixtures changing).
fetch-depth: '0'
- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go }}
stable: ${{ !contains(matrix.go, 'rc') }}
- run: go test -race -cover ./...
14 changes: 8 additions & 6 deletions .github/workflows/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
go: [1.17]
pg: [9.6.5]
ingestion-backend: [db, captive-core, captive-core-remote-storage]
captive-core: [18.0.3-746.f3baea6.focal]
runs-on: ${{ matrix.os }}
services:
postgres:
Expand All @@ -38,25 +39,26 @@ jobs:
PGDATABASE: postgres
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
# We need to full history for git-restore-mtime to know what modification dates to use.
# Otherwise, the Go test cache will fail (due to the modification time of fixtures changing).
fetch-depth: '0'
- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go }}
- name: Pull latest Stellar Core image
run: docker pull stellar/stellar-core
- if: ${{ startsWith(matrix.ingestion-backend, 'captive-core') }}
name: Install and enable Captive Core
env:
CAPTIVE_CORE_VERSION: 18.0.3-746.f3baea6.focal
run: |
sudo wget -qO - https://apt.stellar.org/SDF.asc | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true sudo apt-key add -
sudo bash -c 'echo "deb https://apt.stellar.org focal unstable" > /etc/apt/sources.list.d/SDF-unstable.list'
sudo apt-get update && sudo apt-get install -y stellar-core=$CAPTIVE_CORE_VERSION
sudo apt-get update && sudo apt-get install -y stellar-core=${{ matrix.captive-core }}
echo "Using stellar core version $(stellar-core version)"
echo 'HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE=true' >> $GITHUB_ENV
echo 'CAPTIVE_CORE_BIN=/usr/bin/stellar-core' >> $GITHUB_ENV
- if: ${{ matrix.ingestion-backend == 'captive-core-remote-storage' }}
name: Setup Captive Core Remote Storage
run: echo 'HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE_USE_DB=true' >> $GITHUB_ENV
- run: go test -race -timeout 25m -v ./services/horizon/internal/integration/...
- run: GODEBUG='gocachehash=1,gocachetest=1' go test -race -timeout 25m -v ./services/horizon/internal/integration/...

4 changes: 4 additions & 0 deletions services/horizon/internal/integration/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integration
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"testing"
Expand Down Expand Up @@ -538,6 +539,9 @@ func command(horizonConfig horizon.Config, args ...string) []string {
// due to ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING
"--checkpoint-frequency",
"8",
// Create the storage directory outside of the source repo,
// otherwise it will break Golang test caching.
"--captive-core-storage-path=" + os.TempDir(),
}, args...)
}

Expand Down
11 changes: 7 additions & 4 deletions services/horizon/internal/test/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,13 @@ func (i *Test) StartHorizon() error {
hostname,
stellarCorePostgresPort,
),
"stellar-core-binary-path": coreBinaryPath,
"captive-core-config-path": captiveCoreConfigPath,
"captive-core-http-port": "21626",
"captive-core-use-db": captiveCoreUseDB,
"stellar-core-binary-path": coreBinaryPath,
"captive-core-config-path": captiveCoreConfigPath,
"captive-core-http-port": "21626",
"captive-core-use-db": captiveCoreUseDB,
// Create the storage directory outside of the source repo,
// otherwise it will break Golang test caching.
"captive-core-storage-path": os.TempDir(),
"enable-captive-core-ingestion": strconv.FormatBool(len(coreBinaryPath) > 0),
"ingest": "true",
"history-archive-urls": fmt.Sprintf("http://%s:%d", hostname, historyArchivePort),
Expand Down