Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit d159769

Browse files
authored
Updated Build Process + CI/CD Updates (#251)
1 parent d77eed0 commit d159769

File tree

18 files changed

+203
-109
lines changed

18 files changed

+203
-109
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
name: Build
3+
name: Build Pull Request
44

5-
on: [ push, pull_request ]
5+
on: [ pull_request ]
66

77
jobs:
88
build:
99
name: Build
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
go: [ "^1.15" ]
13+
go: [ "^1.17", "^1.18" ]
1414
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v3
1517
- name: Setup Go
16-
uses: actions/setup-go@v2
18+
uses: actions/setup-go@v3
1719
with:
1820
go-version: ${{ matrix.go }}
19-
- name: Checkout Repository
20-
uses: actions/checkout@v2
2121
- name: Setup
2222
run: make setup
2323
#- name: Lint
2424
# run: make lint
2525
- name: Lint
2626
run: make check-headers
27-
- name: Test
28-
run: make test
2927
- name: Build
3028
run: make build
29+
- name: Test
30+
run: make test
3131
generate:
3232
name: Generate sbom file
3333
runs-on: ubuntu-latest
@@ -37,12 +37,12 @@ jobs:
3737
- name: gh-action-spdx-sbom-generator
3838
uses: niravpatel27/[email protected]
3939
with:
40-
version: '0.0.3'
40+
version: '0.0.3'
4141
- name: Check if sbom file generated
4242
run: |
4343
if [ ! -f "bom-go-mod.spdx" ]; then
4444
echo "::error::bom-go-mod.spdx is missing. Must generate using the spdx-sbom-generator cli."
4545
exit 1
4646
else
47-
echo "Success!"
48-
fi
47+
echo "Success!"
48+
fi

.github/workflows/merge-main.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
name: Merge to Main
4+
5+
on:
6+
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
name: Build
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
go: [ "^1.17", "^1.18" ]
18+
steps:
19+
- name: Checkout Repository
20+
uses: actions/checkout@v3
21+
- name: Setup Go
22+
uses: actions/setup-go@v3
23+
with:
24+
go-version: ${{ matrix.go }}
25+
- name: Setup
26+
run: make setup
27+
#- name: Lint
28+
# run: make lint
29+
- name: Lint
30+
run: make check-headers
31+
- name: Build
32+
run: make build
33+
- name: Test
34+
run: make test
35+
generate:
36+
name: Generate sbom file
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout the repository
40+
uses: actions/checkout@v2
41+
- name: gh-action-spdx-sbom-generator
42+
uses: niravpatel27/[email protected]
43+
with:
44+
version: '0.0.3'
45+
- name: Check if sbom file generated
46+
run: |
47+
if [ ! -f "bom-go-mod.spdx" ]; then
48+
echo "::error::bom-go-mod.spdx is missing. Must generate using the spdx-sbom-generator cli."
49+
exit 1
50+
else
51+
echo "Success!"
52+
fi

.github/workflows/release.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,36 @@ jobs:
1111
docker:
1212
runs-on: ubuntu-latest
1313
steps:
14-
## checks out our project source code
15-
- uses: actions/checkout@v2
14+
## checks out our project source code
15+
- uses: actions/checkout@v3
1616

17-
## Builds our docker image!
18-
- name: Build the Docker image
19-
run: docker build . --file Dockerfile
17+
## Builds our docker image!
18+
- name: Build the Docker image
19+
run: docker build . --file Dockerfile
2020

21-
## Publishes our image to Docker Hub 😎
22-
- name: Set RELEASE_VERSION env
23-
run: echo RELEASE_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
24-
- name: Publish to Registry
25-
uses: elgohr/Publish-Docker-Github-Action@master
26-
with:
27-
name: spdx/spdx-sbom-generator
28-
username: ${{ secrets.DOCKERHUB_USERNAME }}
29-
password: ${{ secrets.DOCKERHUB_TOKEN }}
30-
tags: "latest,${{ env.RELEASE_VERSION }}"
21+
## Publishes our image to Docker Hub 😎
22+
- name: Set RELEASE_VERSION env
23+
run: echo RELEASE_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
24+
- name: Publish to Registry
25+
uses: elgohr/Publish-Docker-Github-Action@master
26+
with:
27+
name: spdx/spdx-sbom-generator
28+
username: ${{ secrets.DOCKERHUB_USERNAME }}
29+
password: ${{ secrets.DOCKERHUB_TOKEN }}
30+
tags: "latest,${{ env.RELEASE_VERSION }}"
3131
release:
3232
name: Release Go Binary
3333
runs-on: ubuntu-latest
3434
strategy:
3535
matrix:
36-
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64
37-
goos: [linux, windows, darwin]
38-
goarch: ["386", amd64]
36+
# build and publish various targets
37+
goos: [ linux, windows, darwin ]
38+
goarch: [ "386", amd64, arm64 ]
3939
exclude:
4040
- goarch: "386"
4141
goos: darwin
42+
- goarch: arm64
43+
goos: windows
4244
steps:
4345
- uses: actions/checkout@v2
4446
# set current version based on release tag
@@ -49,7 +51,7 @@ jobs:
4951
github_token: ${{ secrets.GITHUB_TOKEN }}
5052
goos: ${{ matrix.goos }}
5153
goarch: ${{ matrix.goarch }}
52-
goversion: "https://dl.google.com/go/go1.16.6.linux-amd64.tar.gz"
54+
goversion: "https://dl.google.com/go/go1.18.3.linux-amd64.tar.gz"
5355
project_path: "./cmd/generator"
5456
binary_name: "spdx-sbom-generator"
5557
ldflags: "-X 'main.version=${{ env.RELEASE_VERSION }}'"

Makefile

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
# It's necessary to set this because some environments don't link sh -> bash.
44
SHELL := /usr/bin/env bash
5-
VERSION=$(shell cat version.txt)
5+
BUILD_TIME=$(shell sh -c 'date +%FT%T%z')
6+
VERSION := $(shell sh -c 'git describe --always --tags')
7+
BRANCH := $(shell sh -c 'git rev-parse --abbrev-ref HEAD')
8+
COMMIT := $(shell sh -c 'git rev-parse --short HEAD')
9+
GO_FILES=$(shell find . -type f -name '*.go' -not -path './vendor/*')
610
PKG_LIST := $(shell go list ./... | grep -v mock)
7-
ldflags='-X "main.version=$(VERSION)"'
11+
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH) -X main.buildDate=$(BUILD_TIME)"
12+
813
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
914
LINT_TOOL=$(shell go env GOPATH)/bin/golangci-lint
1015
LINT_VERSION=v1.37.0
@@ -18,36 +23,36 @@ setup: $(LINT_TOOL)
1823

