Skip to content

Commit 2ab7e8b

Browse files
committed
add signed release builds
1 parent 92ba2b6 commit 2ab7e8b

File tree

5 files changed

+127
-28
lines changed

5 files changed

+127
-28
lines changed

.github/workflows/build.yml

-28
This file was deleted.

.github/workflows/goreleaser.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: release
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
strategy:
6+
matrix:
7+
go-version: [ 1.16.x, 1.17.x ]
8+
os: [ ubuntu-latest, macos-latest, windows-latest ]
9+
runs-on: ${{ matrix.os }}
10+
steps:
11+
- name: Install Go
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: ${{ matrix.go-version }}
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
- name: Format Unix
18+
if: runner.os == 'Linux'
19+
run: test -z $(go fmt ./...)
20+
- name: Test
21+
run: go test -covermode atomic -coverprofile='profile.cov' ./...
22+
- name: Send coverage
23+
if: runner.os == 'Linux'
24+
env:
25+
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
GO111MODULE=off go get github.com/mattn/goveralls
28+
$(go env GOPATH)/bin/goveralls -coverprofile=profile.cov -service=github
29+
release:
30+
permissions:
31+
id-token: write
32+
contents: write
33+
runs-on: ubuntu-latest
34+
needs: test
35+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v2
39+
with:
40+
fetch-depth: 0
41+
- name: Set up Go
42+
uses: actions/setup-go@v2
43+
with:
44+
go-version: 1.17
45+
- name: install cosign
46+
uses: sigstore/cosign-installer@main
47+
with:
48+
cosign-release: 'v1.3.0'
49+
- name: Run GoReleaser
50+
uses: goreleaser/goreleaser-action@v2
51+
with:
52+
distribution: goreleaser
53+
version: 'v0.184.0'
54+
args: release --rm-dist
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
COSIGN_EXPERIMENTAL: 1

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1+
# goreleaser distribution directory
2+
dist
3+
4+
# GoLand idea configuration
5+
.idea
6+
7+
# VSCode configuration
8+
.vscode
9+
10+
# ignore cosign private key
11+
cosign.key
12+
113
bin/

.goreleaser.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
project_name: in-toto
2+
builds:
3+
- ldflags:
4+
- "-s -w"
5+
- "-extldflags=-zrelro"
6+
- "-extldflags=-znow"
7+
- "-X cmd.tag={{.Version}}"
8+
- "-X cmd.commit={{.FullCommit}}"
9+
- "-X cmd.date={{.CommitDate}}"
10+
env:
11+
- "CGO_ENABLED=0"
12+
- "GO111MODULE=on"
13+
- "GOFLAGS=-mod=readonly -trimpath"
14+
goos:
15+
- linux
16+
- darwin
17+
- windows
18+
goarch:
19+
- amd64
20+
main: ./
21+
signs:
22+
- cmd: cosign
23+
signature: "${artifact}.sig"
24+
args: ["sign-blob", "--oidc-issuer=https://token.actions.githubusercontent.com", "--output=${signature}", "${artifact}"]
25+
artifacts: all

cmd/version.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var (
9+
commit = "none"
10+
date = "unknown"
11+
tag = "dev"
12+
)
13+
14+
var versionCmd = &cobra.Command{
15+
Use: "version",
16+
Short: "Display the version of the in-toto CLI tool",
17+
Long: `Display the commit ID, the build date and the version tag of the in-toto CLI as embedded by the build system.`,
18+
RunE: version,
19+
}
20+
21+
func init() {
22+
rootCmd.AddCommand(versionCmd)
23+
}
24+
25+
func version(cmd *cobra.Command, args []string) error {
26+
// let us make it as simple as possible.
27+
// We could encode the version information as JSON like kubectl does,
28+
// but what if the json package has a bug? :/
29+
fmt.Println("commit : ", commit)
30+
fmt.Println("date : ", date)
31+
fmt.Println("version: ", tag)
32+
return nil
33+
}

0 commit comments

Comments
 (0)