Skip to content

Commit

Permalink
ci: configure release please (#32)
Browse files Browse the repository at this point in the history
* ci: multiplatform release build; tidy Makefile
* ci: configure release-please
---------

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson authored Jun 19, 2024
1 parent 02de3a5 commit 533675c
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 42 deletions.
60 changes: 55 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,62 @@ on:
- main
- '[0-9]+.[0-9]+.x'

defaults:
run:
shell: bash

jobs:
call-release:
uses: validator-labs/workflows/.github/workflows/release.yaml@main
release-please:
permissions:
contents: write # for google-github-actions/release-please-action to create release commit
pull-requests: write # for google-github-actions/release-please-action to create release PR
runs-on: [self-hosted, Linux, X64, validator]
outputs:
releases_created: ${{ steps.release.outputs.releases_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4
id: release
with:
token: ${{ secrets.PAT }}

build-binaries:
if: needs.release-please.outputs.releases_created == 'true'
needs:
- release-please
runs-on: [self-hosted, Linux, X64, validator]
permissions:
contents: write
id-token: write
packages: write
pull-requests: write
secrets: inherit
id-token: write
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
submodules: recursive

- name: Build binaries
run: |
make build-release
- name: Generate SBOM
uses: anchore/sbom-action@e8d2a6937ecead383dfe75190d104edd1f9c5751 # v0.16.0
env:
SBOM_NAME: validator-linux-amd64-${{ needs.release-please.outputs.tag_name }}
with:
file: ./bin/validator-linux-amd64
artifact-name: sbom-validator
output-file: ./sbom-validator.spdx.json

- name: Attach artifacts to release
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # v2
with:
tag_name: ${{ needs.release-please.outputs.tag_name }}
files: |
./bin/validator-darwin-arm64
./bin/validator-linux-amd64
./bin/validator-windows-amd64
./sbom-validator.spdx.json
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{".":"0.0.1"}
50 changes: 13 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
.PHONY: docker kind kubectl helm build test
.DEFAULT_GOAL:=help

# Images
IMAGE_TAG ?= latest
CLI_IMG ?= "quay.io/validator-labs/validatorctl:$(IMAGE_TAG)"

# Dependency Versions
BUILDER_GOLANG_VERSION ?= 1.22
DOCKER_VERSION ?= 24.0.6
HELM_VERSION ?= 3.14.0
GOLANGCI_VERSION ?= 1.54.2
Expand All @@ -19,7 +14,7 @@ KUBECTL_VERSION ?= 1.24.10

# Product Version
VERSION_SUFFIX ?= -dev
VERSION ?= 0.0.1${VERSION_SUFFIX}
VERSION ?= 0.0.1${VERSION_SUFFIX} # x-release-please-version

# Common vars
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
Expand Down Expand Up @@ -48,22 +43,28 @@ TARGETARCH ?= amd64
COVER_DIR=_build/cov
COVER_PKGS=$(shell go list ./... | grep -v /tests/) # omit integration tests

# Integrated Images List
IMAGE_LIST=_build/images/images.list

##@ Help Targets
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[0m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build Targets
build: ## Build CLI
@echo "Building CLI binary..."
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GO111MODULE=on go build -ldflags " \
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags " \
-X github.com/validator-labs/validatorctl/cmd.Version=$(VERSION)" \
-a -o bin/validator validator.go

get-version: ## Get the product version
@echo "$(VERSION)"
PLATFORMS ?= linux/amd64 darwin/arm64 windows/amd64
build-release: ## Build CLI for multiple platforms
for platform in $(PLATFORMS); do \
platform_split=($${platform//\// }); \
GOOS=$${platform_split[0]}; \
GOARCH=$${platform_split[1]}; \
echo "Building CLI for $${GOOS}/$${GOARCH}..."; \
CGO_ENABLED=0 GOOS=$${GOOS} GOARCH=$${GOARCH} go build -ldflags " \
-X github.com/validator-labs/validatorctl/cmd.Version=$(VERSION)" \
-a -o bin/validator-$${GOOS}-$${GOARCH} validator.go; \
done

##@ Static Analysis Targets
fmt: ## Run go fmt
Expand Down Expand Up @@ -119,31 +120,6 @@ coverage-integration: ## Show integration test coverage
coverage-integration-html: ## Open integration test coverage report in your browser
go tool cover -html $(COVER_DIR)/integration/integration.out

##@ Image Targets

BUILD_ARGS = --build-arg CLI_VERSION=${VERSION} --build-arg BUILDER_GOLANG_VERSION=${BUILDER_GOLANG_VERSION}

docker-all: docker-cli docker-push ## Builds & pushes Docker images to container registry

docker-cli:
docker buildx build ${BUILD_ARGS} --platform linux/${TARGETARCH} --load -f build/docker/cli.Dockerfile . -t ${CLI_IMG}

docker-compose: ## Rebuild images and restart docker-compose
docker compose build
docker compose up

docker-push: ## Pushes Docker images to container registry
docker push ${CLI_IMG}
echo cli,core,${CLI_IMG} >> ${IMAGE_LIST}

docker-rmi: ## Remove Docker images from local Docker engine
docker rmi -f ${CLI_IMG}

create-images-list: ## Create the image list for CICD
mkdir -p _build/images
touch $(IMAGE_LIST)


##@ Tools Targets
binaries: docker helm kind kubectl

Expand Down
69 changes: 69 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"packages": {
".": {
"changelog-path": "CHANGELOG.md",
"release-type": "go",
"prerelease": false,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"draft": false,
"extra-files": ["Makefile"],
"changelog-sections": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Other"
},
{
"type": "docs",
"section": "Docs"
},
{
"type": "perf",
"section": "Performance"
},
{
"type": "build",
"hidden": true,
"section": "Build"
},
{
"type": "deps",
"section": "Dependency Updates"
},
{
"type": "ci",
"hidden": true,
"section": "CI"
},
{
"type": "refactor",
"section": "Refactoring"
},
{
"type": "revert",
"hidden": true,
"section": "Reverts"
},
{
"type": "style",
"hidden": true,
"section": "Styling"
},
{
"type": "test",
"hidden": true,
"section": "Tests"
}
]
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}

0 comments on commit 533675c

Please sign in to comment.