Skip to content

Commit a26f653

Browse files
committed
add signed release builds
1 parent f2c57d1 commit a26f653

File tree

5 files changed

+129
-28
lines changed

5 files changed

+129
-28
lines changed

.github/workflows/build.yml

-28
This file was deleted.

.github/workflows/goreleaser.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
runs-on: ubuntu-latest
31+
needs: test
32+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v2
36+
with:
37+
fetch-depth: 0
38+
- name: Set up Go
39+
uses: actions/setup-go@v2
40+
with:
41+
go-version: 1.17
42+
- name: install cosign
43+
uses: sigstore/cosign-installer@main
44+
with:
45+
cosign-release: 'v1.2.1'
46+
- name: write cosign.key to environment
47+
run: 'echo "$COSIGN_KEY" > .github/cosign.key'
48+
shell: bash
49+
env:
50+
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
51+
- name: Run GoReleaser
52+
uses: goreleaser/goreleaser-action@v2
53+
with:
54+
distribution: goreleaser
55+
version: 'v0.180.2'
56+
args: release --rm-dist
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
COSIGN_PWD: ${{ secrets.COSIGN_PWD }}

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

.goreleaser.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
project_name: in-toto
2+
builds:
3+
- ldflags:
4+
- "-s -w"
5+
- "-extldflags=-zrelro"
6+
- "-extldflags=-znow"
7+
- "-X main.tag={{.Version}}"
8+
- "-X main.commit={{.FullCommit}}"
9+
- "-X main.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: ./cmd/in-toto/
21+
signs:
22+
- cmd: cosign
23+
signature: "${artifact}.sig"
24+
stdin: '{{ .Env.COSIGN_PWD }}'
25+
args: ["sign-blob", "-key=.github/cosign.key", "-output=${signature}", "${artifact}"]
26+
artifacts: all

cmd/in-toto/version.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
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)