...

Source file src/github.com/opencontainers/image-spec/.tool/genheader.go

Documentation: github.com/opencontainers/image-spec/.tool

     1  // Copyright 2017 The Linux Foundation
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"bytes"
    19  	"fmt"
    20  	"os"
    21  	"os/exec"
    22  	"strings"
    23  	"text/template"
    24  
    25  	specs "github.com/opencontainers/image-spec/specs-go"
    26  )
    27  
    28  var headerTemplate = template.Must(template.New("gen").Parse(`<title>image-spec {{.Version}}</title>
    29  <base href="https://raw.githubusercontent.com/opencontainers/image-spec/{{.Branch}}/">`))
    30  
    31  type Obj struct {
    32  	Version string
    33  	Branch  string
    34  }
    35  
    36  func main() {
    37  	obj := Obj{
    38  		Version: specs.Version,
    39  		Branch:  specs.Version,
    40  	}
    41  	if strings.HasSuffix(specs.Version, "-dev") {
    42  		cmd := exec.Command("git", "log", "-1", `--pretty=%H`, "HEAD")
    43  		var out bytes.Buffer
    44  		cmd.Stdout = &out
    45  		cmd.Stderr = os.Stderr
    46  		if err := cmd.Run(); err != nil {
    47  			fmt.Fprintln(os.Stderr, err)
    48  			os.Exit(1)
    49  		}
    50  
    51  		obj.Branch = strings.Trim(out.String(), " \n\r")
    52  	}
    53  	headerTemplate.Execute(os.Stdout, obj)
    54  }
    55  

View as plain text