Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CI pipeline that runs on PRs #238

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: continuous-integration

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
GO_VERSION: "~1.19.4"

jobs:
# Runs Golangci-lint on the source code
ci-go-lint:
name: ci-go-lint
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v3

# Executes Unit Tests
ci-unit-tests:
name: ci-unit-tests
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Run unit tests
run: |
make test

# Builds mark binary
ci-build:
name: ci-build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Build mark
run: |
make build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/testdata
.idea/
/mark.test
/profile.cov
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ build:
-ldflags "-X main.version=$(VERSION)" \
-gcflags "-trimpath $(GOPATH)/src"

test:
go test -race -coverprofile=profile.cov ./...

image:
@echo :: building image $(NAME):$(VERSION)
@docker build -t $(NAME):$(VERSION) -f Dockerfile .
Expand Down
5 changes: 4 additions & 1 deletion pkg/confluence/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func (tracer *tracer) Printf(format string, args ...interface{}) {
func NewAPI(baseURL string, username string, password string) *API {
var auth *gopencils.BasicAuth
if username != "" {
auth = &gopencils.BasicAuth{username, password}
auth = &gopencils.BasicAuth{
Username: username,
Password: password,
}
}
rest := gopencils.Api(baseURL+"/rest/api", auth)
if username == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mark/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func SubstituteLinks(markdown []byte, links []LinkSubstitution) []byte {
}

func parseLinks(markdown string) []markdownLink {
re := regexp.MustCompile("\\[[^\\]]+\\]\\((([^\\)#]+)?#?([^\\)]+)?)\\)")
re := regexp.MustCompile(`\[[^\]]+\]\((([^\)#]+)?#?([^\)]+)?)\)`)
matches := re.FindAllStringSubmatch(markdown, -1)

links := make([]markdownLink, len(matches))
Expand Down
40 changes: 33 additions & 7 deletions pkg/mark/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (renderer ConfluenceRenderer) RenderNode(
theme = option
}
}
renderer.Stdlib.Templates.ExecuteTemplate(
err := renderer.Stdlib.Templates.ExecuteTemplate(
writer,
"ac:code",
struct {
Expand All @@ -197,20 +197,46 @@ func (renderer ConfluenceRenderer) RenderNode(
strings.TrimSuffix(string(node.Literal), "\n"),
},
)
if err != nil {
panic(err)
}

return bf.GoToNext
}
if node.Type == bf.Link && string(node.Destination[0:3]) == "ac:" {
if entering {
writer.Write([]byte("<ac:link><ri:page ri:content-title=\""))
_, err := writer.Write([]byte("<ac:link><ri:page ri:content-title=\""))
if err != nil {
panic(err)
}

if len(node.Destination) < 4 {
writer.Write(node.FirstChild.Literal)
_, err := writer.Write(node.FirstChild.Literal)
if err != nil {
panic(err)
}
} else {
writer.Write(node.Destination[3:])
_, err := writer.Write(node.Destination[3:])
if err != nil {
panic(err)
}

}
_, err = writer.Write([]byte("\"/><ac:plain-text-link-body><![CDATA["))
if err != nil {
panic(err)
}

_, err = writer.Write(node.FirstChild.Literal)
if err != nil {
panic(err)
}
writer.Write([]byte("\"/><ac:plain-text-link-body><![CDATA["))
writer.Write(node.FirstChild.Literal)
writer.Write([]byte("]]></ac:plain-text-link-body></ac:link>"))

_, err = writer.Write([]byte("]]></ac:plain-text-link-body></ac:link>"))
if err != nil {
panic(err)
}

return bf.SkipChildren
}
return bf.GoToNext
Expand Down
4 changes: 0 additions & 4 deletions pkg/mark/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ const (
NL = "\n"
)

func text(lines ...string) string {
return strings.Join(lines, "\n")
}

func TestCompileMarkdown(t *testing.T) {
test := assert.New(t)

Expand Down