-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create tool to pin locally replaced modules to latest trunk commit (#…
…15290) * Add separate require line for root module. Separating it to avoid potential merge conflicts when surrounding lines change as we expect CI to update its psuedo version. * Create tool to update certain module deps to pin to latest trunk commit * Create new makefile target to use new tool to update module deps to pin * Add support for additional local module replacements * Add support for automatically updating locally replaced modules * Update make target to auto update locally replaced modules * Run go fmt * Add ci workflow * Add test for config sourcing * Add build step to CI * Make it gomods compatible and not a separate module * Remove mocked sys op * Only build during dedicated CI workflow. Tests and linting should now be ran from the ci-core workflow. * Refactor * Remove unused function * Use psuedo version from go lib * Upate pseudo-versions for local replaces to latest time/sha * Cleanup * Update bin path * Fix README * Allow custom org/repo name and apply better validation to git cmds * Address linting * Address linting 2 * Ignore gosec lint for execs * Update Make target name * Avoid merge queue for build * Rename tool * Point to new binary * Remove unused lint directive * Ran goimports -local * Cleanup and refactor * Format * Update local requires * Add more refactoring * Clarify readme * Update comment * Update README about usage and gomods * Add gomods as a dep for new target Co-authored-by: Jordan Krage <jmank88@gmail.com> * Move pre-compiled regular expressions into vars * Fix formatting * Remove remnant from refactor * Move validation of git input into config * Run `make gomodslocalupdate` * Appease linter * Remove unnecessary inline comments * Use a better name for git exec * Remove unnecessary build workflow --------- Co-authored-by: Jordan Krage <jmank88@gmail.com>
- Loading branch information
Showing
13 changed files
with
985 additions
and
8 deletions.
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
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 | ||
|
||
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.