1924
.PHONY: mod
2025
mod:
21-
@GO111MODULE=on GOFLAGS=-mod=vendor go mod vendor
22-
@GO111MODULE=on GOFLAGS=-mod=vendor go mod tidy
26+
@go mod download
27+
@go mod tidy
2328

2429
.PHONY: generator
2530
generate: mod
26-
@echo "Running cli on version $(VERSION)"
31+
@echo "Running cli on version: $(VERSION)"
2732
@GO111MODULE=on GLFLAGs=-mod-vendor go run cmd/generator/generator.go $(ARGS)
2833

2934
.PHONY: build
3035
build: mod
31-
@echo "Building spdx-sbom-generator for Linux Intel/AMD 64-bit version:$(VERSION)"
32-
@GO111MODULE=on GOFLAGS=-mod=vendor GOOS=linux go build -ldflags $(ldflags) -o bin/spdx-sbom-generator cmd/generator/generator.go
36+
@echo "Building spdx-sbom-generator for Linux Intel/AMD 64-bit version: $(VERSION)"
37+
env GOOS=linux GOARCH=amd64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator cmd/generator/generator.go
3338
@chmod +x bin/spdx-sbom-generator
3439

3540
.PHONY: build-mac
3641
build-mac: mod
37-
@echo "Building spdx-sbom-generator for Mac Intel/AMD 64-bit version:$(VERSION)"
38-
@GO111MODULE=on GOFLAGS=-mod=vendor GOOS=darwin GOARCH=amd64 go build -ldflags $(ldflags) -o bin/spdx-sbom-generator cmd/generator/generator.go
42+
@echo "Building spdx-sbom-generator for Mac Intel/AMD 64-bit version: $(VERSION)"
43+
@env GOOS=darwin GOARCH=amd64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator cmd/generator/generator.go
3944
@chmod +x bin/spdx-sbom-generator
4045

4146
.PHONY: build-mac-arm64
4247
build-mac-arm64: mod
43-
@echo "Building spdx-sbom-generator for Mac ARM 64-bit version:$(VERSION)"
44-
@GO111MODULE=on GOFLAGS=-mod=vendor GOOS=darwin GOARCH=arm64 go build -ldflags $(ldflags) -o bin/spdx-sbom-generator cmd/generator/generator.go
48+
@echo "Building spdx-sbom-generator for Mac ARM 64-bit version: $(VERSION)"
49+
@env GOOS=darwin GOARCH=arm64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator cmd/generator/generator.go
4550
@chmod +x bin/spdx-sbom-generator
4651

