Skip to content

Commit

Permalink
add release job and configs
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Mar 28, 2024
1 parent 0572c8f commit 24c4350
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,86 @@
name: Release

on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
release:
runs-on: ubuntu-latest

permissions:
id-token: write
contents: write

env:
COSIGN_YES: "true"

steps:
- name: Check out code onto GOPATH
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 1

- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: './go.mod'
check-latest: true

- name: Install cosign
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0

- name: Install bom
uses: kubernetes-sigs/release-actions/setup-bom@10fecc1c66829d291b2f2fb1a27329d152f212e6 # v0.1.3

- name: Install GoReleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
with:
install-only: true

- name: Get TAG
id: get_tag
run: echo "TAG=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT"

- name: Run Mage
uses: magefile/mage-action@6a5dcb5fe61f43d7c08a98bc3cf9bc63c308c08e # v3.0.0
with:
version: latest
args: buildBinaries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

attestation:
runs-on: ubuntu-latest

permissions:
id-token: write
contents: write

needs:
- release

steps:
- name: Check out code onto GOPATH
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 1

- name: Set tag output
id: tag
run: echo "tag_name=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT"

- name: Install tejolote
uses: kubernetes-sigs/release-actions/setup-tejolote@10fecc1c66829d291b2f2fb1a27329d152f212e6 # v0.1.3

- run: |
tejolote attest --artifacts github://kubernetes-sigs/tejolote/${{ steps.tag.outputs.tag_name }} github://kubernetes-sigs/tejolote/"${GITHUB_RUN_ID}" --output tejolote.intoto.json --sign
- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15
with:
files: tejolote.intoto.json
tag_name: "${{ steps.tag.outputs.tag_name }}"
token: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_REPOSITORY: kubernetes-sigs/tejolote
31 changes: 31 additions & 0 deletions .github/workflows/snapshot.yml
@@ -0,0 +1,31 @@
name: Snapshot

on:
push:
branches:
- 'main'
pull_request:

jobs:
snapshot:
runs-on: ubuntu-latest

steps:
- name: Check out code onto GOPATH
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: './go.mod'
check-latest: true

- name: Install bom
uses: kubernetes-sigs/release-actions/setup-bom@10fecc1c66829d291b2f2fb1a27329d152f212e6 # v0.1.3

- name: Install GoReleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
with:
install-only: true

- name: check binary
run: ./dist/mdtoc-amd64-linux -version
82 changes: 82 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,82 @@
project_name: mdtoc

env:
- CGO_ENABLED=0
- COSIGN_YES=true

before:
hooks:
- go mod tidy
# - /bin/bash -c 'if [ -n "$(git --no-pager diff --exit-code go.mod go.sum)" ]; then exit 1; fi'

gomod:
proxy: true

builds:
- id: mdtoc
dir: .
no_unique_dist_dir: true
binary: mdtoc-{{ .Arch }}-{{ .Os }}
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
- arm
goarm:
- '7'
ignore:
- goos: windows
goarch: arm
flags:
- -trimpath
ldflags:
- "{{ .Env.LDFLAGS }}"

archives:
- format: binary
name_template: "{{ .Binary }}"
allow_different_binary_count: true

signs:
# Keyless
- id: mdtoc-keyless
signature: "${artifact}.sig"
certificate: "${artifact}.pem"
cmd: cosign
args: ["sign-blob", "--output-signature", "${artifact}.sig", "--output-certificate", "${artifact}.pem", "${artifact}"]
artifacts: all

sboms:
- id: mdtoc
cmd: bom
args:
- generate
- "--output"
- "mdtoc-bom.json.spdx"
- "-d"
- "../"
- "-c"
- "../.mdtoc-bom-config.yaml"
- "--format"
- "json"
artifacts: any
documents:
- "mdtoc-bom.json.spdx"

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ .Tag }}-next"

release:
github:
owner: kubernetes-sigs
name: mdtoc
prerelease: auto

changelog:
skip: true
43 changes: 43 additions & 0 deletions .mdtoc-bom-config.yaml
@@ -0,0 +1,43 @@
---
namespace: https://sigs.k8s.io/zeitgeist
license: Apache-2.0
name: mdtoc
creator:
person: The Kubernetes Authors
tool: mdtoc

artifacts:
- type: file
source: mdtoc-amd64-windows.exe
license: Apache-2.0
gomodules: true

- type: file
source: mdtoc-arm64-windows.exe
license: Apache-2.0
gomodules: true

- type: file
source: mdtoc-amd64-darwin
license: Apache-2.0
gomodules: true

- type: file
source: mdtoc-amd64-linux
license: Apache-2.0
gomodules: true

- type: file
source: mdtoc-arm-linux
license: Apache-2.0
gomodules: true

- type: file
source: mdtoc-arm64-darwin
license: Apache-2.0
gomodules: true

- type: file
source: mdtoc-arm64-linux
license: Apache-2.0
gomodules: true
40 changes: 40 additions & 0 deletions Makefile
Expand Up @@ -21,6 +21,34 @@ SHELL:=/usr/bin/env bash
COLOR:=\\033[36m
NOCOLOR:=\\033[0m

# Set version variables for 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

LDFLAGS=-buildid= -X sigs.k8s.io/release-utils/version.gitVersion=$(GIT_VERSION) \
-X sigs.k8s.io/release-utils/version.gitCommit=$(GIT_HASH) \
-X sigs.k8s.io/release-utils/version.gitTreeState=$(GIT_TREESTATE) \
-X sigs.k8s.io/release-utils/version.buildDate=$(BUILD_DATE)


##@ Build

build: ## Build mdtoc
# build local version
go build -trimpath -ldflags "$(LDFLAGS)" -o ./output/mdtoc .

##@ Verify

.PHONY: verify verify-boilerplate verify-dependencies verify-go-mod verify-golangci-lint
Expand Down Expand Up @@ -58,6 +86,18 @@ update-deps-go: ## Update all golang dependencies for this repo
go mod verify
$(MAKE) test

## Release

.PHONY: goreleaser
goreleaser: ## Build zeitgeist binaries with goreleaser
LDFLAGS="$(LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
goreleaser release --clean

.PHONY: snapshot
snapshot: ## Build zeitgeist binaries with goreleaser in snapshot mode
LDFLAGS="$(LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \
goreleaser release --clean --snapshot --skip=sign,publish

##@ Helpers

.PHONY: help
Expand Down

0 comments on commit 24c4350

Please sign in to comment.