Skip to content

Commit cd4821b

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

File tree

5 files changed

+126
-28
lines changed

5 files changed

+126
-28
lines changed

.github/workflows/build.yml

-28
This file was deleted.

.github/workflows/goreleaser.yml

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