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

retry change detection #598

Merged
merged 26 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions .github/workflows/fail-on-needs-generate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI

on:
pull_request:
types: [ labeled ]

jobs:
build:
if: ${{ contains( github.event.label.name, 'needs-go-generate') }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Fail on needs-go-generate
run: echo Failed, needs go generate. && exit 1
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ jobs:
# see: https://www.reddit.com/r/golang/comments/476pae/how_to_speed_up_go_compiler_and_many_other_go/
env:
GOGC: 2000
GOMEMLIMIT: 6GiB

#note: right now this is not run against all work dirs
lint:
Expand Down
1 change: 1 addition & 0 deletions Makefile
1 change: 1 addition & 0 deletions agents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/coinbase/rosetta-sdk-go v0.8.1
github.com/davecgh/go-spew v1.1.1
github.com/ethereum/go-ethereum v1.10.26
github.com/hedzr/log v1.6.3
Copy link
Contributor

Choose a reason for hiding this comment

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

I spent so much time on this :-)

github.com/ipfs/go-log v1.0.5
github.com/jftuga/ellipsis v1.0.0
github.com/jftuga/termsize v1.0.2
Expand Down
3 changes: 3 additions & 0 deletions agents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
github.com/hdevalence/ed25519consensus v0.0.0-20201207055737-7fde80a9d5ff/go.mod h1:Feit0l8NcNO4g69XNjwvsR0LGcwMMfzI1TF253rOIlQ=
github.com/hedzr/log v1.6.3 h1:qCdnDUpeQ+E9vmfDKk+IHjA0QipnWNds2mr4hh6iGxA=
github.com/hedzr/log v1.6.3/go.mod h1:goMXeVWLSKZYxNs+10viGe2O1fbzBNnnLpdx0MoCRkA=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
Expand Down Expand Up @@ -1901,6 +1903,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/hedzr/errors.v3 v3.1.1/go.mod h1:UwtyepqtGTIAmdZGSc7wxXT5Gfd/BjcfRMhPpxwkJM4=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI=
Expand Down
35 changes: 24 additions & 11 deletions contrib/git-changes-action/detector/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"strings"

"github.com/avast/retry-go"
"github.com/google/go-github/v41/github"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/actionscore"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/tree"
"golang.org/x/exp/slices"
"golang.org/x/oauth2"
"os"
"strings"
"time"
)

// GetChangeTree returns the ref for the given event name.
Expand Down Expand Up @@ -64,15 +65,27 @@ func getChangedFilesFromAPI(ctx context.Context, ghContext *actionscore.Context,
ct = tree.NewTree()

page := 1
perPage := 20
const retryCount = 10
const perPage = 100
for {
files, res, err := client.PullRequests.ListFiles(ctx, repoOwner, repoName, prNumber, &github.ListOptions{
Page: page,
PerPage: perPage,
})
var files []*github.CommitFile
var res *github.Response
err = retry.Do(func() error {
reqCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()

files, res, err = client.PullRequests.ListFiles(reqCtx, repoOwner, repoName, prNumber, &github.ListOptions{
Page: page,
PerPage: perPage,
})
if err != nil {
return fmt.Errorf("could not get files for repoOwner %s, repoName %s, prNumber %d, page number %d with page size %d: %w",
repoOwner, repoName, prNumber, page, perPage, err)
}
return nil
}, retry.Context(ctx), retry.Attempts(retryCount))
if err != nil {
return nil, fmt.Errorf("could not get files for repoOwner %s, repoName %s, prNumber %d, page number %d with page size %d: %w",
repoOwner, repoName, prNumber, page, perPage, err)
return nil, fmt.Errorf("could not get files after %d retries: %w", retryCount, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe include the information I had in my log about the page number and repoName and prNumber and repoOwner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done and wrapped above

}

for _, file := range files {
Expand All @@ -84,7 +97,7 @@ func getChangedFilesFromAPI(ctx context.Context, ghContext *actionscore.Context,
}
}

if page == res.LastPage {
if res.NextPage == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure this will work? Keeping it res.LastPage worked for me in the messaging branch that had multiple pages.

Copy link
Contributor Author

@trajan0x trajan0x Mar 7, 2023

Choose a reason for hiding this comment

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

image

I ran it w/ a fmt.Println and you can see the last page detection not working here https://github.com/synapsecns/sanguine/actions/runs/4309209034/jobs/7516328981

It'd get to 12 and then reset to 1. res.LastPage can be 0 when the cursor is lost

break
}

Expand Down
1 change: 1 addition & 0 deletions contrib/git-changes-action/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ replace (

require (
github.com/Flaque/filet v0.0.0-20201012163910-45f684403088
github.com/avast/retry-go v3.0.0+incompatible
github.com/brianvoe/gofakeit/v6 v6.20.1
github.com/ethereum/go-ethereum v1.10.26
github.com/go-git/go-git/v5 v5.5.2
Expand Down
2 changes: 2 additions & 0 deletions contrib/git-changes-action/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/brianvoe/gofakeit/v6 v6.20.1 h1:8ihJ60OvPnPJ2W6wZR7M+TTeaZ9bml0z6oy4gvyJ/ek=
github.com/brianvoe/gofakeit/v6 v6.20.1/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8=
Expand Down
Loading