{"id":16895851,"url":"https://github.com/stevenacoffman/monotidy","last_synced_at":"2025-04-11T06:31:03.936Z","repository":{"id":147330192,"uuid":"393781195","full_name":"StevenACoffman/monotidy","owner":"StevenACoffman","description":"go mod tidy, but for multi-module monorepos via mad science","archived":false,"fork":false,"pushed_at":"2021-09-13T20:56:46.000Z","size":17,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T16:23:20.737Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StevenACoffman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-07T20:04:15.000Z","updated_at":"2021-10-21T04:03:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"d78c9b79-2add-4759-8927-8c657f68ce4b","html_url":"https://github.com/StevenACoffman/monotidy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StevenACoffman%2Fmonotidy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StevenACoffman%2Fmonotidy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StevenACoffman%2Fmonotidy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StevenACoffman%2Fmonotidy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StevenACoffman","download_url":"https://codeload.github.com/StevenACoffman/monotidy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248355644,"owners_count":21090063,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T17:26:34.444Z","updated_at":"2025-04-11T06:31:03.911Z","avatar_url":"https://github.com/StevenACoffman.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### monotidy\ngo mod tidy, but for multi-module monorepos\n\n### Why?\n\nIn a multi-module monorepo, when dependabot updates a shared lib's `go.mod`, this also invalidates the `go.sum` of all the dependent applications in the same repo (if they use a replace directive for the local relative path), so then `go mod verify` will fail for those dependents, breaking the build without manual intervention.\n\nIdeally, when we update a shared library directory, we would then run `go mod tidy` on all the dependent (e.g. application) modules, and commit back the changed `go.sum` files.\n\nThis can be done with a dumb little bash script:\n```shell\n #!/bin/bash\n\n # uncommenting below will update all the go modules, and show you if the go.mod is targetting\n # old go versions. Requires go-mod-upgrade\n\nfunction is_bin_in_path {\n  builtin type -P \"$1\" \u0026\u003e /dev/null\n}\n\nfunction modupdate {\n    for D in */; do\n        if [ -f \"${D}go.mod\" ]; then\n            echo -e \"\\033[32m\\xE2\\x9c\\x93 Updating modules for ${D}\\n\\n\\033[0m\"\n            rm \"./${D}go.sum\"\n            # cat \"./${D}go.mod\" | grep 'go 1.' # list go version\n            cd \"${D}\"\n            #go get -u all\n            # ! is_bin_in_path go-mod-upgrade \u0026\u0026 go get -u github.com/oligot/go-mod-upgrade\n            #is_bin_in_path go-mod-upgrade \u0026\u0026 go-mod-upgrade\n            go mod tidy\n            # go mod download\n            # go mod verify\n            # go vet ./...\n            cd ..\n        fi\n    done\n}\n```\n\nHowever, that assumes we have a whole unix environment and Golang dev tools, which bloats the size of any CI container and slows down the whole process.\n\nI want juuuuuust `go mod tidy`, but from a root directory on all `go.mod` file containing subdirectories, so I can make a static binary to shove in a scratch container.\n\nLuckily, github's dependabot helpfully scrapes and copies the go tools internal packages and renames them so they are re-usable, so I _can_ reuse them!\n\nThen, I can just hook dependabot up to THIS repo, and it will maintain itself. Muhahahahaha!\n\n_insert further mad science here_","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenacoffman%2Fmonotidy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenacoffman%2Fmonotidy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenacoffman%2Fmonotidy/lists"}