Skip to content

Commit

Permalink
Merge pull request #18 from snipem/develop
Browse files Browse the repository at this point in the history
More tests, Asciidoctor image:: fix, Better stdout output
  • Loading branch information
snipem authored Apr 1, 2020
2 parents 792d54b + 893f787 commit 4baaad0
Show file tree
Hide file tree
Showing 27 changed files with 303 additions and 326 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,31 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- name: setup env
- name: Setup env
shell: bash
run: |
echo "::set-env name=GOPATH::${{ github.workspace }}/../go"
echo "::add-path::${{ github.workspace }}/../go/bin"
- name: Setup Ruby for use with actions
uses: actions/[email protected]

- name: Install asciidoctor
run: gem install asciidoctor asciidoctor-diagram

- name: Checkout code
uses: actions/checkout@v2

- name: dependencies
- name: Dependencies
run: make --always-make deps test_deps

- name: Fetch Theme
run: make --always-make theme

- name: test
- name: Test
run: make --always-make test

- name: build
- name: Build
run: make --always-make build

- name: Codecov
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ coverage.out.tmp
# Monako bin
monako

/compose
/compose
test/configs/testgenerated/config.testgenerated.yaml
test/configs/testgenerated/menu.testgenerated.md
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ theme: clean
${GOPATH}/bin/go-bindata -pkg theme -o internal/theme/bindata.go tmp/...

secrets:
touch config/secrets.env && source config/secrets.env
touch config/secrets.env && source config/secrets.env

test:
go test -covermode=count -coverprofile=coverage.out.tmp ./...
# -coverpkg=./... also calculates the whole coverage, for example code that was involded by the main test
cat coverage.out.tmp | grep -v "/bindata.go" > coverage.out
rm coverage.out.tmp

coverage: test
${GOPATH}/bin/goveralls -coverprofile=coverage.out -service=github -repotoken ${COVERALLS_TOKEN}

test_deps:
go get golang.org/x/tools/cmd/cover
go get github.com/mattn/goveralls

test_data:
git clone https://github.com/snipem/monako-test.git /tmp/testdata/monako-test

# Use this for local tests, uses the locally cloned test data from test_data step
test_local:
MONAKO_TEST_REPO="/tmp/testdata/monako-test" $(MAKE) test

run_prd: build secrets
./monako -config ~/work/mopro/architecture/documentation/conf/config.prod.yaml \
Expand All @@ -54,7 +58,9 @@ run_local: build
$(MAKE) serve

compose:
./monako -config configs/config.monako.yaml \
./monako \
-fail-on-error \
-config configs/config.monako.yaml \
-menu-config configs/config.menu.md

serve:
Expand Down
84 changes: 80 additions & 4 deletions cmd/monako/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ func TestMain(t *testing.T) {

targetDir := filet.TmpDir(t, "")

monakoConfig, menuConfig := writeConfig("https://github.com/snipem/monako-test.git")

os.Args = []string{
"monako",
"-fail-on-error",
"-working-dir", targetDir,
"-config", "../../test/configs/only_markdown/config.markdown.yaml",
"-menu-config", "../../test/configs/only_markdown/config.menu.markdown.md"}
"-config", monakoConfig,
"-menu-config", menuConfig}
t.Logf("Running Monako with %s", os.Args)
main()

