From 8239cc58ab1070193d58ca4e7255636a0a00e4ba Mon Sep 17 00:00:00 2001 From: timflannagan Date: Tue, 14 Jan 2025 20:55:50 +0000 Subject: [PATCH] WIP Signed-off-by: timflannagan --- .github/workflows/changelog.yaml | 38 ++++++++++++++++ .github/workflows/release.yaml | 74 ++++++++++++++++++++++++++++++++ .gitignore | 2 + .goreleaser.yaml | 58 +++++++++++++++++++++++++ Makefile | 35 +++++++++------ hack/changelog/changelog.go | 22 ++++++++++ 6 files changed, 215 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/changelog.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml create mode 100644 hack/changelog/changelog.go diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml new file mode 100644 index 000000000000..8941fc418554 --- /dev/null +++ b/.github/workflows/changelog.yaml @@ -0,0 +1,38 @@ +name: Label PR by Kind + +on: + pull_request: + types: [opened, edited, reopened, synchronize] + +permissions: + issues: write + +jobs: + kind-label: + runs-on: ubuntu-latest + steps: + - name: Extract /kind from PR description + id: extract-kind + run: | + sudo apt-get update && sudo apt-get install -y jq + # Extract PR description using jq + PR_DESCRIPTION=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH") + echo "PR_DESCRIPTION: $PR_DESCRIPTION" + + # Use regex to find "/kind " + if [[ $PR_DESCRIPTION =~ /kind[[:space:]]+([[:alnum:]-]+) ]]; then + KIND_LABEL=${BASH_REMATCH[1]} + echo "Detected kind: $KIND_LABEL" + # Set the output for use in later steps + echo "::set-output name=kind::${KIND_LABEL}" + else + echo "No /kind found." + echo "::set-output name=kind::" + fi + shell: bash + + - name: Add detected kind label + if: steps.extract-kind.outputs.kind != '' + uses: christianvuerings/add-labels@v1 + with: + labels: ${{ steps.extract-kind.outputs.kind }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000000..5313cf621ff3 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,74 @@ +name: Release +on: + workflow_dispatch: + push: + tags: + - 'v*' + pull_request: + branches: + - main + +env: + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} + +permissions: + contents: write + id-token: write + packages: write + +jobs: + goreleaser: + name: goreleaser + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + cache: true + + # TODO(tim): Manage tools in this repo better so we can cache them. + # - uses: actions/cache@v4 + # with: + # path: hack/tools + # key: ${{ runner.os }}-go-tools${{ hashFiles('hack/tools/go.sum') }} + # restore-keys: | + # ${{ runner.os }}-go-tools- + + - name: Log into ghcr.io + uses: docker/login-action@v3 + with: + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set the release related variables + id: set_vars + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + # Release tags. + VERSION="${GITHUB_REF#refs/tags/}" + echo GORELEASER_ARGS="--clean" + elif [[ $GITHUB_REF == refs/heads/main ]]; then + # 'main' branch build. + VERSION="$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's|/+|-|g')" + echo GORELEASER_ARGS="--clean --skip=validate" >> $GITHUB_ENV + elif [[ $GITHUB_REF == refs/pull/* ]]; then + # PR build. + VERSION="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')" + else + VERSION="$(git describe --tags --always)" + fi + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + - name: Run goreleaser + run: make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ env.VERSION }} + IMAGE_REGISTRY: ${{ env.IMAGE_REGISTRY }} diff --git a/.gitignore b/.gitignore index e69f58fbc9b0..d8044fd14900 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,5 @@ istio-*/* # Bin directory created by e2e test .bin/ +# Added by goreleaser init: +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 000000000000..231b21ac901c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,58 @@ +version: 2 +before: + hooks: + - go mod tidy + - go mod download +builds: + - id: controller + main: ./projects/gloo/cmd/ + binary: gloo-linux-{{ .Arch }} + gcflags: "{{ .Env.GCFLAGS }}" + ldflags: "{{ .Env.LDFLAGS }}" + env: + - CGO_ENABLED=0 + - GO111MODULE=on + - GOARCH={{ .Arch }} + - GOOS={{ .Os }} + mod_timestamp: "{{ .CommitTimestamp }}" + goos: + - linux + goarch: + - amd64 + - arm64 +dockers: + - image_templates: + - &arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.IMAGE_REPO }}:{{ .Env.VERSION }}-arm64" + use: buildx + dockerfile: &dockerfile projects/gloo/cmd/Dockerfile + goos: linux + goarch: arm64 + build_flag_templates: + - "--pull" + - "--platform=linux/arm64" + - "--build-arg=GOARCH=arm64" + - "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_GLOO_IMAGE }}" + - image_templates: + - &amd_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.IMAGE_REPO }}:{{ .Env.VERSION }}-amd64" + use: buildx + dockerfile: *dockerfile + goos: linux + goarch: amd64 + build_flag_templates: + - "--pull" + - "--platform=linux/amd64" + - "--build-arg=GOARCH=amd64" + - "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_GLOO_IMAGE }}" +docker_manifests: + - name_template: "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.IMAGE_REPO }}:{{ .Env.VERSION }}" + image_templates: + - *amd_image + - *arm_image +changelog: + use: "github-native" + sort: "asc" + disable: false +release: + draft: false + prerelease: "auto" + mode: "replace" diff --git a/Makefile b/Makefile index cf89f5fe0aeb..aa4703b341ca 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ # https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables .DEFAULT_GOAL := help - #---------------------------------------------------------------------------------- # Help #---------------------------------------------------------------------------------- @@ -21,7 +20,6 @@ help: LINE_COLUMN_WIDTH=5 help: ## Output the self-documenting make targets @grep -hnE '^[%a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = "[:]|(## )"}; {printf "\033[36mL%-$(LINE_COLUMN_WIDTH)s%-$(NAME_COLUMN_WIDTH)s\033[0m %s\n", $$1, $$2, $$4}' - #---------------------------------------------------------------------------------- # Base #---------------------------------------------------------------------------------- @@ -33,7 +31,8 @@ OUTPUT_DIR ?= $(ROOTDIR)/_output # To use quay images, set the IMAGE_REGISTRY to "quay.io/solo-io" (or leave unset) # To use dockerhub images, set the IMAGE_REGISTRY to "soloio" # To use gcr images, set the IMAGE_REGISTRY to "gcr.io/$PROJECT_NAME" -IMAGE_REGISTRY ?= quay.io/solo-io +export IMAGE_REGISTRY ?= ghcr.io/kgateway +export IMAGE_REPO ?= kgateway # Kind of a hack to make sure _output exists z := $(shell mkdir -p $(OUTPUT_DIR)) @@ -49,9 +48,9 @@ SOURCES := $(shell find . -name "*.go" | grep -v test.go) # for more information, see https://github.com/solo-io/gloo/pull/9633 # and # https://soloio.slab.com/posts/extended-http-methods-design-doc-40j7pjeu -ENVOY_GLOO_IMAGE ?= quay.io/solo-io/envoy-gloo:1.31.2-patch3 -LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)" -GCFLAGS ?= +export ENVOY_GLOO_IMAGE ?= quay.io/solo-io/envoy-gloo:1.31.2-patch3 +export LDFLAGS := -X github.com/solo-io/gloo/pkg/version.Version=$(VERSION) +export GCFLAGS ?= UNAME_M := $(shell uname -m) # if `GO_ARCH` is set, then it will keep its value. Else, it will be changed based off the machine's host architecture. @@ -126,7 +125,6 @@ ALPINE_BASE_IMAGE ?= alpine:3.17.6 # in the tree rooted at that directory that match the given criteria. get_sources = $(shell find $(1) -name "*.go" | grep -v test | grep -v generated.go | grep -v mock_) - #---------------------------------------------------------------------------------- # Imports #---------------------------------------------------------------------------------- @@ -172,18 +170,27 @@ check-format: check-spelling: ./ci/spell.sh check +#---------------------------------------------------------------------------------- +# Release +#---------------------------------------------------------------------------------- + +GORELEASER_ARGS ?= --snapshot --clean +GORELEASER ?= go run github.com/goreleaser/goreleaser/v2@v2.5.1 +.PHONY: release +release: + $(GORELEASER) release $(GORELEASER_ARGS) + #---------------------------------------------------------------------------- # Analyze #---------------------------------------------------------------------------- LINTER_VERSION := $(shell cat .github/workflows/static-analysis.yaml | yq '.jobs.static-analysis.steps.[] | select( .uses == "*golangci/golangci-lint-action*") | .with.version ') # The analyze target runs a suite of static analysis tools against the codebase. -# The options are defined in .golangci.yaml, and can be overridden by setting the ANALYZE_OPTIONS variable. +# The options are defined in .golangci.yaml, and can be overridden by setting the ANALYZE_ARGS variable. .PHONY: analyze -ANALYZE_OPTIONS ?= --fast --verbose +ANALYZE_ARGS ?= --fast --verbose analyze: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(LINTER_VERSION) run $(ANALYZE_OPTIONS) ./... - + go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(LINTER_VERSION) run $(ANALYZE_ARGS) ./... #---------------------------------------------------------------------------------- # Ginkgo Tests @@ -237,7 +244,7 @@ run-kube-e2e-tests: test #---------------------------------------------------------------------------------- # Go Tests #---------------------------------------------------------------------------------- -GO_TEST_ENV ?= +GO_TEST_ENV ?= # Testings flags: https://pkg.go.dev/cmd/go#hdr-Testing_flags # The default timeout for a suite is 10 minutes, but this can be overridden by setting the -timeout flag. Currently set # to 25 minutes based on the time it takes to run the longest test setup (k8s_gw_test). @@ -378,7 +385,6 @@ generated-code-cleanup: getter-check mod-tidy update-licenses fmt ## Executes th generate-changelog: ## Generate a changelog entry @./devel/tools/changelog.sh - #---------------------------------------------------------------------------------- # Generate CRD Reference Documentation # @@ -521,7 +527,6 @@ discovery-distroless-docker: $(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH) $ --build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_IMAGE) \ -t $(IMAGE_REGISTRY)/discovery:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL) - #---------------------------------------------------------------------------------- # Gloo #---------------------------------------------------------------------------------- @@ -804,6 +809,8 @@ VERSION := $(shell echo $(TAGGED_VERSION) | cut -c 2-) LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)" endif +export VERSION + # controller variable for the "Publish Artifacts" section. Defines which targets exist. Possible Values: NONE, RELEASE, PULL_REQUEST PUBLISH_CONTEXT ?= NONE # specify which bucket to upload helm chart to diff --git a/hack/changelog/changelog.go b/hack/changelog/changelog.go new file mode 100644 index 000000000000..86762a09f7be --- /dev/null +++ b/hack/changelog/changelog.go @@ -0,0 +1,22 @@ +package changelog + +import ( + "fmt" + "os" + + "github.com/go-git/go-git/v5" +) + +func main() { + if err := generate(); err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } +} + +func generate() error { + r, err := git.PlainOpen(".") + if err != nil { + return err + } +}