From d22760c88a09af3b3a56f4e205457e2456b86ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Fri, 10 Apr 2020 13:18:55 +0200 Subject: [PATCH 01/12] Test for Web url build --- pkg/compose/file.go | 19 ++++++++++++++++--- pkg/compose/file_test.go | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/pkg/compose/file.go b/pkg/compose/file.go index 4919fd9..266c97a 100644 --- a/pkg/compose/file.go +++ b/pkg/compose/file.go @@ -230,14 +230,27 @@ func splitFrontmatterAndBody(content string) (frontmatter string, body string) { func getWebLinkForFileInGit(gitURL string, branch string, remotePath string) string { - // TODO Maybe return nothing if it's a ssh or file repository // URLs for checkout have .git suffix gitURL = strings.TrimSuffix(gitURL, ".git") u, err := url.Parse(gitURL) + if err != nil { - log.Fatalf("Can't parse url: %s", gitURL) + return "" } - u.Path = path.Join(u.Path, "blob", branch, remotePath) + + if !strings.Contains(u.Scheme, "http") { + return "" + } + + // This works for Github and Gitlab + middlePath := "blob" + + // Bitbucket does it differently + if strings.Contains(u.Host, "bitbucket") { + middlePath = "src" + } + + u.Path = path.Join(u.Path, middlePath, branch, remotePath) return u.String() } diff --git a/pkg/compose/file_test.go b/pkg/compose/file_test.go index c1ed0e9..f58419f 100644 --- a/pkg/compose/file_test.go +++ b/pkg/compose/file_test.go @@ -1,8 +1,9 @@ package compose -// run: go test ./pkg/compose -run TestFrontmatterExpanding +// run: go test ./pkg/compose -run TestGetWebLink import ( + "fmt" "path/filepath" "testing" @@ -139,3 +140,36 @@ Also on new line` assert.Contains(t, frontmatter, "content: linetwo\n") }) } + +func TestGetWebLink(t *testing.T) { + + cases := []struct { + gitURL, branch, remotePath, Expected string + }{ + {"https://github.com/snipem/monako-test.git", + "master", "test_doc_asciidoc.adoc", + "https://github.com/snipem/monako-test/blob/master/test_doc_asciidoc.adoc"}, + + {"https://gitlab.com/snipem/monako-test.git", + "test-branch", "README.md", + "https://gitlab.com/snipem/monako-test/blob/test-branch/README.md"}, + + {"https://bitbucket.org/snipem/monako-test.git", + "develop", "README.md", + "https://bitbucket.org/snipem/monako-test/src/develop/README.md"}, + + {"/file/local", + "develop", "README.md", + ""}, + + {"git@github.com:snipem/monako-test.git", + "master", "README.md", + ""}, + } + + for _, tc := range cases { + t.Run(fmt.Sprintf("%s, %s, %s -> %s", tc.gitURL, tc.branch, tc.remotePath, tc.Expected), func(t *testing.T) { + assert.Equal(t, tc.Expected, getWebLinkForFileInGit(tc.gitURL, tc.branch, tc.remotePath)) + }) + } +} From 3b66058943a8a23f0cd5c9c22a4f1d4ab5f0ff08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Fri, 10 Apr 2020 19:07:35 +0200 Subject: [PATCH 02/12] Tests for commit weblink --- pkg/compose/file.go | 19 +++++++++++++++---- pkg/compose/file_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/pkg/compose/file.go b/pkg/compose/file.go index 266c97a..87ecc71 100644 --- a/pkg/compose/file.go +++ b/pkg/compose/file.go @@ -255,15 +255,26 @@ func getWebLinkForFileInGit(gitURL string, branch string, remotePath string) str } func getWebLinkForGitCommit(gitURL string, commitID string) string { - - // TODO Maybe return nothing if it's a ssh or file repository // URLs for checkout have .git suffix gitURL = strings.TrimSuffix(gitURL, ".git") u, err := url.Parse(gitURL) + if err != nil { - log.Fatalf("Can't parse url: %s", gitURL) + return "" + } + + if !strings.Contains(u.Scheme, "http") { + return "" + } + + // This works for Github and Gitlab + middlePath := "commit" + + // Bitbucket does it differently + if strings.Contains(u.Host, "bitbucket") { + middlePath = "commits" } - u.Path = path.Join(u.Path, "commit", commitID) + u.Path = path.Join(u.Path, middlePath, commitID) return u.String() } diff --git a/pkg/compose/file_test.go b/pkg/compose/file_test.go index f58419f..6dc5653 100644 --- a/pkg/compose/file_test.go +++ b/pkg/compose/file_test.go @@ -173,3 +173,36 @@ func TestGetWebLink(t *testing.T) { }) } } + +func TestGetCommitWebLink(t *testing.T) { + + cases := []struct { + gitURL, commitID, Expected string + }{ + {"https://github.com/snipem/monako-test.git", + "b744ffe4761cb3a282dcb30ac23b129ec19c9a53", + "https://github.com/snipem/monako-test/commit/b744ffe4761cb3a282dcb30ac23b129ec19c9a53"}, + + {"https://gitlab.com/snipem/monako-test.git", + "1559b863ff3a9cc1c077ebc480215fd54b621693", + "https://gitlab.com/snipem/monako-test/commit/1559b863ff3a9cc1c077ebc480215fd54b621693"}, + + {"https://bitbucket.org/snipem/monako-test.git", + "e99f32612df02ee18de15bd42326a10e4195be3d", + "https://bitbucket.org/snipem/monako-test/commits/e99f32612df02ee18de15bd42326a10e4195be3d"}, + + {"/file/local", + "commitID4711", + ""}, + + {"git@github.com:snipem/monako-test.git", + "commitID4711", + ""}, + } + + for _, tc := range cases { + t.Run(fmt.Sprintf("%s, %s -> %s", tc.gitURL, tc.commitID, tc.Expected), func(t *testing.T) { + assert.Equal(t, tc.Expected, getWebLinkForGitCommit(tc.gitURL, tc.commitID)) + }) + } +} From 0ad3ac24819672a88142c241d29e6534106b559e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Mon, 6 Apr 2020 21:26:09 +0200 Subject: [PATCH 03/12] Add release yaml --- .github/workflows/release.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..9852499 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,22 @@ +# on: +# push: +# tags: +# - v* + +# jobs: +# test: +# strategy: +# matrix: +# go-version: [1.14.x] +# platform: [ubuntu-latest, macos-latest, windows-latest] +# runs-on: ${{ matrix.platform }} +# steps: +# - name: Run GoReleaser +# uses: goreleaser/goreleaser-action@v1 +# with: +# version: latest +# args: release --rm-dist +# key: ${{ secrets.YOUR_PRIVATE_KEY }} +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + From 0d3816aed0fbf937e157623b39b25297e3b9720a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Fri, 10 Apr 2020 19:27:59 +0200 Subject: [PATCH 04/12] Add release --- .github/workflows/release.yaml | 49 ++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9852499..cfb0b3c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,22 +1,31 @@ -# on: -# push: -# tags: -# - v* +on: + push: + tags: + - v* + branches: + - develop-release #for testing this -# jobs: -# test: -# strategy: -# matrix: -# go-version: [1.14.x] -# platform: [ubuntu-latest, macos-latest, windows-latest] -# runs-on: ${{ matrix.platform }} -# steps: -# - name: Run GoReleaser -# uses: goreleaser/goreleaser-action@v1 -# with: -# version: latest -# args: release --rm-dist -# key: ${{ secrets.YOUR_PRIVATE_KEY }} -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +jobs: + test: + strategy: + matrix: + go-version: [1.14.x] + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Build + uses: goreleaser/goreleaser-action@v1 + + - name: Dependencies + run: make --always-make deps theme + + steps: + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v1 + with: + version: latest + args: release --rm-dist + key: ${{ secrets.YOUR_PRIVATE_KEY }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 1b2ed26e3b61e0f64724978d3a4618a7221ff0dd Mon Sep 17 00:00:00 2001 From: snipem Date: Fri, 10 Apr 2020 19:46:16 +0200 Subject: [PATCH 05/12] Fix typo --- .github/workflows/release.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cfb0b3c..1f33e95 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,7 +19,6 @@ jobs: - name: Dependencies run: make --always-make deps theme - steps: - name: Run GoReleaser uses: goreleaser/goreleaser-action@v1 with: From 4eb885edcbbb2f366a41f60a58e8addb146b23b3 Mon Sep 17 00:00:00 2001 From: snipem Date: Fri, 10 Apr 2020 19:49:07 +0200 Subject: [PATCH 06/12] Possible fix for garbled go.mod after bindata install --- .github/workflows/release.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1f33e95..43c6424 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,11 +13,12 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - name: Build - uses: goreleaser/goreleaser-action@v1 - name: Dependencies run: make --always-make deps theme + + - name: Reset go.mod and go.sum + run: git checkout -- go.mod go.sum - name: Run GoReleaser uses: goreleaser/goreleaser-action@v1 From 7c81a6fa5f87d41597a7e7a772344f455290610d Mon Sep 17 00:00:00 2001 From: snipem Date: Fri, 10 Apr 2020 19:51:17 +0200 Subject: [PATCH 07/12] Checkout --- .github/workflows/release.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 43c6424..e3147cc 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,6 +13,8 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: + - name: Checkout code + uses: actions/checkout@v2 - name: Dependencies run: make --always-make deps theme From 98b021dea0d57fc53c575379d1c4a4d33457c921 Mon Sep 17 00:00:00 2001 From: snipem Date: Fri, 10 Apr 2020 19:53:19 +0200 Subject: [PATCH 08/12] Add Go --- .github/workflows/release.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e3147cc..9b78d76 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,6 +13,17 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: + - name: Install Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + + - name: Setup env + shell: bash + run: | + echo "::set-env name=GOPATH::${{ github.workspace }}/../go" + echo "::add-path::${{ github.workspace }}/../go/bin" + - name: Checkout code uses: actions/checkout@v2 From eefe13c39e671fbbda706e07028c2de86c7ff862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Fri, 10 Apr 2020 20:03:23 +0200 Subject: [PATCH 09/12] Add goreleaser --- .goreleaser.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .goreleaser.yaml diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..a68ba39 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,15 @@ +builds: + - + + main: ./cmd/monako + + goos: + - linux + - darwin + - windows + + goarch: + - 386 + - amd64 + - arm + - arm64 \ No newline at end of file From 24d264c833d3ca2729b5e91c0b1f71de582b7434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Fri, 10 Apr 2020 20:04:26 +0200 Subject: [PATCH 10/12] Run test before releasing --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9b78d76..ac4290a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -28,7 +28,7 @@ jobs: uses: actions/checkout@v2 - name: Dependencies - run: make --always-make deps theme + run: make --always-make deps theme test - name: Reset go.mod and go.sum run: git checkout -- go.mod go.sum From a48a7302088c18735e642ea526d14f02a40f8a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Fri, 10 Apr 2020 20:08:51 +0200 Subject: [PATCH 11/12] Add asciidoc --- .github/workflows/release.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ac4290a..553bdad 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: go-version: [1.14.x] - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} steps: - name: Install Go @@ -23,6 +23,12 @@ jobs: 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/setup-ruby@v1.0.0 + + - name: Install asciidoctor + run: gem install asciidoctor asciidoctor-diagram - name: Checkout code uses: actions/checkout@v2 From 2153ffd5301939df77e09302fcad31a9de982ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCch?= Date: Fri, 10 Apr 2020 20:28:35 +0200 Subject: [PATCH 12/12] Build less --- .github/workflows/release.yaml | 11 +++-------- .goreleaser.yaml | 4 +--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 553bdad..f5e42bb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,7 +1,8 @@ on: - push: + create: tags: - v* + push: branches: - develop-release #for testing this @@ -24,17 +25,11 @@ jobs: echo "::set-env name=GOPATH::${{ github.workspace }}/../go" echo "::add-path::${{ github.workspace }}/../go/bin" - - name: Setup Ruby for use with actions - uses: actions/setup-ruby@v1.0.0 - - - name: Install asciidoctor - run: gem install asciidoctor asciidoctor-diagram - - name: Checkout code uses: actions/checkout@v2 - name: Dependencies - run: make --always-make deps theme test + run: make --always-make deps theme - name: Reset go.mod and go.sum run: git checkout -- go.mod go.sum diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a68ba39..1042d80 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,6 +10,4 @@ builds: goarch: - 386 - - amd64 - - arm - - arm64 \ No newline at end of file + - amd64 \ No newline at end of file