Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add githubgen tool #639

Merged
merged 67 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5ec8630
feat: add githubgen tool
mowies Dec 10, 2024
b90fc12
add changelog entry
mowies Dec 10, 2024
ddf8592
add githubgen to versions file
mowies Dec 10, 2024
5b0722b
adapt module name, adapt makefile
mowies Dec 10, 2024
fad052c
make linter happy
mowies Dec 10, 2024
7c4ee3e
make dependabot-generate
mowies Dec 10, 2024
275b19c
make linter happier
mowies Dec 10, 2024
644637e
more linting things
mowies Dec 10, 2024
026bd29
adjust readme, go version, flag default value
mowies Dec 10, 2024
57f140b
refactoring
mowies Dec 10, 2024
8c19e01
make linter happy
mowies Dec 10, 2024
a275020
remove githubgen from makefile
mowies Dec 11, 2024
9f50acd
refactoring
mowies Dec 11, 2024
e10eb15
WIP
mowies Dec 12, 2024
2ebadce
fixed import cycles
odubajDT Dec 12, 2024
af6b14a
move reading of distros to main func
mowies Dec 12, 2024
b15b8f7
fix license headers
mowies Dec 12, 2024
b9125f2
make tidy
mowies Dec 12, 2024
bf25a42
fix module changes
mowies Dec 12, 2024
8680c9e
remove toolchain directives
mowies Dec 12, 2024
db983d8
more reverts
mowies Dec 12, 2024
7aa885b
revert commenting out
mowies Dec 12, 2024
1ce86a1
exclude test file from linting
mowies Dec 12, 2024
1c22732
linting issues
mowies Dec 12, 2024
3414c25
regenerate mock file
mowies Dec 12, 2024
61fc9b5
try adding moq to tools
mowies Dec 12, 2024
87c0810
use older version
mowies Dec 12, 2024
08f713b
go mod tidy
mowies Dec 12, 2024
250e066
again
mowies Dec 12, 2024
3eb81ba
try again
mowies Dec 12, 2024
a7b6b3c
add moq tool to internal tools
mowies Dec 12, 2024
bd70d7c
use correct relative path
mowies Dec 12, 2024
1fa7e1f
revert relative path
mowies Dec 12, 2024
ae2e37c
install tools of cache was not hit
mowies Dec 12, 2024
49071fa
maybe fix tools cache
mowies Dec 12, 2024
c803c05
debugging windows CI
mowies Dec 12, 2024
4bda691
debugging windows CI
mowies Dec 12, 2024
1026f1d
fix caching again
mowies Dec 12, 2024
bc8fd6e
try fixing for windows
mowies Dec 16, 2024
e526826
remove linting for now
mowies Dec 16, 2024
7cf652b
try again
mowies Dec 16, 2024
6eb4b08
set up GH cache
mowies Dec 16, 2024
e735a73
revert
mowies Dec 16, 2024
9c2b154
debugging
mowies Dec 16, 2024
2dd8aa2
try again
mowies Dec 16, 2024
645483f
again
mowies Dec 16, 2024
33f22e3
more debugging
mowies Dec 16, 2024
513d1f9
more debugging
mowies Dec 16, 2024
25e07b6
more debugging
mowies Dec 16, 2024
f8c25da
try switching path delimiter
mowies Dec 16, 2024
57259d7
try with lesss quotes
mowies Dec 16, 2024
66c4108
try with lesss quotes
mowies Dec 16, 2024
b46f4bb
again
mowies Dec 16, 2024
bb4b012
try again
mowies Dec 16, 2024
4088866
try exporting before loop
mowies Dec 16, 2024
70f872a
try again
mowies Dec 16, 2024
c3ba601
works but sucks...
mowies Dec 16, 2024
435f0d0
try ls ing the path
mowies Dec 16, 2024
08f9cf7
debugging
mowies Dec 16, 2024
588c907
try some more things
mowies Dec 16, 2024
8b3e049
try setting pipeline shell to bash
mowies Dec 16, 2024
74f7d03
add exe file ending on windows
mowies Dec 18, 2024
17e72e7
try with bash
mowies Dec 18, 2024
280ba24
debugging
mowies Dec 18, 2024
4adfe5d
cleanup
mowies Dec 18, 2024
a5142fb
remove githubgen from versions file to unblock releases until all fol…
mowies Dec 18, 2024
7d87860
revert
mowies Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/add-githubgen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'new_component'

# The name of the component, or a single word describing the area of concern, (e.g. crosslink)
component: githubgen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Moved githubgen tool here from open-telemetry/opentelemetry-collector-contrib

# One or more tracking issues related to the change
issues: [639]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
10 changes: 5 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ updates:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /checkdoc
directory: /checkfile
labels:
- dependencies
- go
Expand All @@ -29,7 +29,7 @@ updates:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /checkfile
directory: /chloggen
labels:
- dependencies
- go
Expand All @@ -38,7 +38,7 @@ updates:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /chloggen
directory: /crosslink
labels:
- dependencies
- go
Expand All @@ -47,7 +47,7 @@ updates:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /crosslink
directory: /dbotconf
labels:
- dependencies
- go
Expand All @@ -56,7 +56,7 @@ updates:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /dbotconf
directory: /githubgen
labels:
- dependencies
- go
Expand Down
31 changes: 30 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,45 @@ jobs:
with:
go-version: ${{ env.DEFAULT_GO_VERSION }}
check-latest: true

- name: Checkout Repo
uses: actions/checkout@v4

