Skip to content

Commit

Permalink
Merge branch 'main' into let-webhook-pass-on-config-parse-err
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 authored Jun 25, 2024
2 parents 2f0f9fe + 402938e commit e484bdd
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,5 @@ issues:

run:
timeout: 15m
build-tags:
- test
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ else
endif
endif

TAGS ?=
LDFLAGS := -X go.woodpecker-ci.org/woodpecker/v2/version.Version=${VERSION}
STATIC_BUILD ?= true
ifeq ($(STATIC_BUILD),true)
Expand Down Expand Up @@ -162,20 +163,20 @@ lint-ui: ui-dependencies ## Lint UI code
(cd web/; pnpm lint --quiet)

test-agent: ## Test agent code
go test -race -cover -coverprofile agent-coverage.out -timeout 30s go.woodpecker-ci.org/woodpecker/v2/cmd/agent go.woodpecker-ci.org/woodpecker/v2/agent/...
go test -race -cover -coverprofile agent-coverage.out -timeout 30s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/cmd/agent go.woodpecker-ci.org/woodpecker/v2/agent/...

test-server: ## Test server code
go test -race -cover -coverprofile server-coverage.out -timeout 30s go.woodpecker-ci.org/woodpecker/v2/cmd/server $(shell go list go.woodpecker-ci.org/woodpecker/v2/server/... | grep -v '/store')
go test -race -cover -coverprofile server-coverage.out -timeout 30s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/cmd/server $(shell go list go.woodpecker-ci.org/woodpecker/v2/server/... | grep -v '/store')

test-cli: ## Test cli code
go test -race -cover -coverprofile cli-coverage.out -timeout 30s go.woodpecker-ci.org/woodpecker/v2/cmd/cli go.woodpecker-ci.org/woodpecker/v2/cli/...
go test -race -cover -coverprofile cli-coverage.out -timeout 30s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/cmd/cli go.woodpecker-ci.org/woodpecker/v2/cli/...

test-server-datastore: ## Test server datastore
go test -timeout 120s -run TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/...
go test -race -timeout 30s -skip TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/...
go test -timeout 120s -tags 'test $(TAGS)' -run TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/...
go test -race -timeout 30s -tags 'test $(TAGS)' -skip TestMigrate go.woodpecker-ci.org/woodpecker/v2/server/store/...

test-server-datastore-coverage: ## Test server datastore with coverage report
go test -race -cover -coverprofile datastore-coverage.out -timeout 180s go.woodpecker-ci.org/woodpecker/v2/server/store/...
go test -race -cover -coverprofile datastore-coverage.out -timeout 180s -tags 'test $(TAGS)' go.woodpecker-ci.org/woodpecker/v2/server/store/...

test-ui: ui-dependencies ## Test UI code
(cd web/; pnpm run lint)
Expand All @@ -184,7 +185,7 @@ test-ui: ui-dependencies ## Test UI code
(cd web/; pnpm run test)

test-lib: ## Test lib code
go test -race -cover -coverprofile coverage.out -timeout 30s $(shell go list ./... | grep -v '/cmd\|/agent\|/cli\|/server')
go test -race -cover -coverprofile coverage.out -timeout 30s -tags 'test $(TAGS)' $(shell go list ./... | grep -v '/cmd\|/agent\|/cli\|/server')

.PHONY: test
test: test-agent test-server test-server-datastore test-cli test-lib ## Run all tests
Expand All @@ -195,13 +196,13 @@ build-ui: ## Build UI
(cd web/; pnpm install --frozen-lockfile; pnpm build)

build-server: build-ui generate-swagger ## Build server
CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-server${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/server
CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags '$(TAGS)' -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-server${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/server

build-agent: ## Build agent
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-agent${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/agent
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags '$(TAGS)' -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-agent${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/agent

build-cli: ## Build cli
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-cli${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/cli
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags '$(TAGS)' -ldflags '${LDFLAGS}' -o ${DIST_DIR}/woodpecker-cli${BIN_SUFFIX} go.woodpecker-ci.org/woodpecker/v2/cmd/cli

build-tarball: ## Build tar archive
mkdir -p ${DIST_DIR} && tar chzvf ${DIST_DIR}/woodpecker-src.tar.gz \
Expand Down
46 changes: 46 additions & 0 deletions cli/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"crypto/x509"
"fmt"
"net/http"
"os/exec"
"strconv"
"strings"

vsc_url "github.com/gitsight/go-vcsurl"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"golang.org/x/net/proxy"
Expand Down Expand Up @@ -90,8 +92,52 @@ func NewClient(c *cli.Context) (woodpecker.Client, error) {
return woodpecker.NewClient(server, client), nil
}

func getRepoFromGit(remoteName string) (string, error) {
cmd := exec.Command("git", "remote", "get-url", remoteName)
stdout, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("could not get remote url: %w", err)
}

gitRemote := strings.TrimSpace(string(stdout))

log.Debug().Str("git-remote", gitRemote).Msg("extracted remote url from git")

if len(gitRemote) == 0 {
return "", fmt.Errorf("no repository provided")
}

u, err := vsc_url.Parse(gitRemote)
if err != nil {
return "", fmt.Errorf("could not parse git remote url: %w", err)
}

repoFullName := u.FullName
log.Debug().Str("repo", repoFullName).Msg("extracted repository from remote url")

return repoFullName, nil
}

// ParseRepo parses the repository owner and name from a string.
func ParseRepo(client woodpecker.Client, str string) (repoID int64, err error) {
if str == "" {
str, err = getRepoFromGit("upstream")
if err != nil {
log.Debug().Err(err).Msg("could not get repository from git upstream remote")
}
}

if str == "" {
str, err = getRepoFromGit("origin")
if err != nil {
log.Debug().Err(err).Msg("could not get repository from git origin remote")
}
}

if str == "" {
return 0, fmt.Errorf("no repository provided")
}

if strings.Contains(str, "/") {
repo, err := client.RepoLookup(str)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf
github.com/fsnotify/fsnotify v1.7.0
github.com/gin-gonic/gin v1.10.0
github.com/gitsight/go-vcsurl v1.0.1
github.com/go-ap/httpsig v0.0.0-20221203064646-3647b4d88fdf
github.com/go-sql-driver/mysql v1.8.1
github.com/golang-jwt/jwt/v5 v5.2.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/gitsight/go-vcsurl v1.0.1 h1:wkijKsbVg9R2IBP97U7wOANeIW9WJJKkBwS9XqllzWo=
github.com/gitsight/go-vcsurl v1.0.1/go.mod h1:qRFdKDa/0Lh9MT0xE+qQBYZ/01+mY1H40rZUHR24X9U=
github.com/go-ap/httpsig v0.0.0-20221203064646-3647b4d88fdf h1:Ab5yBsD/dXhFmgf2hX7T/YYr+VK0Df7SrIxyNztT9YE=
github.com/go-ap/httpsig v0.0.0-20221203064646-3647b4d88fdf/go.mod h1:+4SUDMvPlRMUPW5PlMTbxj3U5a4fWasBIbakUw7Kp6c=
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
Expand Down
3 changes: 3 additions & 0 deletions pipeline/rpc/mocks/peer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pipeline/rpc/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type (
}
)

//go:generate mockery --name Peer --output mocks --case underscore
//go:generate mockery --name Peer --output mocks --case underscore --note "+build test"

// Peer defines a peer-to-peer connection.
type Peer interface {
Expand Down
2 changes: 1 addition & 1 deletion server/forge/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package forge

//go:generate mockery --name Forge --output mocks --case underscore
//go:generate mockery --name Forge --output mocks --case underscore --note "+build test"

import (
"context"
Expand Down
3 changes: 3 additions & 0 deletions server/forge/mocks/forge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/services/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server/store"
)

//go:generate mockery --name Manager --output mocks --case underscore
//go:generate mockery --name Manager --output mocks --case underscore --note "+build test"

const forgeCacheTTL = 10 * time.Minute

Expand Down
3 changes: 3 additions & 0 deletions server/services/mocks/manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions server/store/mocks/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package store

//go:generate mockery --name Store --output mocks --case underscore
//go:generate mockery --name Store --output mocks --case underscore --note "+build test"

import (
"go.woodpecker-ci.org/woodpecker/v2/server/model"
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/user/UserCLIAndAPITab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const usageWithCurl = computed(() => {
return usage;
});
const usageWithCli = `# woodpecker setup --server-url ${address}`;
const usageWithCli = `# woodpecker setup --server ${address}`;
const cliDownload = 'https://github.com/woodpecker-ci/woodpecker/releases';
Expand Down
6 changes: 3 additions & 3 deletions web/src/compositions/useFavicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ watch(
);

function convertStatus(status: PipelineStatus): Status {
if (['blocked', 'declined', 'error', 'failure', 'killed'].includes(status)) {
if (['declined', 'error', 'failure', 'killed'].includes(status)) {
return 'error';
}

if (['started', 'running', 'pending'].includes(status)) {
if (['blocked', 'started', 'running', 'pending'].includes(status)) {
return 'pending';
}

if (['success', 'declined', 'error', 'failure', 'killed'].includes(status)) {
if (status === 'success') {
return 'success';
}

Expand Down
2 changes: 1 addition & 1 deletion woodpecker-go/woodpecker/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"net/http"
)

//go:generate mockery --name Client --output mocks --case underscore
//go:generate mockery --name Client --output mocks --case underscore --note "+build test"

// Client is used to communicate with a Woodpecker server.
type Client interface {
Expand Down
3 changes: 3 additions & 0 deletions woodpecker-go/woodpecker/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e484bdd

Please sign in to comment.