-
Notifications
You must be signed in to change notification settings - Fork 6
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
Centralize upstream sync infrastructure to the go-infra respository #9
Conversation
81f39b7
to
62117f4
Compare
@microsoft/golang-compiler PTAL, this will start us syncing the Docker repo from upstream automatically. |
62117f4
to
d1758c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- An empty
eng/go.mod
has been added to the repo, is it necessary? If it is, add at least the module name to it so it becomes a valid mod file. - I would replace raw
panic
calls with log.Panic so the error message is logged in the cmd output. Using log.Fatal is also tempting, but deferred functions won't be called as it exists the program directly so the temporary directories won't be cleaned up.
buildmodel/commands.go
Outdated
// sortable path-friendly name to use as the name. This allows a command to run multiple times in | ||
// sequence without overwriting or deleting the old data, for diagnostic purposes. This is intended | ||
// as a dev convenience, not to enable running in parallel. | ||
func GetTempPathInDir(rootDir string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functions could be simplified by using os.MkdirTemp.
func GetTempPathInDir(rootDir string) (string, error) {
pathDate := time.Now().Format("2006-01-02_15-04-05.000")
return os.MkdirTemp(rootDir, fmt.Sprintf("%s_*", pathDate))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes it safer overall, too, since it actually guarantees it won't pick the same directory. Can also remove some of the timestamp's precision since it's only useful for manually poking through these directories at that point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think to test this change in a clean environment, and it ended up failing in the pipeline:
stat /home/vsts/work/1/s/eng/artifacts/sync-upstream-temp-repo: no such file or directory
I think it's because MkdirTemp
actually tries to create the directory, but at this point, the parent directory doesn't exist yet. It used to be that git init {temp path}
was the first place the result of this func gets used, and git handles creating parent directories if necessary. MkdirTemp
doesn't seem to.
My initial plan to fix it is to try to find a simple way to create any necessary chain of parent directories in Go. Working on it....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry, the reasoning is in the commit message:
Maybe adding a comment would work for discoverability--upstream just recommends the empty file so I went with that:
Interesting, I'll have to try that. The errors have been showing up in the output for me, so will be interesting to see how this is different. I guess that if the panic is recovered, this makes the error show up anyway? |
Yep, a comment explaining the reasoning would be great.
You are right, the error is printed before throwing a panic. In addition, the error message will be logged to the output specified by log.SetOutput -defaults to stderr- and any flag and prefix configured will also by applied. Probably not relevant for this repo, but a good practice anyway 😄. |
Add template for microsoft-golang-bot "git config" and Go toolset init. Update to 1.17.2. Place empty go.mod in eng to ignore artifacts dir. Use "os.MkdirTemp" for "GetWorkPathInDir" func. Use "log.Panic" instead of "panic".
d1758c9
to
10543eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing!
This PR:
eng/sync-config.json
to control the sync process.microsoft
GitHub org.The first commit copies over the
cmd/sync/sync.go
file. The second commit does everything else. I recommend reviewing the second commit to see what changed with the switch to a centralized script that reuses existing code.Example build: https://dev.azure.com/dnceng/internal/_build/results?buildId=1449982. It submitted PRs that looked fine and passed CI:
master
intomicrosoft/main
go#247release-branch.go1.16
intomicrosoft/release-branch.go1.16
go#248release-branch.go1.17
intomicrosoft/release-branch.go1.17
go#249master
intomicrosoft/main
go-images#17On the Docker auto-update side, I ran it on my repo multiple times to make sure it still behaves the same and updates existing PRs properly: