diff --git a/.ci/e2e b/.ci/e2e index 063552c7..77a1d9ca 100755 --- a/.ci/e2e +++ b/.ci/e2e @@ -50,7 +50,7 @@ export GITHUB_OAUTH_TOKEN=$TOKEN buildWebsite() { LOCAL_BUILD=1 "${docforge_repo_path}/.ci/build" >/dev/null 2>&1 mv "$docforge_bin" /usr/local/bin/docforge - "${website_generator_path}/.ci/build" + SKIP_VALIDATION=true "${website_generator_path}/.ci/build" } echo "Building current docforge" diff --git a/.ci/integration-test b/.ci/integration-test index 8d324e61..7769842a 100755 --- a/.ci/integration-test +++ b/.ci/integration-test @@ -87,12 +87,12 @@ docforge_bin="${docforge_repo_path}/bin/docforge" echo "Docforge version: $(${docforge_bin} version)" -GIT_OAUTH_TOKEN="github.com=${GITHUB_OAUTH_TOKEN:-$(getGitHubToken github_com)}" +GIT_OAUTH_TOKEN="${GITHUB_OAUTH_TOKEN:-$(getGitHubToken github_com)}" test "$GIT_OAUTH_TOKEN" #fail fast # Run docforge command with Git handler echo "Run ${docforge_bin}" -${docforge_bin} -f "${int_test_manifest}" -d "${int_test_output_tree_dir}" --hugo --github-oauth-token-map "${GIT_OAUTH_TOKEN}" --github-info-destination ../generated-metadata +${docforge_bin} -f "${int_test_manifest}" -d "${int_test_output_tree_dir}" --hugo --github-oauth-token-map "github.com=${GIT_OAUTH_TOKEN}" --github-info-destination ../generated-metadata #Remove untested metadata keys removeUntestedKeysFromMetadata "${int_test_expected_metadata_dir}" diff --git a/cmd/app/flags.go b/cmd/app/flags.go index 326963f2..349fabfd 100644 --- a/cmd/app/flags.go +++ b/cmd/app/flags.go @@ -68,7 +68,7 @@ func configureFlags(command *cobra.Command) { "Rewrites the relative links of documentation files to root-relative where possible.") _ = vip.BindPFlag("hugo-base-url", command.Flags().Lookup("hugo-base-url")) - command.Flags().StringSlice("hugo-section-files", []string{"readme.md", "readme", "read.me", "index.md", "index"}, + command.Flags().StringSlice("hugo-section-files", []string{"readme.md", "README.md"}, "When building a Hugo-compliant documentation bundle, files with filename matching one form this list (in that order) will be renamed to _index.md. Only useful with --hugo=true") _ = vip.BindPFlag("hugo-section-files", command.Flags().Lookup("hugo-section-files")) diff --git a/pkg/workers/document/document_worker.go b/pkg/workers/document/document_worker.go index 3778d4f3..71231765 100644 --- a/pkg/workers/document/document_worker.go +++ b/pkg/workers/document/document_worker.go @@ -91,7 +91,7 @@ func (d *Worker) ProcessNode(ctx context.Context, node *manifest.Node) error { } cnt = bytesBuff.Bytes() } - if err := d.writer.Write(node.Name(), node.Path, cnt, node); err != nil { + if err := d.writer.Write(node.Name(), node.Path, cnt, node, d.hugo.IndexFileNames); err != nil { return err } return nil diff --git a/pkg/workers/document/document_worker_test.go b/pkg/workers/document/document_worker_test.go index 1fc5862b..542d0413 100644 --- a/pkg/workers/document/document_worker_test.go +++ b/pkg/workers/document/document_worker_test.go @@ -68,7 +68,7 @@ var _ = Describe("Document resolving", func() { } err := dw.ProcessNode(context.TODO(), node) Expect(err).ToNot(HaveOccurred()) - name, path, cnt, nodegot := w.WriteArgsForCall(0) + name, path, cnt, nodegot, _ := w.WriteArgsForCall(0) Expect(name).To(Equal("node")) Expect(path).To(Equal("one")) target, err := manifests.ReadFile("tests/expected_target.md") @@ -91,7 +91,7 @@ var _ = Describe("Document resolving", func() { } err := dw.ProcessNode(context.TODO(), node) Expect(err).ToNot(HaveOccurred()) - name, path, cnt, nodegot := w.WriteArgsForCall(0) + name, path, cnt, nodegot, _ := w.WriteArgsForCall(0) Expect(name).To(Equal("node")) Expect(path).To(Equal("one")) target, err := manifests.ReadFile("tests/expected_target.md") diff --git a/pkg/workers/githubinfo/github_info.go b/pkg/workers/githubinfo/github_info.go index 0e473b3f..23510d52 100644 --- a/pkg/workers/githubinfo/github_info.go +++ b/pkg/workers/githubinfo/github_info.go @@ -66,7 +66,7 @@ func (w *Worker) WriteGithubInfo(ctx context.Context, node *manifest.Node) error } nodePath := node.Path klog.V(6).Infof("writing git info for node %s/%s\n", nodePath, node.Name()) - if err = w.writer.Write(node.Name(), nodePath, b.Bytes(), node); err != nil { + if err = w.writer.Write(node.Name(), nodePath, b.Bytes(), node, nil); err != nil { return err } return nil diff --git a/pkg/workers/githubinfo/github_info_test.go b/pkg/workers/githubinfo/github_info_test.go index d4844ea6..4cb65fe5 100644 --- a/pkg/workers/githubinfo/github_info_test.go +++ b/pkg/workers/githubinfo/github_info_test.go @@ -99,7 +99,7 @@ var _ = Describe("Executing WriteGithubInfo", func() { }) It("succeeded", func() { Expect(err).NotTo(HaveOccurred()) - _, _, content, _ := writer.WriteArgsForCall(0) + _, _, content, _, _ := writer.WriteArgsForCall(0) Expect(string(content)).To(Equal("repoHost1 source_content\nrepoHost2 multi_source_content\n")) }) }) @@ -116,7 +116,7 @@ var _ = Describe("Executing WriteGithubInfo", func() { It("succeeded", func() { Expect(err).NotTo(HaveOccurred()) - name, path, content, node := writer.WriteArgsForCall(0) + name, path, content, node, _ := writer.WriteArgsForCall(0) Expect(node).NotTo(BeNil()) Expect(node.Name()).To(Equal("README.md")) Expect(node.Source).To(Equal("https://github.com/gardener/docforge/blob/master/README.md")) diff --git a/pkg/workers/resourcedownloader/resourcedownloader.go b/pkg/workers/resourcedownloader/resourcedownloader.go index 680d2490..f45fec40 100644 --- a/pkg/workers/resourcedownloader/resourcedownloader.go +++ b/pkg/workers/resourcedownloader/resourcedownloader.go @@ -79,7 +79,7 @@ func (d *ResourceDownloadWorker) download(ctx context.Context, Source string, Ta if err != nil { return err } - if err = d.writer.Write(Target, "", blob, nil); err != nil { + if err = d.writer.Write(Target, "", blob, nil, nil); err != nil { return err } return nil diff --git a/pkg/workers/resourcedownloader/resourcedownloader_test.go b/pkg/workers/resourcedownloader/resourcedownloader_test.go index d3eb1ca9..257979ff 100644 --- a/pkg/workers/resourcedownloader/resourcedownloader_test.go +++ b/pkg/workers/resourcedownloader/resourcedownloader_test.go @@ -102,7 +102,7 @@ var _ = Describe("Executing Download", func() { It("succeeded", func() { Expect(err).NotTo(HaveOccurred()) Expect(writer.WriteCallCount()).To(Equal(1)) - name, path, content, node := writer.WriteArgsForCall(0) + name, path, content, node, _ := writer.WriteArgsForCall(0) Expect(node).To(BeNil()) Expect(path).To(Equal("")) Expect(name).To(Equal("fake_target")) diff --git a/pkg/writers/dryRunWriter.go b/pkg/writers/dryRunWriter.go index d3a6f2a3..4ef45dd8 100644 --- a/pkg/writers/dryRunWriter.go +++ b/pkg/writers/dryRunWriter.go @@ -70,7 +70,7 @@ func (d *dryRunWriter) GetWriter(root string) Writer { return _w } -func (w *writer) Write(name, path string, docBlob []byte, node *manifest.Node) error { +func (w *writer) Write(name, path string, docBlob []byte, node *manifest.Node, IndexFileNames []string) error { if len(docBlob) > 0 && node != nil { if !strings.HasSuffix(name, ".md") { name = fmt.Sprintf("%s.md", name) diff --git a/pkg/writers/fswriter.go b/pkg/writers/fswriter.go index a7471f80..507c1f61 100644 --- a/pkg/writers/fswriter.go +++ b/pkg/writers/fswriter.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "github.com/gardener/docforge/pkg/manifest" "gopkg.in/yaml.v3" @@ -21,7 +22,10 @@ type FSWriter struct { Hugo bool } -func (f *FSWriter) Write(name, path string, docBlob []byte, node *manifest.Node) error { +func (f *FSWriter) Write(name, path string, docBlob []byte, node *manifest.Node, IndexFileNames []string) error { + if slices.Contains(IndexFileNames, name) { + name = "_index.md" + } //generate _index.md content if f.Hugo && name == "_index.md" && node != nil && node.Frontmatter != nil && docBlob == nil { buf := bytes.Buffer{} diff --git a/pkg/writers/fswriter_test.go b/pkg/writers/fswriter_test.go index 97a7c20f..cde81034 100644 --- a/pkg/writers/fswriter_test.go +++ b/pkg/writers/fswriter_test.go @@ -59,7 +59,7 @@ func TestWrite(t *testing.T) { } }() - err := fs.Write(tc.name, tc.path, tc.docBlob, tc.node) + err := fs.Write(tc.name, tc.path, tc.docBlob, tc.node, nil) if err != tc.wantErr { t.Errorf("expected err %v != %v", tc.wantErr, err) diff --git a/pkg/writers/writers.go b/pkg/writers/writers.go index 03be4a68..8f3e9842 100644 --- a/pkg/writers/writers.go +++ b/pkg/writers/writers.go @@ -12,5 +12,5 @@ import "github.com/gardener/docforge/pkg/manifest" // //counterfeiter:generate . Writer type Writer interface { - Write(name, path string, resourceContent []byte, node *manifest.Node) error + Write(name, path string, resourceContent []byte, node *manifest.Node, IndexFileNames []string) error } diff --git a/pkg/writers/writersfakes/fake_writer.go b/pkg/writers/writersfakes/fake_writer.go index 17eb6698..af0d45b9 100644 --- a/pkg/writers/writersfakes/fake_writer.go +++ b/pkg/writers/writersfakes/fake_writer.go @@ -12,13 +12,14 @@ import ( ) type FakeWriter struct { - WriteStub func(string, string, []byte, *manifest.Node) error + WriteStub func(string, string, []byte, *manifest.Node, []string) error writeMutex sync.RWMutex writeArgsForCall []struct { arg1 string arg2 string arg3 []byte arg4 *manifest.Node + arg5 []string } writeReturns struct { result1 error @@ -30,12 +31,17 @@ type FakeWriter struct { invocationsMutex sync.RWMutex } -func (fake *FakeWriter) Write(arg1 string, arg2 string, arg3 []byte, arg4 *manifest.Node) error { +func (fake *FakeWriter) Write(arg1 string, arg2 string, arg3 []byte, arg4 *manifest.Node, arg5 []string) error { var arg3Copy []byte if arg3 != nil { arg3Copy = make([]byte, len(arg3)) copy(arg3Copy, arg3) } + var arg5Copy []string + if arg5 != nil { + arg5Copy = make([]string, len(arg5)) + copy(arg5Copy, arg5) + } fake.writeMutex.Lock() ret, specificReturn := fake.writeReturnsOnCall[len(fake.writeArgsForCall)] fake.writeArgsForCall = append(fake.writeArgsForCall, struct { @@ -43,13 +49,14 @@ func (fake *FakeWriter) Write(arg1 string, arg2 string, arg3 []byte, arg4 *manif arg2 string arg3 []byte arg4 *manifest.Node - }{arg1, arg2, arg3Copy, arg4}) + arg5 []string + }{arg1, arg2, arg3Copy, arg4, arg5Copy}) stub := fake.WriteStub fakeReturns := fake.writeReturns - fake.recordInvocation("Write", []interface{}{arg1, arg2, arg3Copy, arg4}) + fake.recordInvocation("Write", []interface{}{arg1, arg2, arg3Copy, arg4, arg5Copy}) fake.writeMutex.Unlock() if stub != nil { - return stub(arg1, arg2, arg3, arg4) + return stub(arg1, arg2, arg3, arg4, arg5) } if specificReturn { return ret.result1 @@ -63,17 +70,17 @@ func (fake *FakeWriter) WriteCallCount() int { return len(fake.writeArgsForCall) } -func (fake *FakeWriter) WriteCalls(stub func(string, string, []byte, *manifest.Node) error) { +func (fake *FakeWriter) WriteCalls(stub func(string, string, []byte, *manifest.Node, []string) error) { fake.writeMutex.Lock() defer fake.writeMutex.Unlock() fake.WriteStub = stub } -func (fake *FakeWriter) WriteArgsForCall(i int) (string, string, []byte, *manifest.Node) { +func (fake *FakeWriter) WriteArgsForCall(i int) (string, string, []byte, *manifest.Node, []string) { fake.writeMutex.RLock() defer fake.writeMutex.RUnlock() argsForCall := fake.writeArgsForCall[i] - return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5 } func (fake *FakeWriter) WriteReturns(result1 error) {