Skip to content

Commit

Permalink
chore: run dependabot on sundays (#1446)
Browse files Browse the repository at this point in the history
* chore: run dependabot monthly on Sundays

* chore: better assertions for dependabot generation

* chore: remove outdated if clause when generating modules

* fix: remove quotes

* fix: use os package instead of deprecared APIs in ioutil

* chore: properly autogenerate dependabot

* fix: update tests
  • Loading branch information
mdelapenya authored Aug 7, 2023
1 parent 4089912 commit 56cb52a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
39 changes: 33 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,158 +1,185 @@
# This file is autogenerated by the modulegen code generator. Please look at the generator code when updating it.
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: pip
directory: /
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/bigtable
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/cockroachdb
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/consul
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/datastore
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/firestore
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/mongodb
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/nats
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/nginx
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/pubsub
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/spanner
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/toxiproxy
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modulegen
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/compose
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/couchbase
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/k3s
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/localstack
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/mysql
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/neo4j
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/postgres
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/pulsar
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/redis
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/redpanda
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/vault
schedule:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: pip
directory: /
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
16 changes: 11 additions & 5 deletions modulegen/dependabot.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"

"gopkg.in/yaml.v3"
Expand All @@ -18,6 +18,7 @@ type DependabotConfig struct {

type Schedule struct {
Interval string `yaml:"interval"`
Day string `yaml:"day"`
}

type Update struct {
Expand All @@ -36,6 +37,7 @@ func NewUpdate(example Example) Update {
RebaseStrategy: "disabled",
Schedule: Schedule{
Interval: updateSchedule,
Day: "sunday",
},
}
}
Expand All @@ -54,8 +56,8 @@ func (u Updates) Len() int {
// while Stable preserves the original input order of equal elements.
//
// Less must describe a transitive ordering:
// - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
// - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
// - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
// - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
//
// Note that floating-point comparison (the < operator on float32 or float64 values)
// is not a transitive ordering when not-a-number (NaN) values are involved.
Expand Down Expand Up @@ -90,7 +92,7 @@ func getDependabotUpdates() ([]Update, error) {
func readDependabotConfig(rootDir string) (*DependabotConfig, error) {
configFile := getDependabotConfigFile(rootDir)

file, err := ioutil.ReadFile(configFile)
file, err := os.ReadFile(configFile)
if err != nil {
return nil, err
}
Expand All @@ -113,5 +115,9 @@ func writeDependabotConfig(rootDir string, config *DependabotConfig) error {

file := getDependabotConfigFile(rootDir)

return ioutil.WriteFile(file, data, 0777)
header := "# This file is autogenerated by the modulegen code generator. Please look at the generator code when updating it.\n"

data = append([]byte(header), data...)

return os.WriteFile(file, data, 0777)
}
2 changes: 1 addition & 1 deletion modulegen/dependabot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestExamplesHasDependabotEntry(t *testing.T) {
exampleUpdates := []Update{}
// exclude the Go modules from the examples updates
for _, update := range dependabotUpdates {
if update.Directory == "/" || update.Directory == "/modulegen" || strings.HasPrefix(update.Directory, "/modules") {
if update.PackageEcosystem != "gomod" || update.Directory == "/" || update.Directory == "/modulegen" || strings.HasPrefix(update.Directory, "/modules") {
continue
}
exampleUpdates = append(exampleUpdates, update)
Expand Down
14 changes: 6 additions & 8 deletions modulegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,6 @@ func generate(example Example, rootDir string) error {
Modules: modulesList,
}
}
} else if strings.EqualFold(tmpl, "tools.go") {
// tools.go example file will go into the tools package
exampleFilePath = filepath.Join(outputDir, exampleLower, "tools", tmpl)
} else {
exampleFilePath = filepath.Join(outputDir, exampleLower, strings.ReplaceAll(tmpl, "example", exampleLower))
}
Expand Down Expand Up @@ -285,13 +282,13 @@ func generateDependabotUpdates(rootDir string, example Example) error {

dependabotExampleUpdates := dependabotConfig.Updates

// make sure the main module is the first element in the list of examples
exampleUpdates := make(Updates, len(dependabotExampleUpdates)-1)
// make sure GH actions, Pip and the core module are the three first elements in the list of examples
exampleUpdates := make(Updates, len(dependabotExampleUpdates)-3)
j := 0

for _, exampleUpdate := range dependabotExampleUpdates {
// filter out the root module
if exampleUpdate.Directory != "/" {
if exampleUpdate.PackageEcosystem == "gomod" && exampleUpdate.Directory != "/" {
exampleUpdates[j] = exampleUpdate
j++
}
Expand All @@ -300,8 +297,9 @@ func generateDependabotUpdates(rootDir string, example Example) error {
exampleUpdates = append(exampleUpdates, NewUpdate(example))
sort.Sort(exampleUpdates)

// prepend the main and compose modules
exampleUpdates = append([]Update{dependabotExampleUpdates[0]}, exampleUpdates...)
// prepend the github actions, pip and main modules
firstUpdates := dependabotExampleUpdates[0:3]
exampleUpdates = append(firstUpdates, exampleUpdates...)

dependabotConfig.Updates = exampleUpdates

Expand Down
11 changes: 10 additions & 1 deletion modulegen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,17 @@ func assertDependabotExamplesUpdates(t *testing.T, example Example, originalConf

assert.True(t, found)

// first item is the main module
// first item is the github-actions module
assert.Equal(t, "/", examples[0].Directory, examples)
assert.Equal(t, "github-actions", examples[0].PackageEcosystem, "PackageEcosystem should be github-actions")

// second item is the core module
assert.Equal(t, "/", examples[1].Directory, examples)
assert.Equal(t, "pip", examples[1].PackageEcosystem, "PackageEcosystem should be pip")

// third item is the core module
assert.Equal(t, "/", examples[2].Directory, examples)
assert.Equal(t, "gomod", examples[2].PackageEcosystem, "PackageEcosystem should be gomod")
}

// assert content example file in the docs
Expand Down
5 changes: 2 additions & 3 deletions modulegen/mkdocs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -80,7 +79,7 @@ func getRootDir() (string, error) {
func readMkdocsConfig(rootDir string) (*MkDocsConfig, error) {
configFile := getMkdocsConfigFile(rootDir)

file, err := ioutil.ReadFile(configFile)
file, err := os.ReadFile(configFile)
if err != nil {
return nil, err
}
Expand All @@ -103,5 +102,5 @@ func writeMkdocsConfig(rootDir string, config *MkDocsConfig) error {

file := getMkdocsConfigFile(rootDir)

return ioutil.WriteFile(file, data, 0777)
return os.WriteFile(file, data, 0777)
}

0 comments on commit 56cb52a

Please sign in to comment.