diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..272576a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* +!go.mod +!go.sum +!cmd +!pkg \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3eeabe2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +woodpecker-plugin-sonar +plugin-sonar +.scannerwork \ No newline at end of file diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml new file mode 100644 index 0000000..610945e --- /dev/null +++ b/.woodpecker/build.yaml @@ -0,0 +1,50 @@ +pipeline: + debug: + image: busybox + commands: + - env + sonar-tests: + image: git.kle.li/woodpecker/plugin-sonar:manual + settings: + sonar_url: https://sonar.kle.li + sonar_token: + from_secret: sonar_token + sonar_key: ${CI_REPO_OWNER}:${CI_REPO_NAME} + sonar_quality_enabled: true + branchanalysis: auto + + publish-docker-image: + image: woodpeckerci/plugin-docker-buildx + settings: + repo: git.kle.li/${CI_REPO} + platforms: linux/amd64 + tag: ${CI_COMMIT_BRANCH} + dockerfile: Dockerfile + registry: git.kle.li + username: + from_secret: gitea_user + password: + from_secret: gitea_token + when: + branch: [main, test, dev, release/*] + path: + exclude: ["*.md", "docs/**"] + ignore_message: "[FORCE CI]" + + publish-docker-tag-image: + image: woodpeckerci/plugin-docker-buildx + settings: + repo: git.kle.li/${CI_REPO} + platforms: linux/amd64 + tag: ${CI_COMMIT_TAG}, + dockerfile: Dockerfile + registry: git.kle.li + username: + from_secret: gitea_user + password: + from_secret: gitea_token + when: + tag: v* + path: + exclude: ["*.md", "docs/**"] + ignore_message: "[FORCE CI]" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9434322 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ + +FROM golang:1.19-alpine as go-build + +ARG GO_WORK="/go/src/git.kle.li/woodpecker/plugin-sonar" +RUN mkdir -p "${GO_WORK}" +WORKDIR "${GO_WORK}" +COPY ./ "${GO_WORK}/" + +RUN go mod download \ + && go mod verify \ + && go build -o /plugin-sonar ./cmd/main.go + + +FROM alpine:latest as sonar-prep +ARG SONAR_VERSION=4.7.0.2747 +ARG SONAR_SCANNER_CLI=sonar-scanner-cli-${SONAR_VERSION} +ARG SONAR_SCANNER=sonar-scanner-${SONAR_VERSION} +WORKDIR "/sonar" + +RUN apk add --no-cache --update curl unzip +RUN curl https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/${SONAR_SCANNER_CLI}.zip -so "/sonar/${SONAR_SCANNER_CLI}.zip" \ + && unzip "${SONAR_SCANNER_CLI}.zip" \ + && rm "${SONAR_SCANNER_CLI}.zip" \ + && pwd && ls -la \ + && mv "${SONAR_SCANNER}" "/sonar/sonar-scanner" \ + && echo "${SONAR_VERSION}" > "/sonar/sonar-scanner/version" + + +FROM alpine:latest + +# set / add low change items +WORKDIR /bin +RUN apk add --no-cache --update nodejs npm && rm -rf /var/cache/apk/* +ENV JAVA_HOME=/opt/java/openjdk +COPY --from=eclipse-temurin:17-jre-alpine $JAVA_HOME $JAVA_HOME +ENV PATH="${JAVA_HOME}/bin:${PATH}" + +# add plugin binary +RUN echo "/plugin-sonar $SONAR_SCANNER" +COPY --from=go-build "/plugin-sonar" /bin/ + +# add sonar download +COPY --from=sonar-prep "/sonar" /bin/ +ENV PATH $PATH:/bin/sonar-scanner/bin + +ENTRYPOINT [ "/bin/plugin-sonar" ] diff --git a/main.go b/cmd/main.go similarity index 96% rename from main.go rename to cmd/main.go index 2c43d5a..aefe1ca 100644 --- a/main.go +++ b/cmd/main.go @@ -20,9 +20,9 @@ import ( "os" "time" - plugLib "git.kle.li/gapodo/woodpecker-plugin-lib/urfave" - "git.kle.li/gapodo/woodpecker-plugin-sonar/pkg/plugin" - "git.kle.li/gapodo/woodpecker-plugin-sonar/pkg/sonar" + plugLib "git.kle.li/woodpecker/plugin-lib/urfave" + "git.kle.li/woodpecker/plugin-sonar/pkg/plugin" + "git.kle.li/woodpecker/plugin-sonar/pkg/sonar" "github.com/urfave/cli/v2" "go.uber.org/zap" ) @@ -41,7 +41,7 @@ func main() { Email: "gapodo@geekvoid.net", }, }, - Copyright: "(c) 2022 Michael Amann", + Copyright: "(c) 2022 Woodpecker Authors", Before: func(ctx *cli.Context) error { fmt.Fprintf(ctx.App.Writer, "Woodpecker-CI SonarQube plugin\n") return nil diff --git a/go.mod b/go.mod index a4da56b..75ab8d7 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ -module git.kle.li/gapodo/woodpecker-plugin-sonar +module git.kle.li/woodpecker/plugin-sonar go 1.19 require ( - git.kle.li/gapodo/woodpecker-plugin-lib v0.0.4 + git.kle.li/woodpecker/plugin-lib v0.0.5 github.com/pelletier/go-toml v1.9.5 github.com/urfave/cli/v2 v2.20.3 go.uber.org/zap v1.23.0 diff --git a/go.sum b/go.sum index a0754f2..a776605 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -git.kle.li/gapodo/woodpecker-plugin-lib v0.0.4 h1:+N8ZKk7NkpnCb3/nNTJwM8rjGlK1Wzi4uLzN7HY+wZM= -git.kle.li/gapodo/woodpecker-plugin-lib v0.0.4/go.mod h1:HcNuDYsML3ZwNi/pYrgpzwEqkV/e+sC2eaPpaLmmBLQ= +git.kle.li/woodpecker/plugin-lib v0.0.5 h1:sZXGK/zRB83YQu75b3zkh47svRwTWKUccV2jER8Sq7U= +git.kle.li/woodpecker/plugin-lib v0.0.5/go.mod h1:vzLk04kVG43eMrJjPIvFBE42UuG9QttZIXUm6HB5LUA= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index e01f6a6..93b8203 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -21,8 +21,8 @@ import ( "strconv" "strings" - "git.kle.li/gapodo/woodpecker-plugin-lib/common" - "git.kle.li/gapodo/woodpecker-plugin-sonar/pkg/sonar" + "git.kle.li/woodpecker/plugin-lib/common" + "git.kle.li/woodpecker/plugin-sonar/pkg/sonar" "github.com/pelletier/go-toml" "go.uber.org/zap" ) diff --git a/woodpecker-plugin-sonar b/woodpecker-plugin-sonar deleted file mode 100755 index fdbaeeb..0000000 Binary files a/woodpecker-plugin-sonar and /dev/null differ