Skip to content

Commit 08e8772

Browse files
authored
Import syft as a library (#2)
1 parent 8924418 commit 08e8772

93 files changed

Lines changed: 6607 additions & 232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bouncer.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,19 @@ permit:
44
- Apache.*
55
- MPL.*
66
- ISC
7+
ignore-packages:
8+
# packageurl-go is released under the MIT license located in the root of the repo at /mit.LICENSE
9+
- github.com/anchore/packageurl-go
710

11+
# from: https://github.com/spdx/tools-golang/blob/main/LICENSE.code
12+
# The tools-golang source code is provided and may be used, at your option,
13+
# under either:
14+
# * Apache License, version 2.0 (Apache-2.0), OR
15+
# * GNU General Public License, version 2.0 or later (GPL-2.0-or-later).
16+
# (we choose Apache-2.0)
17+
- github.com/spdx/tools-golang
18+
19+
# from: https://github.com/xi2/xz/blob/master/LICENSE
20+
# All these files have been put into the public domain.
21+
# You can do whatever you want with these files.
22+
- github.com/xi2/xz

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/test-fixtures/**/*.jpi filter=lfs diff=lfs merge=lfs -text
2+
**/test-fixtures/**/*.hpi filter=lfs diff=lfs merge=lfs -text
3+
**/test-fixtures/**/*.jar filter=lfs diff=lfs merge=lfs -text
4+
**/test-fixtures/**/*.war filter=lfs diff=lfs merge=lfs -text
5+
**/test-fixtures/**/*.ear filter=lfs diff=lfs merge=lfs -text

.github/scripts/go-mod-tidy-check.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ set -eu
44
ORIGINAL_STATE_DIR=$(mktemp -d "TEMP-original-state-XXXXXXXXX")
55
TIDY_STATE_DIR=$(mktemp -d "TEMP-tidy-state-XXXXXXXXX")
66

7-
trap "cp -v ${ORIGINAL_STATE_DIR}/* ./ && rm -fR ${ORIGINAL_STATE_DIR} ${TIDY_STATE_DIR}" EXIT
7+
trap "cp ${ORIGINAL_STATE_DIR}/* ./ && rm -fR ${ORIGINAL_STATE_DIR} ${TIDY_STATE_DIR}" EXIT
88

99
echo "Capturing original state of files..."
10-
cp -v go.mod go.sum "${ORIGINAL_STATE_DIR}"
10+
cp go.mod go.sum "${ORIGINAL_STATE_DIR}"
1111

1212
echo "Capturing state of go.mod and go.sum after running go mod tidy..."
1313
go mod tidy
14-
cp -v go.mod go.sum "${TIDY_STATE_DIR}"
14+
cp go.mod go.sum "${TIDY_STATE_DIR}"
1515
echo ""
1616

1717
set +e
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
3+
SYFT_LINE=$(cat go.mod | grep github.com/anchore/syft)
4+
5+
if [ "$(echo $SYFT_LINE | grep -o '-' | wc -l)" -gt "1" ]; then
6+
echo "syft version is not a released version! $SYFT_LINE"
7+
exit 1
8+
else
9+
echo 'syft version is a released version!'
10+
fi

.github/workflows/release.yaml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,23 @@ jobs:
6161
checkName: "Acceptance tests (Mac)"
6262
ref: ${{ github.event.pull_request.head.sha || github.sha }}
6363

64+
- name: Check cli test results (linux)
65+
uses: fountainhead/action-wait-for-check@v1.0.0
66+
id: cli-linux
67+
with:
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
# This check name is defined as the github action job name (in .github/workflows/testing.yaml)
70+
checkName: "CLI tests (Linux)"
71+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
72+
6473
- name: Quality gate
65-
if: steps.static-analysis.outputs.conclusion != 'success' || steps.unit.outputs.conclusion != 'success' || steps.acceptance-linux.outputs.conclusion != 'success' || steps.acceptance-mac.outputs.conclusion != 'success'
74+
if: steps.static-analysis.outputs.conclusion != 'success' || steps.unit.outputs.conclusion != 'success' || steps.acceptance-linux.outputs.conclusion != 'success' || steps.acceptance-mac.outputs.conclusion != 'success' || steps.cli-linux.outputs.conclusion != 'success'
6675
run: |
6776
echo "Static Analysis Status: ${{ steps.static-analysis.conclusion }}"
6877
echo "Unit Test Status: ${{ steps.unit.outputs.conclusion }}"
6978
echo "Acceptance Test (Linux) Status: ${{ steps.acceptance-linux.outputs.conclusion }}"
7079
echo "Acceptance Test (Mac) Status: ${{ steps.acceptance-mac.outputs.conclusion }}"
80+
echo "CLI Test (Linux) Status: ${{ steps.cli-linux.outputs.conclusion }}"
7181
false
7282
7383
release:
@@ -109,19 +119,10 @@ jobs:
109119
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110120

111121
- uses: anchore/sbom-action@v0
122+
continue-on-error: true
112123
with:
113124
artifact-name: sbom.spdx.json
114125

115-
# TODO
116-
# - uses: 8398a7/action-slack@v3
117-
# with:
118-
# status: ${{ job.status }}
119-
# fields: repo,workflow,action,eventName
120-
# text: "A new docker-sbom-cli-plugin release is ready to be manually published: https://github.com/anchore/docker-sbom-cli-plugin/releases"
121-
# env:
122-
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_TOOLBOX_WEBHOOK_URL }}
123-
# if: ${{ success() }}
124-
125126
- uses: actions/upload-artifact@v2
126127
with:
127128
name: artifacts

