From fec31f445e0caf2fb75b44cab38d67284ceedf43 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Tue, 31 Jan 2017 10:19:55 -0500 Subject: [PATCH] docs: image base reference Fixes #247 this makes an ephemeral header that gets included into the html doc that bases the images path to pull from the same tag on github. Signed-off-by: Vincent Batts --- .gitignore | 1 + .tool/genheader.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 15 +++++++------ 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 .tool/genheader.go diff --git a/.gitignore b/.gitignore index 7d00975..dcc5d55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /oci-validate-examples output +header.html diff --git a/.tool/genheader.go b/.tool/genheader.go new file mode 100644 index 0000000..6d1e176 --- /dev/null +++ b/.tool/genheader.go @@ -0,0 +1,54 @@ +// Copyright 2017 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "bytes" + "fmt" + "os" + "os/exec" + "strings" + "text/template" + + specs "github.com/opencontainers/image-spec/specs-go" +) + +var headerTemplate = template.Must(template.New("gen").Parse(`image-spec {{.Version}} +`)) + +type Obj struct { + Version string + Branch string +} + +func main() { + obj := Obj{ + Version: specs.Version, + Branch: specs.Version, + } + if strings.HasSuffix(specs.Version, "-dev") { + cmd := exec.Command("git", "log", "-1", `--pretty=%H`, "HEAD") + var out bytes.Buffer + cmd.Stdout = &out + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + obj.Branch = strings.Trim(out.String(), " \n\r") + } + headerTemplate.Execute(os.Stdout, obj) +} diff --git a/Makefile b/Makefile index 56cd1af..b69329c 100644 --- a/Makefile +++ b/Makefile @@ -68,13 +68,16 @@ $(OUTPUT_DIRNAME)/$(DOC_FILENAME).pdf: $(DOC_FILES) $(FIGURE_FILES) $(PANDOC) -f markdown_github -t latex --latex-engine=xelatex -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES)) ls -sh $(shell readlink -f $@) -$(OUTPUT_DIRNAME)/$(DOC_FILENAME).html: $(DOC_FILES) $(FIGURE_FILES) +$(OUTPUT_DIRNAME)/$(DOC_FILENAME).html: header.html $(DOC_FILES) $(FIGURE_FILES) @mkdir -p $(OUTPUT_DIRNAME)/ && \ cp -ap img/ $(shell pwd)/$(OUTPUT_DIRNAME)/&& \ - $(PANDOC) -f markdown_github -t html5 -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES)) + $(PANDOC) -f markdown_github -t html5 -H $(PANDOC_SRC)/header.html --standalone -o $(PANDOC_DST)$@ $(patsubst %,$(PANDOC_SRC)%,$(DOC_FILES)) ls -sh $(shell readlink -f $@) endif +header.html: .tool/genheader.go specs-go/version.go + go run .tool/genheader.go > $@ + validate-examples: schema/fs.go go test -run TestValidate ./schema @@ -98,7 +101,6 @@ test: schema/fs.go img/%.png: img/%.dot dot -Tpng $^ > $@ -.PHONY: .gitvalidation # When this is running in travis, it will only check the travis commit range .gitvalidation: @@ -109,8 +111,6 @@ else git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..HEAD endif -.PHONY: install.tools - install.tools: .install.gitvalidation .install.glide .install.glide-vc .install.gitvalidation: @@ -123,13 +123,16 @@ install.tools: .install.gitvalidation .install.glide .install.glide-vc go get -u github.com/sgotti/glide-vc clean: - rm -rf *~ $(OUTPUT_DIRNAME) + rm -rf *~ $(OUTPUT_DIRNAME) header.html .PHONY: \ validate-examples \ check-license \ clean \ lint \ + install.tools \ docs \ test \ + .gitvalidation \ + schema/fs.go \ schema-fs