t.Run("Check for Hugo input files", func(t *testing.T) {
Expand Down Expand Up @@ -68,7 +71,7 @@ func TestMain(t *testing.T) {
log.Fatal(err)
}

// TODO For some reason imgages seem to be ignored in urls
// TODO For some reason images seem to be ignored in urls
for _, url := range urls {
if strings.HasPrefix(url.String(), ts.URL) {
// t.Logf("Checking for local served url %s", url.String())
Expand All @@ -80,7 +83,7 @@ func TestMain(t *testing.T) {

})

t.Run("Check contents of served page", func(t *testing.T) {
t.Run("Check contents of served page markdown", func(t *testing.T) {

content, err := getContent(ts, "/docs/test/test_doc_markdown/index.html")
assert.NoError(t, err, "HTTP Call failed")
Expand All @@ -91,6 +94,17 @@ func TestMain(t *testing.T) {

})

t.Run("Check contents of served page asciidoc", func(t *testing.T) {

content, err := getContent(ts, "/docs/test/test_doc_asciidoc/index.html")
assert.NoError(t, err, "HTTP Call failed")

assert.Contains(t, content, "Ihr naht euch wieder, schwankende Gestalten!", "Does not contain Goethe")
assert.Contains(t, content, "Test docs", "Does not contain Menu header")
assert.Contains(t, content, "<a href=\"#_asciidoc_second_level\">Asciidoc Second Level</a>", "Check rendered Asciidoc")

})

if !t.Failed() && runtime.GOOS != "windows" {
// Only clean up when not failed
// and not on Windows this is because of a filet bug (https://github.com/Flaque/filet/issues/3)
Expand Down Expand Up @@ -164,3 +178,65 @@ func getURLKeyValuesFromHTML(content string, key string, baseURL string) ([]*url
}

}

// writeConfig writes a temporary config for a repo in the local test folders
// of this project and returns the path to the monakoConfig and menuConfig
// Also if the MONAKO_TEST_REPO environment variable is set, it will use this
// environment variable for the repository stored in the Monako config.
func writeConfig(repo string) (string, string) {

var testRepo string

if os.Getenv("MONAKO_TEST_REPO") != "" {
testRepo = os.Getenv("MONAKO_TEST_REPO")
} else {
testRepo = repo
}

monakoConfig := fmt.Sprintf(`
---
baseURL : "https://example.com/"
title : "Local Test Page"
whitelist:
- ".md"
- ".adoc"
- ".jpg"
- ".jpeg"
- ".svg"
- ".gif"
- ".png"
origins:
# Files have to be commited to appear!
- src: %s
branch: master
docdir: .
targetdir: docs/test/
`, testRepo)

menuConfig := fmt.Sprintf(`
---
headless: true
---
- **Test docs**
- [Markdown]({{<relref "test_doc_markdown.md">}})
<br />
`)

pathMonakoConfig := "../../test/configs/testgenerated/config.testgenerated.yaml"
err := ioutil.WriteFile(pathMonakoConfig, []byte(monakoConfig), os.FileMode(0600))
if err != nil {
log.Fatal(err)
}

pathMenuConfig := "../../test/configs/testgenerated/menu.testgenerated.md"
err = ioutil.WriteFile(pathMenuConfig, []byte(menuConfig), os.FileMode(0600))
if err != nil {
log.Fatal(err)
}

return pathMonakoConfig, pathMenuConfig
}
6 changes: 6 additions & 0 deletions configs/config.monako.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
baseURL : "https://example.com/"
title : "My Projects"
logo : "docs/monako/profile.png"

whitelist:
- ".md"
Expand All @@ -13,6 +14,11 @@

origins:

- src: https://github.com/snipem/monako-test
branch: master
docdir: .
targetdir: docs/monako

- src: https://github.com/snipem/commute-tube
branch: master
docdir: .
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ go 1.12
require (
github.com/Flaque/filet v0.0.0-20190209224823-fc4d33cfcf93
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38
github.com/artdarek/go-unzip v1.0.0
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c
github.com/dsnet/compress v0.0.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gohugoio/hugo v0.67.0
github.com/golang/protobuf v1.3.2 // indirect
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect
github.com/klauspost/pgzip v1.2.3 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mitchellh/mapstructure v1.2.2 // indirect
Expand All @@ -19,6 +23,7 @@ require (
github.com/spf13/cobra v0.0.7 // indirect
github.com/spf13/viper v1.6.2 // indirect
github.com/stretchr/testify v1.5.1
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/yuin/goldmark v1.1.25 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
Expand Down
20 changes: 18 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/artdarek/go-unzip v1.0.0 h1:Ja9wfhiXyl67z5JT37rWjTSb62KXDP+9jHRkdSREUvg=
github.com/artdarek/go-unzip v1.0.0/go.mod h1:KhX4LV7e4UwWCTo7orBYnJ6LJ/dZTI6jXxUg69hO/C8=
github.com/aws/aws-sdk-go v1.15.27/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/aws/aws-sdk-go v1.18.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.19.16/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
Expand All @@ -80,6 +78,10 @@ github.com/bep/golibsass v0.5.0 h1:b+Uxsk826Q35OmbenSmU65P+FJJQoVs2gI2mk1ba28s=
github.com/bep/golibsass v0.5.0/go.mod h1:DL87K8Un/+pWUS75ggYv41bliGiolxzDKWJAq3eJ1MA=
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 h1:GKTyiRCL6zVf5wWaqKnf+7Qs6GbEPfd4iMOitWzXJx8=
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8/go.mod h1:spo1JLcs67NmW1aVLEgtA8Yy1elc+X8y5SRW1sFW4Og=
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c h1:aprLqMn7gSPT+vdDSl+/E6NLEuArwD/J7IWd8bJt5lQ=
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c/go.mod h1:Ie6SubJv/NTO9Q0UBH0QCl3Ve50lu9hjbi5YJUw03TE=
github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U=
Expand Down Expand Up @@ -111,6 +113,9 @@ github.com/disintegration/gift v1.2.1/go.mod h1:Jh2i7f7Q2BM7Ezno3PhfezbR1xpUg9dU
github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk=
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
Expand Down Expand Up @@ -202,6 +207,8 @@ github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 h1:WgfvpuKg42WVLkxNwzfFraXkTXPK36bMqXvMFN67clI=
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214/go.mod h1:kj6hFWqfwSjFjLnYW5PK1DoxZ4O0uapwHRmd9jhln4E=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand All @@ -225,6 +232,12 @@ github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.4.1 h1:8VMb5+0wMgdBykOV96DwNwKFQ+WTI4pzYURP99CcB9E=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.3 h1:Ce2to9wvs/cuJ2b86/CKQoTYr9VHfpanYosZ0UBJqdw=
github.com/klauspost/pgzip v1.2.3/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
Expand Down Expand Up @@ -391,6 +404,9 @@ github.com/uber/jaeger-client-go v2.15.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMW
github.com/uber/jaeger-lib v1.5.0/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/ulikunitz/xz v0.5.7 h1:YvTNdFzX6+W5m9msiYg/zpkSURPPtOlzbqYjrFn7Yt4=
github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
Expand Down
34 changes: 11 additions & 23 deletions internal/theme/theme.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package theme

import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/artdarek/go-unzip"
"github.com/c4milo/unpackit"
"github.com/snipem/monako/pkg/compose"
)

Expand Down Expand Up @@ -49,6 +50,9 @@ baseURL = '%s'
title = '%s'
theme = '%s'
# Because of this bug: https://github.com/gohugoio/hugo/issues/4841
timeout = 60000
# Book configuration
disablePathToLower = true
enableGitInfo = false
Expand All @@ -64,15 +68,15 @@ startLevel = 1
[params]
# See: https://github.com/snipem/monako-book#configuration for settings
BookToC = true
BookLogo = 'logo.png'
BookLogo = '%s'
BookMenuBundle = '/%s'
BookSection = 'docs'
#BookRepo = 'https://github.com/alex-shpak/hugo-book'
#BookEditPath = 'edit/master/exampleSite/content'
BookDateFormat = 'Jan 2, 2006'
BookSearch = true
BookComments = true
`, composeConfig.BaseURL, composeConfig.Title, themeName, monakoMenuDirectory)
`, composeConfig.BaseURL, composeConfig.Title, themeName, composeConfig.Logo, monakoMenuDirectory)
return ioutil.WriteFile(filepath.Join(composeConfig.HugoWorkingDir, "config.toml"), []byte(configContent), os.FileMode(0700))
}

Expand All @@ -81,28 +85,12 @@ func extractTheme(composeConfig compose.Config) {
if err != nil {
log.Fatalf("Error loading theme %s", err)
}
byteReader := bytes.NewReader(themezip)

// TODO Don't use local filesystem, keep it in memory
tmpFile, err := ioutil.TempFile(os.TempDir(), "monako-theme-")
if err != nil {
log.Fatalf("Cannot create temporary file %s", err)
}
_, err = tmpFile.Write(themezip)
destPath, err := unpackit.Unpack(byteReader, filepath.Join(composeConfig.HugoWorkingDir, "themes"))
if err != nil {
log.Fatalf("Error temporary theme zip file %s", err)
log.Fatalf("Error extracting theme: %s", err)
}

tempfilename := tmpFile.Name()

if err != nil {
log.Fatalf("Error writing temp theme %s", err)
}

// TODO Don't use a library that depends on local files
uz := unzip.New(tempfilename, filepath.Join(composeConfig.HugoWorkingDir, "themes"))
err = uz.Extract()
if err != nil {
log.Fatalf("Error extracting theme: %s ", err)
}
os.RemoveAll(tempfilename)
log.Printf("Extracted %s", destPath)
}
Loading

0 comments on commit 4baaad0

Please sign in to comment.