.github/workflows/validations.yaml

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: "Validations"
22
on:
33
workflow_dispatch:
44
push:
5+
branches:
6+
- main
57
pull_request:
68

79
env:
@@ -43,6 +45,15 @@ jobs:
4345
- name: Run static analysis
4446
run: make static-analysis
4547

48+
# allow for PRs to skip validating the syft version to allow for incremental updates of syft before release.
49+
# In this way checks against the main branch (which are required for release) will fail, but PR checks will not
50+
- name: Ensure syft version is a release version
51+
run: |
52+
echo "GitHub reference: ${GITHUB_REF##*/}"
53+
git fetch origin main
54+
git merge-base --is-ancestor ${GITHUB_REF##*/} origin/main && make validate-syft-release-version || echo "skipping syft version check"
55+
56+
4657
Unit-Test:
4758
# Note: changing this job name requires making the same update in the .github/workflows/release.yaml pipeline
4859
name: "Unit tests"
@@ -174,5 +185,60 @@ jobs:
174185
brew install docker
175186
mkdir ~/.docker
176187
177-
- name: Run install.sh tests (Mac)
178-
run: make install-test-ci-mac
188+
# TODO: put back in after the first release
189+
# - name: Run install.sh tests (Mac)
190+
# run: make install-test-ci-mac
191+
192+
Cli-Linux:
193+
# Note: changing this job name requires making the same update in the .github/workflows/release.yaml pipeline
194+
name: "CLI tests (Linux)"
195+
needs: [Build-Snapshot-Artifacts]
196+
runs-on: ubuntu-20.04
197+
steps:
198+
- uses: actions/setup-go@v2
199+
with:
200+
go-version: ${{ env.GO_VERSION }}
201+
202+
- uses: actions/checkout@v2
203+
with:
204+
# this downloads and initializes LFS, but does not pull the objects
205+
lfs: true
206+
# we need to jump between multiple branches to compare compute a diff, which means we need a deeper clone depth
207+
fetch-depth: 0
208+
209+
- name: Restore go cache
210+
id: go-cache
211+
uses: actions/cache@v2.1.3
212+
with:
213+
path: ~/go/pkg/mod
214+
key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
215+
restore-keys: |
216+
${{ runner.os }}-go-${{ env.GO_VERSION }}-
217+
218+
- name: Restore tool cache
219+
id: tool-cache
220+
uses: actions/cache@v2.1.3
221+
with:
222+
path: ${{ github.workspace }}/.tmp
223+
key: ${{ runner.os }}-tool-${{ hashFiles('Makefile') }}
224+
225+
- name: (cache-miss) Bootstrap all project dependencies
226+
if: steps.tool-cache.outputs.cache-hit != 'true' || steps.go-cache.outputs.cache-hit != 'true'
227+
run: make bootstrap
228+
229+
- name: Build key for tar cache
230+
run: make cli-fingerprint
231+
232+
- name: Restore CLI test cache
233+
uses: actions/cache@v2.1.3
234+
with:
235+
path: ${{ github.workspace }}/test/cli/test-fixtures/cache
236+
key: ${{ runner.os }}-cli-test-cache-${{ hashFiles('test/cli/test-fixtures/cache.fingerprint') }}
237+
238+
- uses: actions/download-artifact@v2
239+
with:
240+
name: artifacts
241+
path: snapshot
242+
243+
- name: Run CLI Tests (Linux)
244+
run: make cli

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ CHANGELOG.md
77
.history/
88
*.fingerprint
99
*.tar
10-
*.jar
11-
*.war
12-
*.ear
13-
*.jpi
14-
*.hpi
1510
*.zip
1611
.idea/
1712
*.log
1813
.images
1914
.tmp/
2015
coverage.txt
16+
bin/
17+
**/test-fixtures/cache/*
2118

2219
# Binaries for programs and plugins
2320
*.exe

.goreleaser.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ builds:
1919
-w
2020
-s
2121
-extldflags '-static'
22-
-X github.com/anchore/docker-sbom-cli-plugin/internal.version={{.Version}}
23-
-X github.com/anchore/docker-sbom-cli-plugin/internal.gitCommit={{.Commit}}
24-
-X github.com/anchore/docker-sbom-cli-plugin/internal.buildDate={{.Date}}
25-
-X github.com/anchore/docker-sbom-cli-plugin/internal.gitDescription={{.Summary}}
22+
-X github.com/anchore/docker-sbom-cli-plugin/internal/version.version={{.Version}}
23+
-X github.com/anchore/docker-sbom-cli-plugin/internal/version.gitCommit={{.Commit}}
24+
-X github.com/anchore/docker-sbom-cli-plugin/internal/version.buildDate={{.Date}}
25+
-X github.com/anchore/docker-sbom-cli-plugin/internal/version.gitDescription={{.Summary}}
2626

2727
archives:
2828
- format: tar.gz

.syft.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exclude:
2+
- '**/test-fixtures/*'
3+
- './.git'

DEVELOPING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Developing
2+
3+
## Getting started
4+
5+
In order to test and develop in this repo you will need the following dependencies installed:
6+
- docker
7+
- make
8+
- git-lfs
9+
10+
After cloning you will need to do the following:
11+
1. run `git lfs install && git lfs pull` to grab the latest test assets in LFS
12+
2. run `make bootstrap` to download go mod dependencies, create the `/.tmp` dir, and download helper utilities.
13+
3. run `make` to run linting, tests, and other verifications to make certain everything is working alright.
14+
15+
## Running tests
16+
17+
The main make tasks for common static analysis and testing are:
18+
19+
- `static-analysis`: runs the linter and license checks
20+
- `lint-fix`: let the linter auto-fix as many issues as it can
21+
- `unit`: plain-ol'e unit tests
22+
- `cli`: run trait assertions against snapshot builds
23+
24+
Checkout `make help` to see what other actions you can take.
25+
26+
## Testing with Docker
27+
28+
To create a snapshot and install into the local ` ~/.docker/cli-plugins` directory:
29+
30+
```
31+
make clean-snapshot snapshot install-snapshot
32+
```

0 commit comments

Comments
 (0)