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

✨ Make apigen a standalone go module #2669

Merged
merged 2 commits into from
Jan 24, 2023

Conversation

ncdc
Copy link
Member

@ncdc ncdc commented Jan 24, 2023

Summary

Make apigen a standalone go module so it can be installed by itself.

Related issue(s)

Fixes #2668

@openshift-ci openshift-ci bot requested review from csams and s-urbaniak January 24, 2023 18:56
@ncdc ncdc requested review from stevekuznetsov, clubanderson, MikeSpreitzer and sttts and removed request for s-urbaniak and csams January 24, 2023 18:56
@clubanderson
Copy link

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 24, 2023
mapfile -t DIRS < <(find "${REPO_ROOT}" -name go.mod -print0 | xargs -0 dirname)

for dir in "${DIRS[@]}"; do
pushd "$dir" &> /dev/null
Copy link
Contributor

@MikeSpreitzer MikeSpreitzer Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ( cd $dir; ... ) is safer than pushd $dir; ...; popd

Copy link
Contributor

@MikeSpreitzer MikeSpreitzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know how to test that it solves the problem. I tried and failed as follows.

(base) mspreitz@mjs12 test5 % go install github.com/ncdc/kcp/cmd/apigen@bd5342130765ecec91053b5690e9e246c41372df
go: downloading github.com/ncdc/kcp/cmd/apigen v0.0.0-20230124185555-bd5342130765
go: downloading github.com/ncdc/kcp v0.0.0-20230124185555-bd5342130765
go: github.com/ncdc/kcp/cmd/apigen@bd5342130765ecec91053b5690e9e246c41372df: github.com/ncdc/kcp/cmd/[email protected]: parsing go.mod:
	module declares its path as: github.com/kcp-dev/kcp/cmd/apigen
	        but was required as: github.com/ncdc/kcp/cmd/apigen

@MikeSpreitzer
Copy link
Contributor

I see that this avoids the "replace" for apis by requiring a specific version rather than replacing with the version in the same commit. This requires updating the "require" line every time the apis change. Just checking that this consequence is understood and approved by others.


REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)

mapfile -t DIRS < <(find "${REPO_ROOT}" -name go.mod -print0 | xargs -0 dirname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dirname terminates its output with a newline, right? So despite all the effort, this still fails when a directory name includes a newline, right? There are simpler approaches that accomplish as much. OTOH, if you want to succeed when the directory name contains a newline, perhaps find ... -exec process.sh \{\} \;.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am following the shellcheck suggestions

Copy link
Contributor

@MikeSpreitzer MikeSpreitzer Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following makes shellcheck happy and works with newlines in the directory name. It starts with a listing showing all the paths used in this test.

bash-5.1$ find . -name go.mod
./ta
ste/go.mod
./go.mod
./docs/go.mod
./te  st/go.mod
./pkg/apis/go.mod

bash-5.1$ cat > process.sh
#!/usr/bin/env bash
echo "Working on (${1%/go.mod})"

bash-5.1$ chmod a+x process.sh

bash-5.1$ find . -name go.mod -exec "$PWD/process.sh" \{\} \;
Working on (./ta
ste)
Working on (.)
Working on (./docs)
Working on (./te  st)
Working on (./pkg/apis)

@ncdc
Copy link
Member Author

ncdc commented Jan 24, 2023

I do not know how to test that it solves the problem. I tried and failed as follows.

This will only work after it merges.

I see that this avoids the "replace" for apis by requiring a specific version rather than replacing with the version in the same commit. This requires updating the "require" line every time the apis change. Just checking that this consequence is understood and approved by others.

We only have to update if/when the code in apigen's main.go needs to react to changes to the apis such that the generation logic needs to change. For typical api modifications, we shouldn't need to change anything.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 24, 2023
@clubanderson
Copy link

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 24, 2023
@ncdc
Copy link
Member Author

ncdc commented Jan 24, 2023

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 24, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ncdc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 24, 2023
@openshift-merge-robot openshift-merge-robot merged commit cb8dd3c into kcp-dev:main Jan 24, 2023
@MikeSpreitzer
Copy link
Contributor

Thanks!

@MikeSpreitzer
Copy link
Contributor

Still having trouble testing.

(base) mspreitz@mjs12 ~ % mkdir test6

(base) mspreitz@mjs12 ~ % cd test6

(base) mspreitz@mjs12 test6 % GOBIN=$PWD go install github.com/ncdc/kcp/cmd/apigen@cb8dd3c46470f30414c6789be956162ccb21f669
go: github.com/ncdc/kcp/cmd/apigen@cb8dd3c46470f30414c6789be956162ccb21f669: github.com/ncdc/kcp/cmd/apigen@cb8dd3c46470f30414c6789be956162ccb21f669: invalid version: unknown revision cb8dd3c46470f30414c6789be956162ccb21f669


(base) mspreitz@mjs12 test6 % GOBIN=$PWD go install github.com/ncdc/kcp/cmd/[email protected]  
go: github.com/ncdc/kcp/cmd/[email protected]: github.com/ncdc/kcp/cmd/[email protected]: invalid version: unknown revision cb8dd3c46470

@ncdc
Copy link
Member Author

ncdc commented Jan 25, 2023

It looks like you're still trying to use my ncdc fork. You'll want to try github.com/kcp-dev/kcp/cmd/apigen instead:

$ cd /tmp
$ mkdir foo
$ cd foo
$ go install github.com/kcp-dev/kcp/cmd/apigen@main
go: downloading github.com/kcp-dev/kcp/cmd/apigen v0.0.0-20230124223207-cb8dd3c46470
go: downloading github.com/kcp-dev/kcp v0.10.1-0.20230124223207-cb8dd3c46470

@MikeSpreitzer
Copy link
Contributor

D'oh! Yes, it works when I do it right.

(base) mspreitz@mjs12 ~ % mkdir test7

(base) mspreitz@mjs12 ~ % cd test7

(base) mspreitz@mjs12 test7 % GOBIN=$PWD go install github.com/kcp-dev/kcp/cmd/apigen@cb8dd3c46470f30414c6789be956162ccb21f669
go: downloading github.com/kcp-dev/kcp/cmd/apigen v0.0.0-20230124223207-cb8dd3c46470
go: downloading github.com/kcp-dev/kcp/pkg/apis v0.10.1-0.20230123155139-7b3126cbf96c
go: downloading github.com/bombsimon/logrusr/v3 v3.1.0
go: downloading k8s.io/apiserver v0.24.3
go: downloading k8s.io/component-base v0.24.3

(base) mspreitz@mjs12 test7 % ls -l
total 111256
-rwxr-xr-x  1 mspreitz  staff  56960512 Jan 24 23:53 apigen

(base) mspreitz@mjs12 test7 % date
Tue Jan 24 23:54:08 EST 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: can not go install apigen
4 participants