Skip to content

Commit

Permalink
Merge pull request #172 from asalvi0/improve-updater
Browse files Browse the repository at this point in the history
Improve updater and Go -> 1.20
  • Loading branch information
smacker authored Aug 27, 2024
2 parents a85ceeb + 30107c6 commit dd81d9e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.22', '1.21', '1.20', '1.19']
go: ['1.23', '1.22', '1.21', '1.20']
name: Test on ${{ matrix.go }}
steps:
- uses: actions/checkout@v4
Expand Down
28 changes: 10 additions & 18 deletions _automation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func root(args []string) error {
flagsParse(fs, args[1:])

s.CheckUpdates(ctx)

case "update":
if len(args) < 2 {
return fmt.Errorf("language argument is missing")
Expand All @@ -91,11 +92,15 @@ func root(args []string) error {
flagsParse(fs, args[2:])

s.Update(ctx, args[1], *force)
s.writeGrammarsFile(ctx)

case "update-all":
fs := flag.NewFlagSet("update-all", flag.ExitOnError)
flagsParse(fs, args[1:])

s.UpdateAll(ctx)
s.UpdateAll(ctx, true)
s.writeGrammarsFile(ctx)

default:
return fmt.Errorf("unknown sub-command")
}
Expand Down Expand Up @@ -194,33 +199,20 @@ func (s *UpdateService) Update(ctx context.Context, language string, force bool)
}

s.downloadGrammar(ctx, grammar)
s.writeGrammarsFile(ctx)
}

func (s *UpdateService) UpdateAll(ctx context.Context) {
newVersions := s.fetchNewVersions()

func (s *UpdateService) UpdateAll(ctx context.Context, force bool) {
wg := sync.WaitGroup{}
for i, g := range s.grammars {
v := newVersions[i]
if v == nil {
continue
}

for _, g := range s.grammars {
wg.Add(1)
g.Reference = v.Reference
g.Revision = v.Revision

go func(g *Grammar) {
defer wg.Done()

s.downloadGrammar(ctx, g)
s.Update(ctx, g.Language, force)
}(g)
}

wg.Wait()

s.writeGrammarsFile(ctx)
}

func (s *UpdateService) downloadGrammar(ctx context.Context, g *Grammar) {
Expand Down Expand Up @@ -310,7 +302,7 @@ func (s *UpdateService) fetchFile(ctx context.Context, url string) []byte {
defer resp.Body.Close()

if resp.StatusCode != 200 {
logAndExit(logger, "incorrect response status code", "statusCode", resp.StatusCode)
logger.Error("incorrect response status code", "statusCode", resp.StatusCode)
}

b, err := io.ReadAll(resp.Body)
Expand Down
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module github.com/smacker/go-tree-sitter

go 1.13
go 1.20

require github.com/stretchr/testify v1.7.4
require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 2 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM=
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit dd81d9e

Please sign in to comment.