Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: timflannagan <[email protected]>
  • Loading branch information
timflannagan committed Jan 14, 2025
1 parent 99db769 commit 92c1ba1
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 14 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Label PR by Kind

on:
pull_request:
types: [opened, edited, reopened, synchronize]

jobs:
label-kind:
runs-on: ubuntu-latest
steps:
- name: Check PR description for kind and add label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get the pull request from the event payload
const pr = context.payload.pull_request;
if (!pr) {
core.info('No pull request found');
return;
}
// Extract the body of the pull request
const body = pr.body || "";
// Search for a "/kind enhancement" directive using regex
const match = body.match(/\/kind\s+(enhancement)/i);
if (match) {
// Extracted kind from the description
const kindLabel = match[1].toLowerCase();
core.info(`Found kind: ${kindLabel}. Adding label...`);
// Add the label to the pull request
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [kindLabel]
});
core.info(`Label "${kindLabel}" added to PR #${pr.number}.`);
} else {
core.info('No /kind enhancement found in the PR description.');
}
74 changes: 74 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ istio-*/*

# Bin directory created by e2e test
.bin/
# Added by goreleaser init:
dist/
58 changes: 58 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 21 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables
.DEFAULT_GOAL := help


#----------------------------------------------------------------------------------
# Help
#----------------------------------------------------------------------------------
Expand All @@ -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
#----------------------------------------------------------------------------------
Expand All @@ -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))
Expand All @@ -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.
Expand Down Expand Up @@ -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
#----------------------------------------------------------------------------------
Expand Down Expand Up @@ -172,18 +170,27 @@ check-format:
check-spelling:
./ci/spell.sh check

#----------------------------------------------------------------------------------
# Release
#----------------------------------------------------------------------------------

GORELEASER_ARGS ?= --snapshot --clean
GORELEASER ?= go run github.com/goreleaser/goreleaser/[email protected]
.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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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
#----------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions hack/changelog/changelog.go
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 92c1ba1

Please sign in to comment.