Skip to content

Commit

Permalink
Merge pull request #27 from snipem/develop-release
Browse files Browse the repository at this point in the history
Add gorelease
  • Loading branch information
snipem authored Apr 10, 2020
2 parents 1c2956c + 2153ffd commit e68ecd6
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 8 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
create:
tags:
- v*
push:
branches:
- develop-release #for testing this

jobs:
test:
strategy:
matrix:
go-version: [1.14.x]
platform: [ubuntu-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

- 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
with:
version: latest
args: release --rm-dist
key: ${{ secrets.YOUR_PRIVATE_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

13 changes: 13 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
builds:
-

main: ./cmd/monako

goos:
- linux
- darwin
- windows

goarch:
- 386
- amd64
38 changes: 31 additions & 7 deletions pkg/compose/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,27 +230,51 @@ 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 ""
}

if !strings.Contains(u.Scheme, "http") {
return ""
}
u.Path = path.Join(u.Path, "blob", branch, remotePath)

// 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()
}

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()
}
69 changes: 68 additions & 1 deletion pkg/compose/file_test.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -139,3 +140,69 @@ 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",
""},

{"[email protected]: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))
})
}
}

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",
""},

{"[email protected]: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))
})
}
}

0 comments on commit e68ecd6

Please sign in to comment.