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

Create tool to pin locally replaced modules to latest trunk commit #15290

Merged
merged 55 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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 Nov 15, 2024
8f5b382
Create tool to update certain module deps to pin to latest trunk commit
chainchad Nov 18, 2024
81968a8
Create new makefile target to use new tool to update module deps to pin
chainchad Nov 18, 2024
1a1d9d3
Add support for additional local module replacements
chainchad Nov 19, 2024
1e3811c
Add support for automatically updating locally replaced modules
chainchad Nov 19, 2024
cb70261
Update make target to auto update locally replaced modules
chainchad Nov 19, 2024
87e940f
Run go fmt
chainchad Nov 19, 2024
5b269ca
Add ci workflow
chainchad Nov 19, 2024
7165514
Add test for config sourcing
chainchad Nov 19, 2024
979b0c1
Add build step to CI
chainchad Nov 21, 2024
99ad50b
Make it gomods compatible and not a separate module
chainchad Nov 21, 2024
b5dc9fb
Remove mocked sys op
chainchad Nov 21, 2024
683ae99
Only build during dedicated CI workflow.
chainchad Nov 21, 2024
7358367
Refactor
chainchad Nov 22, 2024
e47bdd1
Remove unused function
chainchad Nov 22, 2024
eb28c01
Use psuedo version from go lib
chainchad Nov 22, 2024
9c22ee2
Upate pseudo-versions for local replaces to latest time/sha
chainchad Nov 22, 2024
dd2390c
Cleanup
chainchad Nov 22, 2024
b9dc91a
Update bin path
chainchad Nov 22, 2024
f8fbc9b
Fix README
chainchad Nov 22, 2024
bf12443
Allow custom org/repo name and apply better validation to git cmds
chainchad Nov 23, 2024
94a6f0f
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad Nov 23, 2024
da8130b
Address linting
chainchad Nov 24, 2024
c37c8f5
Address linting 2
chainchad Nov 24, 2024
5f60e09
Ignore gosec lint for execs
chainchad Nov 24, 2024
f17e56d
Update Make target name
chainchad Nov 25, 2024
b40b4f6
Avoid merge queue for build
chainchad Nov 25, 2024
6c6c8be
Rename tool
chainchad Nov 25, 2024
9ec395a
Point to new binary
chainchad Nov 25, 2024
1b44e1c
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad Nov 27, 2024
72c98a4
Remove unused lint directive
chainchad Nov 27, 2024
938baea
Ran goimports -local
chainchad Nov 27, 2024
a2b1834
Cleanup and refactor
chainchad Nov 29, 2024
daa12bc
Format
chainchad Nov 29, 2024
98cbd75
Update local requires
chainchad Nov 29, 2024
224281a
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad Nov 29, 2024
df62848
Add more refactoring
chainchad Nov 29, 2024
08dfe5d
Merge branch 're-3199/updater-root-module-go.mod-ref' of https://gith…
chainchad Nov 29, 2024
9af0d0c
Clarify readme
chainchad Nov 29, 2024
2f48978
Update comment
chainchad Nov 29, 2024
63638a7
Update README about usage and gomods
chainchad Dec 6, 2024
88c1b73
Add gomods as a dep for new target
chainchad Dec 6, 2024
941e003
Move pre-compiled regular expressions into vars
chainchad Dec 6, 2024
833427a
Fix formatting
chainchad Dec 6, 2024
1d9497a
Remove remnant from refactor
chainchad Dec 6, 2024
cbda2d1
Move validation of git input into config
chainchad Dec 6, 2024
b53cec3
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad Dec 6, 2024
b80bcfa
Run `make gomodslocalupdate`
chainchad Dec 6, 2024
89dd71b
Appease linter
chainchad Dec 7, 2024
25864d1
Remove unnecessary inline comments
chainchad Dec 7, 2024
4be3d94
Use a better name for git exec
chainchad Dec 9, 2024
d0740ce
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad Dec 10, 2024
ccf2842
Remove unnecessary build workflow
chainchad Dec 10, 2024
737c8db
Merge branch 're-3199/updater-root-module-go.mod-ref' of https://gith…
chainchad Dec 10, 2024
45efc1a
Merge branch 'develop' into re-3199/updater-root-module-go.mod-ref
chainchad Dec 10, 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 .github/workflows/ci-gomod-required-updater.yml
Copy link
Contributor

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?

Copy link
Collaborator Author

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?

Copy link
Contributor

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?

