-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CI for release and create image (#19)
- Loading branch information
Showing
3 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
id-token: write | ||
packages: write | ||
steps: | ||
- | ||
name: Login to GHCR | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- | ||
name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.20" | ||
- | ||
name: install cosign | ||
uses: sigstore/cosign-installer@main | ||
- | ||
uses: anchore/sbom-action/[email protected] | ||
- | ||
name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COSIGN_EXPERIMENTAL: 1 | ||
GOVERSION: "1.20" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
project_name: hollow-bomservice | ||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- id: go | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
ldflags: | ||
- -X "github.com/metal-toolbox/hollow-bomservice/internal/version.AppVersion={{ .Version }}" | ||
-X "github.com/metal-toolbox/hollow-bomservice/internal/version.GoVersion={{ .Env.GOVERSION }}" | ||
-X "github.com/metal-toolbox/hollow-bomservice/internal/version.GitCommit={{ .Commit }}" | ||
-X "github.com/metal-toolbox/hollow-bomservice/internal/version.GitBranch={{ .Branch }}" | ||
-X "github.com/metal-toolbox/hollow-bomservice/internal/version.BuildDate={{ .Date }}" | ||
|
||
archives: | ||
- id: go | ||
format: tar.gz | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{ .Version }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}64bit | ||
{{- else if eq .Arch "386" }}32bit | ||
{{- else if eq .Arch "arm" }}ARM | ||
{{- else if eq .Arch "arm64" }}ARM64 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
files: | ||
- README.md | ||
|
||
checksum: | ||
name_template: "checksums.txt" | ||
|
||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" | ||
|
||
dockers: | ||
- image_templates: | ||
- "ghcr.io/metal-toolbox/{{.ProjectName}}:{{ .Tag }}" | ||
- "ghcr.io/metal-toolbox/{{.ProjectName}}:latest" | ||
dockerfile: Dockerfile | ||
build_flag_templates: | ||
- "--label=org.opencontainers.image.created={{.Date}}" | ||
- "--label=org.opencontainers.image.title={{.ProjectName}}" | ||
- "--label=org.opencontainers.image.revision={{.FullCommit}}" | ||
- "--label=org.opencontainers.image.version={{.Version}}" | ||
|
||
sboms: | ||
- artifacts: archive | ||
- id: source | ||
artifacts: source | ||
|
||
signs: | ||
- cmd: cosign | ||
signature: "${artifact}.sig" | ||
certificate: "${artifact}.pem" | ||
args: | ||
- "sign-blob" | ||
- "--oidc-issuer=https://token.actions.githubusercontent.com" | ||
- "--output-certificate=${certificate}" | ||
- "--output-signature=${signature}" | ||
- "${artifact}" | ||
- "--yes" # required on cosign 2.0.0+ | ||
artifacts: all | ||
output: true | ||
|
||
docker_signs: | ||
- cmd: cosign | ||
args: | ||
- "sign" | ||
- "--oidc-issuer=https://token.actions.githubusercontent.com" | ||
- "${artifact}" | ||
- "--yes" # required on cosign 2.0.0+ | ||
artifacts: all | ||
output: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"runtime/debug" | ||
"strings" | ||
) | ||
|
||
var ( | ||
GitCommit string | ||
GitBranch string | ||
GitSummary string | ||
BuildDate string | ||
AppVersion string | ||
ServerserviceVersion = serverserviceVersion() | ||
GoVersion = runtime.Version() | ||
) | ||
|
||
type Version struct { | ||
GitCommit string `json:"git_commit"` | ||
GitBranch string `json:"git_branch"` | ||
GitSummary string `json:"git_summary"` | ||
BuildDate string `json:"build_date"` | ||
AppVersion string `json:"app_version"` | ||
GoVersion string `json:"go_version"` | ||
ServerserviceVersion string `json:"serverservice_version"` | ||
} | ||
|
||
func Current() *Version { | ||
return &Version{ | ||
GitBranch: GitBranch, | ||
GitCommit: GitCommit, | ||
GitSummary: GitSummary, | ||
BuildDate: BuildDate, | ||
AppVersion: AppVersion, | ||
GoVersion: GoVersion, | ||
ServerserviceVersion: ServerserviceVersion, | ||
} | ||
} | ||
|
||
func (v *Version) String() string { | ||
return fmt.Sprintf("version=%s ref=%s branch=%s built=%s", v.AppVersion, v.GitCommit, v.GitBranch, v.BuildDate) | ||
} | ||
|
||
func serverserviceVersion() string { | ||
buildInfo, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return "" | ||
} | ||
|
||
for _, d := range buildInfo.Deps { | ||
if strings.Contains(d.Path, "serverservice") { | ||
return d.Version | ||
} | ||
} | ||
|
||
return "" | ||
} |