Skip to content

Merge pull request #18240 from hpidcock/merge-3.4-3.5-20241015 #1183

Merge pull request #18240 from hpidcock/merge-3.4-3.5-20241015

Merge pull request #18240 from hpidcock/merge-3.4-3.5-20241015 #1183

Workflow file for this run

name: "Generate"
on:
push:
branches: [2.*, 3.*, 4.*, main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- '**.go'
- 'go.mod'
- '.github/workflows/gen.yml'
- 'Makefile'
- 'make_functions.sh'
workflow_dispatch:
permissions:
contents: read
jobs:
Generate:
name: Generate
runs-on: [self-hosted, linux, arm64, aws, xxlarge]
if: github.event.pull_request.draft == false
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Set up Go"
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: "Regenerate code"
shell: bash
run: |
# Running go generate by itself is slow over a large codebase, where
# all generate directives are dispersed over many files. Instead, the
# following uses tools for locating and extracting the directives,
# before piping them to go generate in parallel.
#
# 1. grep for go generate directive in the go files recursively.
# 2. Grab the file name of each select file.
# 3. Unique every file, so we only go generate the file once.
# 4. Using xargs perform go generate in parallel.
#
git ls-files | xargs grep "//go:generate" --include '*.go' | awk -F : '{ print $1 }' | uniq | xargs -n 1 -P 8 -I% sh -c "go generate -x $(realpath %) || (echo FAIL: % && exit 1)"
- name: "Check diff"
if: success() || failure()
shell: bash
run: |
# The generation sometimes adds things to go.sum. Tidy to remove these.
go mod tidy
git add -A
if [[ -n $(git diff HEAD) ]]; then
# Print the full diff for debugging purposes
git diff HEAD
echo "*****"
echo "The following generated files have been modified:"
git diff --name-status HEAD
echo "Please regenerate these files and check in the changes."
echo "*****"
exit 1
fi