Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: timflannagan <timflannagan@gmail.com>
  • Loading branch information
timflannagan committed Jan 15, 2025
1 parent 9526b64 commit 1b3f902
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 14 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/add-type-label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Label PR by Kind

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

permissions:
pull-requests: write

jobs:
# TODO(tim): cache JQ.
install-jq:
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
release-note:
runs-on: ubuntu-latest
needs: install-jq
steps:
- name: Extract release note content
id: extract-release-note
shell: bash
run: |
# Extract PR description using jq
PR_DESCRIPTION=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH")
echo "PR_DESCRIPTION: $PR_DESCRIPTION"
# Extract the content between the release-note fences
RELEASE_NOTE=$(echo "$PR_DESCRIPTION" | awk '/```release-note/{flag=1;next}/```/{flag=0}flag')
RELEASE_NOTE=$(echo "$RELEASE_NOTE" | tr -d '\r\n' | xargs)
if [[ $RELEASE_NOTE == "NONE" ]]; then
# no release note needed.
echo "::set-output name=release-note::false"
elif [[ $RELEASE_NOTE == "" ]]; then
# invalid, no release note found.
echo "::set-output name=release-note::invalid"
else
# else, release note found.
echo "::set-output name=release-note::true"
fi
echo "Extracted RELEASE_NOTE: '$RELEASE_NOTE'"
echo "::set-output name=release_note::$RELEASE_NOTE"
- name: Add release-note label when the release note is present
if: ${{ steps.extract-release-note.outputs.release-note == 'true' && !contains(github.event.pull_request.labels.*.name, 'release-note') }}
uses: actions-ecosystem/action-add-labels@v1
with:
labels: release-note
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Add do-not-merge label when the release note is missing
if: ${{ steps.extract-release-note.outputs.release_note == 'invalid' && !contains(github.event.pull_request.labels.*.name, 'do-not-merge') }}
uses: actions-ecosystem/action-add-labels@v1
with:
labels: do-not-merge
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Remove stale do-not-merge label when release note is present or NONE
if: ${{ steps.extract-release-note.outputs.release-note != 'invalid' && contains(github.event.pull_request.labels.*.name, 'do-not-merge') }}
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: do-not-merge
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Remove stale release-note label when release note is missing or NONE
if: ${{ steps.extract-release-note.outputs.release-note != 'true' && contains(github.event.pull_request.labels.*.name, 'release-note') }}
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: release-note
github_token: ${{ secrets.GITHUB_TOKEN }}
kind-label:
runs-on: ubuntu-latest
needs: install-jq
steps:
- name: Extract /kind from PR description
id: extract-kind
shell: bash
run: |
# Extract PR description using jq
PR_DESCRIPTION=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH")
echo "Original PR_DESCRIPTION: $PR_DESCRIPTION"
# Remove HTML comment blocks to avoid false matches in commented sections
CLEAN_DESCRIPTION=$(echo "$PR_DESCRIPTION" | sed '/<!--/,/-->/d')
echo "Cleaned PR_DESCRIPTION: $CLEAN_DESCRIPTION"
# Use regex on the cleaned description to find "/kind <something>"
if [[ $CLEAN_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
- name: Validate and prepare kind label removal
if: steps.extract-kind.outputs.kind != ''
shell: bash
run: |
KIND_LABEL=${{ steps.extract-kind.outputs.kind }}
SUPPORTED_KINDS=( "bug" "enhancement" "helm" "deprecation" "breaking-change" )
# Validate that the kind is supported
if [[ ! " ${SUPPORTED_KINDS[@]} " =~ " ${KIND_LABEL} " ]]; then
echo "Unsupported kind label: $KIND_LABEL"
echo "Supported kinds: ${SUPPORTED_KINDS[@]}"
# TODO(tim): we should add a label to the PR to indicate that the kind is invalid.
exit 1
fi
# Build a list of all kind labels except the current one
LABELS_TO_REMOVE=()
for kind in "${SUPPORTED_KINDS[@]}"; do
if [[ "$kind" != "$KIND_LABEL" ]]; then
LABELS_TO_REMOVE+=( "kind/$kind" )
fi
done
# Export the list of labels to remove as a space-separated string
echo "::set-output name=labels_to_remove::${LABELS_TO_REMOVE[*]}"
# TODO(tim): this is broken, we need to fix it.
- name: Remove existing kind labels to prevent stale labels
uses: actions-ecosystem/action-remove-labels@v1
if: steps.extract-kind.outputs.kind != ''
with:
labels: ${{ steps.validate_and_prepare_kind_label_removal.outputs.labels_to_remove }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Add labels to PR
uses: actions-ecosystem/action-add-labels@v1
if: ${{ steps.extract-kind.outputs.kind != '' }}
with:
labels: |
kind/${{ steps.extract-kind.outputs.kind }}
github_token: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Generate CHANGELOG

on:
workflow_dispatch:

permissions:
contents: write
issues: read

jobs:
generate-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up GitHub CLI
run: |
sudo apt-get install -y gh jq
- name: Generate CHANGELOG
run: |
./hack/changelog.sh
- name: Commit and push CHANGELOG
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet CHANGELOG.md; then
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md [skip ci]"
git push
else
echo "No changes in CHANGELOG.md"
fi
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"
Loading

0 comments on commit 1b3f902

Please sign in to comment.