Skip to content

Commit

Permalink
Cache bincapz-samples repository to speed up subsequent tests (#448)
Browse files Browse the repository at this point in the history
* Cache bincapz-samples repository to speed up subsequent tests

Signed-off-by: egibs <[email protected]>

* Update -> prepare

Signed-off-by: egibs <[email protected]>

* Address PR comments; rework out/samples target

Signed-off-by: egibs <[email protected]>

* Use Make targets in CI; simplify + clean up targets

Signed-off-by: egibs <[email protected]>

---------

Signed-off-by: egibs <[email protected]>
  • Loading branch information
egibs authored Sep 13, 2024
1 parent 0ecdea2 commit 9223b64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/go-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
repository: chainguard-dev/bincapz-samples
path: ${{ github.workspace }}/samples

- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: go.mod
Expand All @@ -50,12 +44,8 @@ jobs:
- name: Prepare samples
run: |
cp -a ${{ github.workspace }}/test_data/. ${{ github.workspace }}/samples/
for file in caddy.xz chezmoi.xz minio_x86_64.xz mongosh.xz neuvector_agent_aarch64.xz opa.xz ; do \
tar -xJvf ${{ github.workspace }}/samples/linux/clean/${file} -C ${{ github.workspace }}/samples/linux/clean; \
done
tar -xJvf ${{ github.workspace }}/samples/macOS/clean/bincapz.xz -C ${{ github.workspace }}/samples/macOS/clean
make prepare-samples
- name: Test
run: |
go test $(go list ./... | grep -v test_data)
make test
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@ fix: $(FIXERS)

# END: lint-install ../bincapz

SAMPLES_REPO=https://github.com/chainguard-dev/bincapz-samples.git
SAMPLES_HASH=bdcb8c2e9bf557a0abe3e2b0144f437d456299b7
OUT_DIR=out/samples-$(SAMPLES_HASH).tmp
out/samples-$(SAMPLES_HASH):
mkdir -p out
git clone $(SAMPLES_REPO) $(OUT_DIR)
git -C $(OUT_DIR) checkout $(SAMPLES_HASH)
find $(OUT_DIR) -name "*.xz" -execdir tar xJvf "{}" \;
mv $(OUT_DIR) $(basename $(OUT_DIR))

prepare-samples: out/samples-$(SAMPLES_HASH)
cp -a test_data/. $(basename $(OUT_DIR))

.PHONY: test
test: clone-samples
test: prepare-samples
go test $(shell go list ./... | grep -v test_data)

.PHONY: bench
Expand Down Expand Up @@ -113,16 +126,7 @@ update-third-party:
.PHONY: refresh-sample-testdata out/bincapz
refresh-sample-testdata: clone-samples out/bincapz
cp ./test_data/refresh-testdata.sh samples/
./samples/refresh-testdata.sh ./out/bincapz

.PHONY: clone-samples
clone-samples:
rm -rf samples; git clone [email protected]:chainguard-dev/bincapz-samples.git samples
cp -a test_data/. samples/
for file in caddy.xz chezmoi.xz minio_x86_64.xz mongosh.xz neuvector_agent_aarch64.xz opa.xz ; do \
tar -xJvf samples/linux/clean/$$file -C samples/linux/clean; \
done
tar -xJvf samples/macOS/clean/bincapz.xz -C samples/macOS/clean
./out/samples/refresh-testdata.sh ./out/bincapz

ARCH ?= $(shell uname -m)
CRANE_VERSION=v0.20.2
Expand Down
2 changes: 1 addition & 1 deletion test_data/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestDiff(t *testing.T) {
MinRisk: tc.minResultScore,
Renderer: simple,
Rules: yrs,
ScanPaths: []string{strings.TrimPrefix(tc.src, "../samples/"), strings.TrimPrefix(tc.dest, "../samples/")},
ScanPaths: []string{strings.TrimPrefix(tc.src, "../out/samples/"), strings.TrimPrefix(tc.dest, "../out/samples/")},
}

logger := clog.New(slog.Default().Handler()).With("src", tc.src)
Expand Down

0 comments on commit 9223b64

Please sign in to comment.