Skip to content

Commit 336e2dc

Browse files
egibsstevebeattie
andauthored
chore: cache Go/Rust dependencies and sample files (#1368)
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> Co-authored-by: Steve Beattie <steve+github@nxnw.org>
1 parent dd6d780 commit 336e2dc

4 files changed

Lines changed: 133 additions & 15 deletions

File tree

.github/workflows/codeql.yaml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ jobs:
2929
with:
3030
egress-policy: audit
3131
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
32+
- name: Cache yara-x-capi installation
33+
id: yara-x-capi
34+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
35+
with:
36+
path: yara-x-install
37+
key: yara-x-capi-v1.12.0-${{ runner.os }}
3238
- name: Checkout virusTotal/yara-x
39+
if: steps.yara-x-capi.outputs.cache-hit != 'true'
3340
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3441
with:
3542
fetch-depth: 0
@@ -38,23 +45,32 @@ jobs:
3845
path: yara-x
3946
ref: refs/tags/v1.12.0
4047
- name: Install Rust for yara-x-capi
48+
if: steps.yara-x-capi.outputs.cache-hit != 'true'
4149
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
4250
with:
4351
toolchain: stable
44-
- name: Install cargo-c and yara-x-capi
52+
- name: Cache Rust dependencies
53+
if: steps.yara-x-capi.outputs.cache-hit != 'true'
54+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
55+
with:
56+
path: |
57+
~/.cargo/registry/
58+
~/.cargo/git/
59+
key: rust-cargo-v1.12.0-${{ runner.os }}
60+
restore-keys: rust-cargo-
61+
- name: Build yara-x-capi
62+
if: steps.yara-x-capi.outputs.cache-hit != 'true'
4563
run: |
64+
command -v cargo-cinstall || cargo install cargo-c --locked
4665
cd ${{ github.workspace }}/yara-x
47-
cargo install cargo-c --locked
48-
sudo -E env "PATH=$PATH" cargo cinstall -p yara-x-capi --features=native-code-serialization --release
49-
sudo ldconfig -v
50-
cd ${{ github.workspace }}
51-
sudo rm -rf ${{ github.workspace }}/yara-x
66+
cargo cinstall -p yara-x-capi --features=native-code-serialization --release --pkgconfigdir=${{ github.workspace }}/yara-x-install --includedir=${{ github.workspace }}/yara-x-install --libdir=${{ github.workspace }}/yara-x-install
67+
rm -rf ${{ github.workspace }}/yara-x
5268
- name: Set up Go
5369
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
5470
with:
5571
go-version-file: "go.mod"
5672
check-latest: true
57-
cache: false
73+
cache: true
5874
- name: Initialize CodeQL
5975
uses: github/codeql-action/init@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
6076
with:
@@ -63,12 +79,15 @@ jobs:
6379
- run: |
6480
go build -o /dev/null ./...
6581
go test -o /dev/null -c ./...
82+
env:
83+
PKG_CONFIG_PATH: ${{ github.workspace }}/yara-x-install
84+
LD_LIBRARY_PATH: ${{ github.workspace }}/yara-x-install
6685
- name: Perform CodeQL Analysis
6786
uses: github/codeql-action/analyze@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2
6887
with:
6988
category: "/language:go"
7089
analyze-actions:
71-
if: ${{ github.repository }} == 'chainguard-dev/malcontent'
90+
if: ${{ github.repository == 'chainguard-dev/malcontent' }}
7291
runs-on: ubuntu-latest
7392
permissions:
7493
actions: read

.github/workflows/fuzz.yaml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
- name: Install dependencies
118118
run: |
119119
apk update
120-
apk add curl findutils git go nodejs upx xz yara-x~1.12.0
120+
apk add curl findutils git gnutar go nodejs upx xz yara-x~1.12.0
121121
122122
- name: Checkout code
123123
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -127,7 +127,34 @@ jobs:
127127
- name: Trust repository
128128
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"
129129

130-
- name: Clone malcontent samples (required for compile fuzzers)
130+
- name: Get Go cache paths
131+
id: go-env
132+
run: |
133+
echo "modcache=$(go env GOMODCACHE)" >> "${GITHUB_OUTPUT}"
134+
echo "cache=$(go env GOCACHE)" >> "${GITHUB_OUTPUT}"
135+
136+
- name: Cache Go dependencies
137+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
138+
with:
139+
path: |
140+
${{ steps.go-env.outputs.modcache }}
141+
${{ steps.go-env.outputs.cache }}
142+
key: go-${{ hashFiles('go.sum') }}
143+
restore-keys: go-
144+
145+
- name: Get samples commit
146+
id: samples
147+
if: contains(matrix.target.package, 'programkind')
148+
run: echo "commit=$(grep '^SAMPLES_COMMIT' Makefile | head -1 | cut -d'=' -f2 | tr -d ' ?')" >> "$GITHUB_OUTPUT"
149+
150+
- name: Cache malcontent samples
151+
if: contains(matrix.target.package, 'programkind')
152+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
153+
with:
154+
path: out/chainguard-sandbox/malcontent-samples
155+
key: samples-${{ steps.samples.outputs.commit }}
156+
157+
- name: Clone malcontent samples (required for programkind fuzzers)
131158
if: contains(matrix.target.package, 'programkind')
132159
run: |
133160
make samples

.github/workflows/go-tests.yaml

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Install dependencies
3838
run: |
3939
apk update
40-
apk add curl findutils git go nodejs upx xz yara-x~1.12.0
40+
apk add curl findutils git gnutar go nodejs upx xz yara-x~1.12.0
4141
4242
- name: Checkout code
4343
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -47,13 +47,28 @@ jobs:
4747
- name: Trust repository
4848
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"
4949

50+
- name: Get Go cache paths
51+
id: go-env
52+
run: |
53+
echo "modcache=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
54+
echo "cache=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
55+
56+
- name: Cache Go dependencies
57+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
58+
with:
59+
path: |
60+
${{ steps.go-env.outputs.modcache }}
61+
${{ steps.go-env.outputs.cache }}
62+
key: go-${{ hashFiles('go.sum') }}
63+
restore-keys: go-
64+
5065
- name: Unit tests
5166
run: |
5267
make test
5368
5469
integration:
5570
if: ${{ github.repository == 'chainguard-dev/malcontent' }}
56-
runs-on: ubuntu-latest-16-core
71+
runs-on: ubuntu-latest-32-core
5772
permissions:
5873
contents: read
5974
container:
@@ -64,7 +79,7 @@ jobs:
6479
--cap-add SETUID
6580
--cap-drop ALL
6681
--cgroupns private
67-
--cpu-shares=16384
82+
--cpu-shares=32768
6883
--memory-swappiness=0
6984
--security-opt no-new-privileges
7085
--ulimit core=0
@@ -74,7 +89,7 @@ jobs:
7489
- name: Install dependencies
7590
run: |
7691
apk update
77-
apk add curl findutils git go nodejs upx xz yara-x~1.12.0
92+
apk add curl findutils git gnutar go nodejs upx xz yara-x~1.12.0
7893
7994
- name: Checkout code
8095
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -84,6 +99,34 @@ jobs:
8499
- name: Trust repository
85100
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"
86101

102+
- name: Get Go cache paths
103+
id: go-env
104+
run: |
105+
echo "modcache=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
106+
echo "cache=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
107+
108+
- name: Cache Go dependencies
109+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
110+
with:
111+
path: |
112+
${{ steps.go-env.outputs.modcache }}
113+
${{ steps.go-env.outputs.cache }}
114+
key: go-${{ hashFiles('go.sum') }}
115+
restore-keys: go-
116+
117+
- name: Get samples commit
118+
id: samples
119+
run: echo "commit=$(grep '^SAMPLES_COMMIT' Makefile | head -1 | cut -d'=' -f2 | tr -d ' ?')" >> "$GITHUB_OUTPUT"
120+
121+
- name: Cache malcontent samples
122+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
123+
with:
124+
path: out/chainguard-sandbox/malcontent-samples
125+
key: samples-${{ steps.samples.outputs.commit }}
126+
127+
- name: Prepare samples
128+
run: make samples
129+
87130
- name: Integration tests
88131
run: |
89132
make integration

.github/workflows/third-party.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,39 @@ jobs:
3737
- name: Install dependencies
3838
run: |
3939
apk update
40-
apk add bash curl findutils gh git go nodejs perl upx xz yara-x~1.12.0
40+
apk add bash curl findutils gh git gnutar go nodejs perl upx xz yara-x~1.12.0
4141
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4242
- name: Trust repository
4343
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"
44+
45+
- name: Get Go cache paths
46+
id: go-env
47+
run: |
48+
echo "modcache=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
49+
echo "cache=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
50+
51+
- name: Cache Go dependencies
52+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
53+
with:
54+
path: |
55+
${{ steps.go-env.outputs.modcache }}
56+
${{ steps.go-env.outputs.cache }}
57+
key: go-${{ hashFiles('go.sum') }}
58+
restore-keys: go-
59+
60+
- name: Get samples commit
61+
id: samples
62+
run: echo "commit=$(grep '^SAMPLES_COMMIT' Makefile | head -1 | cut -d'=' -f2 | tr -d ' ?')" >> "$GITHUB_OUTPUT"
63+
64+
- name: Cache malcontent samples
65+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
66+
with:
67+
path: out/chainguard-sandbox/malcontent-samples
68+
key: samples-${{ steps.samples.outputs.commit }}
69+
70+
- name: Prepare samples
71+
run: make samples
72+
4473
- uses: chainguard-dev/actions/setup-gitsign@6f74cdeee55d70b03fa220746d6739dbbb3e9421
4574
- name: Set up Octo-STS
4675
uses: octo-sts/action@f603d3be9d8dd9871a265776e625a27b00effe05 # v1.1.1

0 commit comments

Comments
 (0)