- name: Module cache
uses: actions/cache@v4
env:
cache-name: go-mod-cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}

- name: Tools cache
id: cache-tools
uses: actions/cache@v4
env:
cache-name: go-tools-cache
with:
path: ~/.tools
path: .tools
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('./internal/tools/**') }}

- name: Install tools
if: steps.cache-tools.outputs.cache-hit != 'true'
run: make tools

- name: Add .exe to tools on Windows
if: matrix.os == 'windows-latest'
shell: bash
run: |
for file in ./.tools/*; do
cp "$file" "${file}.exe"
done

- name: Run linters
run: make multimod-verify dependabot-check license-check lint

- name: Build
run: make build

- name: Check clean repository
run: make check-clean-work-tree

Expand All @@ -55,19 +74,23 @@ jobs:
with:
go-version: ${{ env.DEFAULT_GO_VERSION }}
check-latest: true

- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Environment
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- name: Module cache
uses: actions/cache@v4
env:
cache-name: go-mod-cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}

- name: Run tests with race detector
run: make test-race

Expand All @@ -79,33 +102,39 @@ jobs:
with:
go-version: ${{ env.DEFAULT_GO_VERSION }}
check-latest: true

- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Environment
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- name: Module cache
uses: actions/cache@v4
env:
cache-name: go-mod-cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}

- name: Run coverage tests
run: |
make test-coverage
mkdir $TEST_RESULTS
cp coverage.out $TEST_RESULTS
cp coverage.txt $TEST_RESULTS
cp coverage.html $TEST_RESULTS

- name: Upload coverage report
uses: codecov/[email protected]
with:
file: ./coverage.txt
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Store coverage test output
uses: actions/upload-artifact@v4
with:
Expand Down
27 changes: 24 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

SHELL_CASE_EXP = case "$$(uname -s)" in CYGWIN*|MINGW*|MSYS*) echo "true";; esac;
UNIX_SHELL_ON_WINDOWS := $(shell $(SHELL_CASE_EXP))

ifeq ($(UNIX_SHELL_ON_WINDOWS),true)
# The "sed" transformation below is needed on Windows, since commands like `go list -f '{{ .Dir }}'`
# return Windows paths and such paths are incompatible with other *nix tools, like `find`,
# used by the Makefile shell.
# The backslash needs to be doubled so its passed correctly to the shell.
NORMALIZE_DIRS = sed -e 's/^/\\//' -e 's/://' -e 's/\\\\/\\//g' | sort
PATH_SEPARATOR=;
else
NORMALIZE_DIRS = sort
PATH_SEPARATOR=:
endif

TOOLS_MOD_DIR := ./internal/tools

# All source code and documents. Used in spell check.
Expand All @@ -20,7 +35,7 @@ ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
ALL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort))
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^$(TOOLS_MOD_DIR)' | sort)

GO = go
GO ?= go
TIMEOUT = 60

.DEFAULT_GOAL := precommit
Expand Down Expand Up @@ -60,17 +75,23 @@ $(TOOLS)/chloggen: PACKAGE=go.opentelemetry.io/build-tools/chloggen
GOVULNCHECK = $(TOOLS)/govulncheck
$(TOOLS)/govulncheck: PACKAGE=golang.org/x/vuln/cmd/govulncheck

MOQ = $(TOOLS)/moq
$(TOOLS)/moq: PACKAGE=github.com/matryer/moq

.PHONY: tools
tools: $(DBOTCONF) $(GOLANGCI_LINT) $(MISSPELL) $(MULTIMOD) $(CROSSLINK) $(CHLOGGEN) $(GOVULNCHECK)
tools: $(DBOTCONF) $(GOLANGCI_LINT) $(MISSPELL) $(MULTIMOD) $(CROSSLINK) $(CHLOGGEN) $(GOVULNCHECK) $(MOQ)

# Build

UPDATED_PATH := $(shell echo $(TOOLS) | $(NORMALIZE_DIRS))
NEW_PATH := $(UPDATED_PATH)$(PATH_SEPARATOR)$(PATH)

.PHONY: generate build
generate:
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
echo "$(GO) generate $${dir}/..."; \
(cd "$${dir}" && \
PATH="$(TOOLS):$${PATH}" $(GO) generate ./...); \
PATH="$(UPDATED_PATH)$(PATH_SEPARATOR)$${PATH}" $(GO) generate ./...); \
done

build: generate
Expand Down
37 changes: 37 additions & 0 deletions githubgen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# githubgen

This executable is used to generate `.github/CODEOWNERS` and
`.github/ALLOWLIST` files.

It reads status metadata from `metadata.yaml` files located throughout the
repository.

It checks that codeowners are known members of the OpenTelemetry organization.

## Usage

```shell
$> ./githubgen
```

The equivalent of:

```shell
$> GITHUB_TOKEN=<mypattoken> githubgen --folder . [--allowlist cmd/githubgen/allowlist.txt]
```

## Checking codeowners against OpenTelemetry membership via GitHub API

To authenticate, set the environment variable `GITHUB_TOKEN` to a PAT token.
If a PAT is not available you can use the `--skipgithub` flag to avoid checking
for membership in the GitHub organization.

For each codeowner, the script will check if the user is registered as a member
of the OpenTelemetry organization.

If any codeowner is missing, it will stop and print names of missing codeowners.

These can be added to allowlist.txt as a workaround.

If a codeowner is present in allowlist.txt and also a member of the
OpenTelemetry organization, the script will error out.
Loading
Loading