mirror of
https://github.com/ossf/scorecard.git
synced 2024-10-26 10:28:10 +03:00
Also add version info to goreleaser (#822)
- shared configuration generation in ./scripts/version-ldflags Signed-off-by: Appu Goundan <appu@google.com>
This commit is contained in:
parent
2931d91e23
commit
8534836923
5
.github/workflows/goreleaser.yaml
vendored
5
.github/workflows/goreleaser.yaml
vendored
@ -33,6 +33,10 @@ jobs:
|
||||
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8 # v2.1.3
|
||||
with:
|
||||
go-version: 1.16
|
||||
-
|
||||
name: Configure ldflags
|
||||
id: ldflags
|
||||
run: echo "::set-output name=version_flags::$(./scripts/version-ldflags)"
|
||||
-
|
||||
name: Import GPG key
|
||||
id: import_gpg
|
||||
@ -49,3 +53,4 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|
||||
VERSION_LDFLAGS: ${{ steps.ldflags.outputs.version_flags }}
|
||||
|
@ -9,13 +9,16 @@ builds:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
# List of combinations of GOOS + GOARCH + GOARM to ignore.
|
||||
# List of combinations of GOOS + GOARCH + GOARM to ignore.
|
||||
# Default is empty.
|
||||
ignore:
|
||||
- goos: darwin
|
||||
goarch: 386
|
||||
- goos: darwin
|
||||
goarch: arm64
|
||||
# CI should set VERSION_LDFLAGS to the output of ./scripts/version_ldflags
|
||||
ldflags:
|
||||
- -s -w {{.Env.VERSION_LDFLAGS}}
|
||||
archives:
|
||||
- replacements:
|
||||
linux: Linux
|
||||
|
22
Makefile
22
Makefile
@ -1,6 +1,7 @@
|
||||
SHELL := /bin/bash
|
||||
GOPATH := $(go env GOPATH)
|
||||
GINKGO := ginkgo
|
||||
GIT_HASH := $(git rev-parse HEAD)
|
||||
GOLANGGCI_LINT := golangci-lint
|
||||
PROTOC_GEN_GO := protoc-gen-go
|
||||
PROTOC := $(shell which protoc)
|
||||
@ -8,26 +9,7 @@ IMAGE_NAME = scorecard
|
||||
OUTPUT = output
|
||||
IGNORED_CI_TEST="E2E TEST:blob|E2E TEST:executable"
|
||||
|
||||
# generate VERSION_LDFLAGS
|
||||
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
|
||||
GIT_HASH ?= $(shell git rev-parse HEAD)
|
||||
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ'
|
||||
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
|
||||
ifdef SOURCE_DATE_EPOCH
|
||||
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
|
||||
else
|
||||
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
|
||||
endif
|
||||
GIT_TREESTATE = clean
|
||||
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
|
||||
ifeq ($(DIFF), 1)
|
||||
GIT_TREESTATE = dirty
|
||||
endif
|
||||
|
||||
# version should be injected in the cmd package
|
||||
PKG=$(shell go list -m | head -n1)/cmd
|
||||
|
||||
VERSION_LDFLAGS=-X $(PKG).gitVersion=$(GIT_VERSION) -X $(PKG).gitCommit=$(GIT_HASH) -X $(PKG).gitTreeState=$(GIT_TREESTATE) -X $(PKG).buildDate=$(BUILD_DATE)
|
||||
VERSION_LDFLAGS=$(shell ./scripts/version-ldflags)
|
||||
|
||||
############################### make help #####################################
|
||||
.PHONY: help
|
||||
|
25
scripts/version-ldflags
Executable file
25
scripts/version-ldflags
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2021 Security Scorecard Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# shared by Makefile and .goreleaser.yml to inject
|
||||
# version info into cmd/version.go via ldflags
|
||||
GIT_VERSION=$(git describe --tags --always --dirty)
|
||||
GIT_HASH=$(git rev-parse HEAD)
|
||||
BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%SZ')
|
||||
GIT_TREESTATE=$(if git diff --quiet; then echo "clean"; else echo "dirty"; fi)
|
||||
PKG=$(go list -m | head -n1)/cmd
|
||||
echo "-X $PKG.gitVersion=$GIT_VERSION -X $PKG.gitCommit=$GIT_HASH -X $PKG.gitTreeState=$GIT_TREESTATE -X $PKG.buildDate=$BUILD_DATE"
|
Loading…
Reference in New Issue
Block a user