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

Cache bincapz-samples repository to speed up subsequent tests #448

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
8 changes: 4 additions & 4 deletions .github/workflows/go-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
repository: chainguard-dev/bincapz-samples
path: ${{ github.workspace }}/samples
path: ${{ github.workspace }}/out/samples

- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
Expand All @@ -50,11 +50,11 @@ jobs:

- name: Prepare samples
run: |
cp -a ${{ github.workspace }}/test_data/. ${{ github.workspace }}/samples/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run the makefile rule instead of duplicating this logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some hang up about that mentally but it may just be because I cloned the other repository separately and wasn't sure if our anonymous clone would work.

The make targets should work in CI as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 4ad123f (#448).

cp -a ${{ github.workspace }}/test_data/. ${{ github.workspace }}/out/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; \
tar -xJvf ${{ github.workspace }}/out/samples/linux/clean/${file} -C ${{ github.workspace }}/out/samples/linux/clean; \
done
tar -xJvf ${{ github.workspace }}/samples/macOS/clean/bincapz.xz -C ${{ github.workspace }}/samples/macOS/clean
tar -xJvf ${{ github.workspace }}/out/samples/macOS/clean/bincapz.xz -C ${{ github.workspace }}/out/samples/macOS/clean

- name: Test
run: |
Expand Down
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,22 @@ fix: $(FIXERS)

# END: lint-install ../bincapz

SAMPLES_HASH=bdcb8c2e9bf557a0abe3e2b0144f437d456299b7
out/samples-$(SAMPLES_HASH):
mkdir -p out
git clone https://github.com/chainguard-dev/bincapz-samples.git out/samples-$(SAMPLES_HASH).tmp
git -C out/samples-$(SAMPLES_HASH).tmp checkout $(SAMPLES_HASH)
for file in caddy.xz chezmoi.xz minio_x86_64.xz mongosh.xz neuvector_agent_aarch64.xz opa.xz ; do \
egibs marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this work to avoid hardcoding filenames?

find <path> -name "*.xz" -exec xz -d {}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented a variant of this in 4ad123f (#448).

tar -xJvf out/samples-$(SAMPLES_HASH).tmp/linux/clean/$$file -C out/samples-$(SAMPLES_HASH).tmp/linux/clean; \
done
tar -xJvf out/samples-$(SAMPLES_HASH).tmp/macOS/clean/bincapz.xz -C out/samples-$(SAMPLES_HASH).tmp/macOS/clean
mv out/samples-$(SAMPLES_HASH).tmp out/samples-$(SAMPLES_HASH)

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

.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 +127,7 @@ update-third-party:
.PHONY: refresh-sample-testdata out/bincapz
refresh-sample-testdata: clone-samples out/bincapz
cp ./test_data/refresh-testdata.sh samples/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: in a future PR, we can switch to running this script from the test_data directory.

./samples/refresh-testdata.sh ./out/bincapz

.PHONY: clone-samples
clone-samples:
rm -rf samples; git clone git@github.com: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
Loading