4752
.PHONY: build-win
4853
build-win: mod
49-
@echo "Building spdx-sbom-generator for Windows Intel/AMD 64-bit version:$(VERSION)"
50-
@GO111MODULE=on GOFLAGS=-mod=vendor GOOS=windows GOARCH=amd64 go build -ldflags $(ldflags) -o bin/spdx-sbom-generator.exe cmd/generator/generator.go
54+
@echo "Building spdx-sbom-generator for Windows Intel/AMD 64-bit version: $(VERSION)"
55+
env GOOS=windows GOARCH=amd64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator.exe cmd/generator/generator.go
5156
@chmod +x bin/spdx-sbom-generator.exe
5257

5358
$(LINT_TOOL):
@@ -63,6 +68,10 @@ check-headers:
6368
@echo "Running license header check..."
6469
$(ROOT_DIR)/check-headers.sh
6570

71+
fmt:
72+
@gofmt -w -l -s $(GO_FILES)
73+
@goimports -w -l $(GO_FILES)
74+
6675
.PHONY: lint
6776
lint: go-lint check-headers
6877

go.mod

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
13
module github.com/spdx/spdx-sbom-generator
24

3-
go 1.15
5+
go 1.17
46

57
require (
68
github.com/go-enry/go-license-detector/v4 v4.2.0
@@ -12,3 +14,37 @@ require (
1214
github.com/vifraa/gopom v0.1.0
1315
golang.org/x/mod v0.4.2
1416
)
17+
18+
require (
19+
github.com/davecgh/go-spew v1.1.1 // indirect
20+
github.com/dgryski/go-minhash v0.0.0-20170608043002-7fe510aff544 // indirect
21+
github.com/ekzhu/minhash-lsh v0.0.0-20171225071031-5c06ee8586a1 // indirect
22+
github.com/emirpasic/gods v1.12.0 // indirect
23+
github.com/go-git/gcfg v1.5.0 // indirect
24+
github.com/go-git/go-billy/v5 v5.0.0 // indirect
25+
github.com/hhatto/gorst v0.0.0-20181029133204-ca9f730cac5b // indirect
26+
github.com/imdario/mergo v0.3.9 // indirect
27+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
28+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
29+
github.com/jdkato/prose v1.1.0 // indirect
30+
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect
31+
github.com/mitchellh/go-homedir v1.1.0 // indirect
32+
github.com/montanaflynn/stats v0.0.0-20151014174947-eeaced052adb // indirect
33+
github.com/pkg/errors v0.9.1 // indirect
34+
github.com/pmezard/go-difflib v1.0.0 // indirect
35+
github.com/russross/blackfriday/v2 v2.0.1 // indirect
36+
github.com/sergi/go-diff v1.1.0 // indirect
37+
github.com/shogo82148/go-shuffle v0.0.0-20170808115208-59829097ff3b // indirect
38+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
39+
github.com/spf13/pflag v1.0.5 // indirect
40+
github.com/xanzy/ssh-agent v0.2.1 // indirect
41+
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect
42+
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 // indirect
43+
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
44+
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
45+
golang.org/x/text v0.3.6 // indirect
46+
gonum.org/v1/gonum v0.7.0 // indirect
47+
gopkg.in/neurosnap/sentences.v1 v1.0.6 // indirect
48+
gopkg.in/warnings.v0 v0.1.2 // indirect
49+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
50+
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ github.com/ekzhu/minhash-lsh v0.0.0-20171225071031-5c06ee8586a1/go.mod h1:yEtCVi
5555
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
5656
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
5757
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
58-
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
5958
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
6059
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
6160
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -320,8 +319,9 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
320319
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
321320
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
322321
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
323-
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
324322
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
323+
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e h1:NHvCuwuS43lGnYhten69ZWqi2QOj/CiDNcKbVqwVoew=
324+
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
325325
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
326326
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
327327
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

pkg/handler/handler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
package handler
44

5-
import ()
6-
75
// Handler ...
86
type Handler interface {
97
Run() error

pkg/handler/spdx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type spdxHandler struct {
4242
func getFiletypeForOutputFormat(outputFormat models.OutputFormat) string {
4343
switch outputFormat {
4444
case models.OutputFormatSpdx:
45-
return "spdx"
45+
return "spdx" // nolint
4646
case models.OutputFormatJson:
4747
return "json"
4848
default:

0 commit comments

Comments
 (0)