Copy link
Collaborator Author

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?

Copy link
Contributor

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

Copy link
Collaborator Author

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.

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
6 changes: 6 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 7 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ replace github.com/smartcontractkit/chainlink/v2 => ../../

replace github.com/smartcontractkit/chainlink/deployment => ../../deployment

// Using a separate `require` here to avoid surrounding line changes
// creating potential merge conflicts.
require (
github.com/smartcontractkit/chainlink/deployment v0.0.0-20241206210521-125d98cdaf66
github.com/smartcontractkit/chainlink/v2 v2.0.0-20241206210521-125d98cdaf66
)

require (
github.com/docker/docker v27.3.1+incompatible
github.com/docker/go-connections v0.5.0
Expand All @@ -27,8 +34,6 @@ require (
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-automation v0.8.1
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206011233-b6684ee6508f
github.com/smartcontractkit/chainlink/deployment v0.0.0-00010101000000-000000000000
github.com/smartcontractkit/chainlink/v2 v2.14.0-mercury-20240807.0.20241106193309-5560cd76211a
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
Expand Down
5 changes: 4 additions & 1 deletion deployment/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ toolchain go1.23.4
// Make sure we're working with the latest chainlink libs
replace github.com/smartcontractkit/chainlink/v2 => ../

// Using a separate inline `require` here to avoid surrounding line changes
// creating potential merge conflicts.
require github.com/smartcontractkit/chainlink/v2 v2.0.0-20241206210521-125d98cdaf66

require (
github.com/Khan/genqlient v0.7.0
github.com/Masterminds/semver/v3 v3.3.0
Expand All @@ -28,7 +32,6 @@ require (
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206011233-b6684ee6508f
github.com/smartcontractkit/chainlink-protos/job-distributor v0.6.0
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.13
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12
github.com/stretchr/testify v1.9.0
github.com/test-go/testify v1.1.4
Expand Down
9 changes: 7 additions & 2 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ replace github.com/smartcontractkit/chainlink/v2 => ../

replace github.com/smartcontractkit/chainlink/deployment => ../deployment

// Using a separate `require` here to avoid surrounding line changes
// creating potential merge conflicts.
require (
github.com/smartcontractkit/chainlink/deployment v0.0.0-20241206210521-125d98cdaf66
github.com/smartcontractkit/chainlink/v2 v2.0.0-20241206210521-125d98cdaf66
)

require (
dario.cat/mergo v1.0.1
github.com/AlekSi/pointer v1.1.0
Expand Down Expand Up @@ -48,8 +55,6 @@ require (
github.com/smartcontractkit/chainlink-testing-framework/lib/grafana v1.50.0
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.9
github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.2
github.com/smartcontractkit/chainlink/deployment v0.0.0-00010101000000-000000000000
github.com/smartcontractkit/chainlink/v2 v2.14.0-mercury-20240807.0.20241120195829-bd7a1943ad07
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
Expand Down
11 changes: 8 additions & 3 deletions integration-tests/load/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ replace github.com/smartcontractkit/chainlink/deployment => ../../deployment

replace github.com/smartcontractkit/chainlink/integration-tests => ../

// Using a separate `require` here to avoid surrounding line changes
// creating potential merge conflicts.
require (
github.com/smartcontractkit/chainlink/deployment v0.0.0-20241206210521-125d98cdaf66
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20241206210521-125d98cdaf66
github.com/smartcontractkit/chainlink/v2 v2.0.0-20241206210521-125d98cdaf66
)

require (
github.com/K-Phoen/grabana v0.22.2
github.com/ethereum/go-ethereum v1.14.11
Expand All @@ -23,9 +31,6 @@ require (
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.18
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.9
github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.2
github.com/smartcontractkit/chainlink/deployment v0.0.0-20241120141814-47da13e86197
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20241030133659-9ec788e78b4f
github.com/smartcontractkit/chainlink/v2 v2.14.0-mercury-20240807.0.20241120195829-bd7a1943ad07
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20241009055228-33d0c0bf38de
github.com/stretchr/testify v1.9.0
github.com/wiremock/go-wiremock v1.9.0
Expand Down
41 changes: 41 additions & 0 deletions tools/gomod-local-update/README.md
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
```
48 changes: 48 additions & 0 deletions tools/gomod-local-update/cmd/gomod-local-update/main.go
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)
}
}
69 changes: 69 additions & 0 deletions tools/gomod-local-update/internal/updater/config.go
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
}
Loading
Loading