-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Create tool to pin locally replaced modules to latest trunk commit #15290
Merged
Merged
Changes from 48 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
8192867
Add separate require line for root module.
chainchad 8f5b382
Create tool to update certain module deps to pin to latest trunk commit
chainchad 81968a8
Create new makefile target to use new tool to update module deps to pin
chainchad 1a1d9d3
Add support for additional local module replacements
chainchad 1e3811c
Add support for automatically updating locally replaced modules
chainchad cb70261
Update make target to auto update locally replaced modules
chainchad 87e940f
Run go fmt
chainchad 5b269ca
Add ci workflow
chainchad 7165514
Add test for config sourcing
chainchad 979b0c1
Add build step to CI
chainchad 99ad50b
Make it gomods compatible and not a separate module
chainchad b5dc9fb
Remove mocked sys op
chainchad 683ae99
Only build during dedicated CI workflow.
chainchad 7358367
Refactor
chainchad e47bdd1
Remove unused function
chainchad eb28c01
Use psuedo version from go lib
chainchad 9c22ee2
Upate pseudo-versions for local replaces to latest time/sha
chainchad dd2390c
Cleanup
chainchad b9dc91a
Update bin path
chainchad f8fbc9b
Fix README
chainchad bf12443
Allow custom org/repo name and apply better validation to git cmds
chainchad 94a6f0f
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad da8130b
Address linting
chainchad c37c8f5
Address linting 2
chainchad 5f60e09
Ignore gosec lint for execs
chainchad f17e56d
Update Make target name
chainchad b40b4f6
Avoid merge queue for build
chainchad 6c6c8be
Rename tool
chainchad 9ec395a
Point to new binary
chainchad 1b44e1c
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad 72c98a4
Remove unused lint directive
chainchad 938baea
Ran goimports -local
chainchad a2b1834
Cleanup and refactor
chainchad daa12bc
Format
chainchad 98cbd75
Update local requires
chainchad 224281a
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad df62848
Add more refactoring
chainchad 08dfe5d
Merge branch 're-3199/updater-root-module-go.mod-ref' of https://gith…
chainchad 9af0d0c
Clarify readme
chainchad 2f48978
Update comment
chainchad 63638a7
Update README about usage and gomods
chainchad 88c1b73
Add gomods as a dep for new target
chainchad 941e003
Move pre-compiled regular expressions into vars
chainchad 833427a
Fix formatting
chainchad 1d9497a
Remove remnant from refactor
chainchad cbda2d1
Move validation of git input into config
chainchad b53cec3
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad b80bcfa
Run `make gomodslocalupdate`
chainchad 89dd71b
Appease linter
chainchad 25864d1
Remove unnecessary inline comments
chainchad 4be3d94
Use a better name for git exec
chainchad d0740ce
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad ccf2842
Remove unnecessary build workflow
chainchad 737c8db
Merge branch 're-3199/updater-root-module-go.mod-ref' of https://gith…
chainchad 45efc1a
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: gomod-local-update | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Setup Go | ||
uses: ./.github/actions/setup-go | ||
- name: Build binary | ||
run: | | ||
go build -o dist/gomod-local-update \ | ||
./tools/gomod-local-update/cmd/gomod-local-update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,12 @@ presubmit: ## Format go files and imports. | |
gomods: ## Install gomods | ||
go install github.com/jmank88/[email protected] | ||
|
||
.PHONY: gomodslocalupdate | ||
gomodslocalupdate: gomods ## Run gomod-local-update | ||
go install ./tools/gomod-local-update/cmd/gomod-local-update | ||
gomods -w gomod-local-update | ||
gomods tidy | ||
|
||
.PHONY: mockery | ||
mockery: $(mockery) ## Install mockery. | ||
go install github.com/vektra/mockery/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# gomod-local-update | ||
erikburt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Updates any module that is `replace`'d with a local path to have its required module version in `go.mod` to match the latest git SHA from a remote branch. | ||
|
||
Is meant to run within each directory where a `go.mod` file is present. | ||
|
||
## Configuration | ||
|
||
Command Line Flags: | ||
|
||
```shell | ||
Optional: | ||
-org-name Organization name (default: smartcontractkit) | ||
-repo-name Repository name (default: chainlink) | ||
-repo-remote Git remote to use (default: origin) | ||
-branch-trunk Branch to get SHA from (default: develop) | ||
-dry-run Preview changes without applying them (default: false) | ||
``` | ||
|
||
## Installation | ||
|
||
The installed binary will be placed in your `$GOPATH/bin` directory. Make sure this directory is in your system's PATH to run the command from anywhere. From the root of this repository, run: | ||
|
||
```shell | ||
go install ./tools/gomod-local-update/cmd/gomod-local-update | ||
``` | ||
|
||
## Usage Examples | ||
|
||
Run from the root of a go module directory. | ||
|
||
```shell | ||
gomod-local-update | ||
``` | ||
|
||
Was designed to be used with [gomods](https://github.com/jmank88/gomods) like: | ||
|
||
```shell | ||
gomods -w gomod-local-update | ||
gomods tidy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/tools/gomod-local-update/internal/updater" | ||
) | ||
|
||
const ( | ||
goBinaryName = "gomod-local-update" | ||
) | ||
|
||
var version = "dev" | ||
var usage = fmt.Sprintf(`%s version %%s | ||
|
||
Usage: | ||
cd /path/to/go/module | ||
%s [flags] | ||
`, goBinaryName, goBinaryName) | ||
|
||
func main() { | ||
cfg, err := updater.ParseFlags(os.Args[1:], version) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, usage, version) | ||
log.Fatal(err) | ||
} | ||
|
||
if cfg.ShowVersion { | ||
fmt.Printf("%s version %s\n", goBinaryName, version) | ||
os.Exit(0) | ||
} | ||
|
||
if err := cfg.Validate(); err != nil { | ||
fmt.Fprintf(os.Stderr, usage, version) | ||
log.Fatal(err) | ||
} | ||
|
||
u := updater.New( | ||
cfg, | ||
updater.NewSystemOperator(), | ||
) | ||
|
||
if err := u.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package updater | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
) | ||
|
||
const ( | ||
DefaultRepoRemote = "origin" | ||
DefaultBranchTrunk = "develop" | ||
DefaultOrgName = "smartcontractkit" | ||
DefaultRepoName = "chainlink" | ||
) | ||
|
||
type Config struct { | ||
RepoRemote string | ||
BranchTrunk string | ||
DryRun bool | ||
ShowVersion bool | ||
OrgName string | ||
RepoName string | ||
} | ||
|
||
func ParseFlags(args []string, version string) (*Config, error) { | ||
flags := flag.NewFlagSet("default", flag.ContinueOnError) | ||
|
||
cfg := &Config{} | ||
|
||
flags.StringVar(&cfg.RepoRemote, "repo-remote", DefaultRepoRemote, "Git remote to use") | ||
flags.StringVar(&cfg.BranchTrunk, "branch-trunk", DefaultBranchTrunk, "Branch to get SHA from") | ||
flags.BoolVar(&cfg.DryRun, "dry-run", false, "Preview changes without applying them") | ||
flags.BoolVar(&cfg.ShowVersion, "version", false, "Show version information") | ||
flags.StringVar(&cfg.OrgName, "org-name", DefaultOrgName, "GitHub organization name") | ||
flags.StringVar(&cfg.RepoName, "repo-name", DefaultRepoName, "GitHub repository name") | ||
|
||
if err := flags.Parse(args); err != nil { | ||
return nil, err | ||
} | ||
|
||
return cfg, nil | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
if c.ShowVersion { | ||
return nil | ||
} | ||
|
||
if c.OrgName == "" { | ||
return fmt.Errorf("%w: org name must be provided", ErrInvalidConfig) | ||
} | ||
if c.RepoName == "" { | ||
return fmt.Errorf("%w: repo name must be provided", ErrInvalidConfig) | ||
} | ||
if c.RepoRemote == "" { | ||
return fmt.Errorf("%w: repo remote must be provided", ErrInvalidConfig) | ||
} | ||
if c.BranchTrunk == "" { | ||
return fmt.Errorf("%w: trunk branch must be provided", ErrInvalidConfig) | ||
} | ||
|
||
if !gitRemoteRE.MatchString(c.RepoRemote) { | ||
return fmt.Errorf("%w: git remote '%s' contains invalid characters", ErrInvalidConfig, c.RepoRemote) | ||
} | ||
if !gitBranchRE.MatchString(c.BranchTrunk) { | ||
return fmt.Errorf("%w: git branch '%s' contains invalid characters", ErrInvalidConfig, c.BranchTrunk) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this separate workflow necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, it's pretty sparse right now. Would love to remove it. Would you suggest just throwing this as a step in
ci-core.yml
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the make command already installs so what effect is this build meant to have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal would be to ensure that the build doesn't break but maybe unnecessary or it gets built in another way that I'm not aware of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should already be covered by the normal CI as part of the root module. I.e. there should be a line for this package in the ci core test output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, removed in ccf2842.