golang.org/x/build@v0.0.0-20240506185731-218518f32b70/cmd/relnote/generate.go (about)

     1  // Copyright 2024 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  	"path/filepath"
    11  	"runtime"
    12  
    13  	"golang.org/x/build/relnote"
    14  	"rsc.io/markdown"
    15  )
    16  
    17  const prefixFormat = `---
    18  path: /doc/go1.%s
    19  template: false
    20  title: Go 1.%[1]s Release Notes
    21  ---
    22  
    23  `
    24  
    25  // generate takes the root of the Go repo.
    26  // It generates release notes by combining the fragments in the doc/next directory
    27  // of the repo.
    28  func generate(version, goRoot string) error {
    29  	if goRoot == "" {
    30  		goRoot = runtime.GOROOT()
    31  	}
    32  	dir := filepath.Join(goRoot, "doc", "next")
    33  	doc, err := relnote.Merge(os.DirFS(dir))
    34  	if err != nil {
    35  		return fmt.Errorf("merging %s: %v", dir, err)
    36  	}
    37  	out := markdown.ToMarkdown(doc)
    38  	out = fmt.Sprintf(prefixFormat, version) + out
    39  	outFile := fmt.Sprintf("go1.%s.md", version)
    40  	if err := os.WriteFile(outFile, []byte(out), 0644); err != nil {
    41  		return err
    42  	}
    43  	fmt.Printf("wrote %s\n", outFile)
    44  	return nil
    45  }