Skip to content

Instantly share code, notes, and snippets.

@andrewtj
Created February 22, 2016 08:21
Show Gist options
  • Save andrewtj/fe8feae87427f3b4c592 to your computer and use it in GitHub Desktop.
Save andrewtj/fe8feae87427f3b4c592 to your computer and use it in GitHub Desktop.
go dns breaking change sketch
// +build ignore
package main
import (
"bytes"
"fmt"
"os"
"os/exec"
)
func Must(a ...interface{}) {
switch err := a[len(a)-1].(type) {
case nil:
case error:
panic(err)
default:
panic("unreachable")
}
}
func main() {
// Note: hash_start depends on prettyfmt
prettyfmt := `%w(0)
%h %cd %s
Commit: https://github.com/miekg/dns/commit/%h
Issues: https://github.com/miekg/dns/search?q=%h&type=Issues
%w(72,0,4)%b%w(0)
`
hash_start := 5
cmd := exec.Command("git", "log", "--grep=#breaking", "--date=short", "--pretty="+prettyfmt)
var buf bytes.Buffer
cmd.Stdout = &buf
Must(cmd.Run())
stdout := buf.Bytes()
file, err := os.Create("zbreaking.go")
Must(err)
Must(fmt.Fprint(file, "//go:generate go run breaking_generate.go\n\n"))
if len(stdout) == 0 {
Must(fmt.Fprint(file, "package dns\n"))
return
}
Must(fmt.Fprintf(file, `/*
Breaking Changes
On rare occasions a breaking change may be introduced to fix a bug or flaw.
As of 22 February 2016 commits introducing breaking changes are tagged
#breaking and the commit hash of the the last breaking change is exported
as the constant LastBreakingChange.
Full list of breaking commits:
%s
*/
package dns
// LastBreakingChange is the short hash of the commit that introduced the last breaking change.
const LastBreakingChange string = "%s"
`, stdout, stdout[hash_start:hash_start+7]))
}
//go:generate go run breaking_generate.go
package dns
@miekg
Copy link

miekg commented Feb 23, 2016

The above looks nice. I wonder, if we should just hold up all breaking changes and then make one release that breaks. I mean just telling there are breaking changes is only one side of the equation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment