From e357f3e52814dca0d6be2304f64ab8908d041c3a Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 14 Aug 2023 21:19:39 +0200 Subject: [PATCH] refactor: initial commit after rewrite to woodpecker --- .chglog/config.yml | 2 +- .dictionary | 2 +- .drone.yml | 297 ------------------ .github/settings.yml | 15 +- .gitignore | 2 +- .prettierignore | 1 - .woodpecker/build-binary.yml | 44 +++ .woodpecker/build-container.yml | 66 ++++ .woodpecker/docs.yml | 72 +++++ .woodpecker/notify.yml | 30 ++ .woodpecker/test.yml | 22 ++ ...rfile.multiarch => Containerfile.multiarch | 12 +- Makefile | 6 +- README.md | 24 +- _docs/content/_index.md | 42 +-- _docs/data/data.yaml | 4 +- cmd/drone-git-action/config.go | 14 +- cmd/drone-git-action/main.go | 55 +--- git/status.go | 4 +- go.mod | 15 +- go.sum | 40 +-- plugin/impl.go | 124 ++++---- plugin/plugin.go | 49 ++- plugin/utils.go | 6 +- 24 files changed, 429 insertions(+), 519 deletions(-) delete mode 100644 .drone.yml create mode 100644 .woodpecker/build-binary.yml create mode 100644 .woodpecker/build-container.yml create mode 100644 .woodpecker/docs.yml create mode 100644 .woodpecker/notify.yml create mode 100644 .woodpecker/test.yml rename Dockerfile.multiarch => Containerfile.multiarch (75%) diff --git a/.chglog/config.yml b/.chglog/config.yml index 0d12601..bfd5d09 100755 --- a/.chglog/config.yml +++ b/.chglog/config.yml @@ -2,7 +2,7 @@ style: github template: CHANGELOG.tpl.md info: title: CHANGELOG - repository_url: https://github.com/thegeeklab/drone-git-action + repository_url: https://github.com/thegeeklab/wp-git-action options: commit_groups: title_maps: diff --git a/.dictionary b/.dictionary index 4c1a95f..38f2549 100644 --- a/.dictionary +++ b/.dictionary @@ -2,5 +2,5 @@ api github url gh -drone-git-action +wp-git-action rsync diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index a4d885d..0000000 --- a/.drone.yml +++ /dev/null @@ -1,297 +0,0 @@ ---- -kind: pipeline -name: test - -platform: - os: linux - arch: amd64 - -steps: - - name: deps - image: golang:1.20 - commands: - - make deps - volumes: - - name: godeps - path: /go - - - name: lint - image: golang:1.20 - commands: - - make lint - volumes: - - name: godeps - path: /go - - - name: test - image: golang:1.20 - commands: - - make test - volumes: - - name: godeps - path: /go - -volumes: - - name: godeps - temp: {} - -trigger: - ref: - - refs/heads/main - - refs/tags/** - - refs/pull/** - ---- -kind: pipeline -name: build-binaries - -platform: - os: linux - arch: amd64 - -steps: - - name: build - image: techknowlogick/xgo:go-1.20.x - commands: - - ln -s /drone/src /source - - make release - - - name: executable - image: alpine - commands: - - $(find dist/ -executable -type f -iname ${DRONE_REPO_NAME}-linux-amd64) --help - - - name: changelog-generate - image: thegeeklab/git-chglog - commands: - - git fetch -tq - - git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased} - - - name: changelog-format - image: thegeeklab/alpine-tools - commands: - - prettier CHANGELOG.md - - prettier -w CHANGELOG.md - - - name: publish - image: plugins/github-release - settings: - api_key: - from_secret: github_token - files: - - dist/* - note: CHANGELOG.md - overwrite: true - title: ${DRONE_TAG} - when: - ref: - - refs/tags/** - -trigger: - ref: - - refs/heads/main - - refs/tags/** - - refs/pull/** - -depends_on: - - test - ---- -kind: pipeline -name: build-container - -platform: - os: linux - arch: amd64 - -steps: - - name: dryrun - image: thegeeklab/drone-docker-buildx:23 - settings: - dockerfile: Dockerfile.multiarch - dry_run: true - platforms: - - linux/amd64 - - linux/arm64 - - linux/arm/v7 - - linux/arm/v6 - provenance: false - repo: thegeeklab/${DRONE_REPO_NAME} - when: - ref: - - refs/pull/** - - - name: publish-dockerhub - image: thegeeklab/drone-docker-buildx:23 - settings: - auto_tag: true - dockerfile: Dockerfile.multiarch - password: - from_secret: docker_password - platforms: - - linux/amd64 - - linux/arm64 - - linux/arm/v7 - - linux/arm/v6 - provenance: false - repo: thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: docker_username - when: - ref: - - refs/heads/main - - refs/tags/** - depends_on: - - dryrun - - - name: publish-quay - image: thegeeklab/drone-docker-buildx:23 - settings: - auto_tag: true - dockerfile: Dockerfile.multiarch - password: - from_secret: quay_password - platforms: - - linux/amd64 - - linux/arm64 - - linux/arm/v7 - - linux/arm/v6 - provenance: false - registry: quay.io - repo: quay.io/thegeeklab/${DRONE_REPO_NAME} - username: - from_secret: quay_username - when: - ref: - - refs/heads/main - - refs/tags/** - depends_on: - - dryrun - -trigger: - ref: - - refs/heads/main - - refs/tags/** - - refs/pull/** - -depends_on: - - test - ---- -kind: pipeline -name: docs - -platform: - os: linux - arch: amd64 - -concurrency: - limit: 1 - -steps: - - name: markdownlint - image: thegeeklab/markdownlint-cli - commands: - - markdownlint 'docs/content/**/*.md' 'README.md' 'CONTRIBUTING.md' - - - name: spellcheck - image: thegeeklab/alpine-tools - commands: - - spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions - environment: - FORCE_COLOR: true - NPM_CONFIG_LOGLEVEL: error - - - name: publish - image: thegeeklab/drone-git-action - settings: - action: - - pages - author_email: bot@thegeeklab.de - author_name: thegeeklab-bot - branch: docs - message: auto-update documentation - netrc_password: - from_secret: github_token - pages_directory: _docs/ - when: - ref: - - refs/heads/main - -trigger: - ref: - - refs/heads/main - - refs/tags/** - - refs/pull/** - -depends_on: - - build-binaries - - build-container - ---- -kind: pipeline -name: notifications - -platform: - os: linux - arch: amd64 - -steps: - - name: pushrm-dockerhub - image: chko/docker-pushrm:1 - environment: - DOCKER_PASS: - from_secret: docker_password - DOCKER_USER: - from_secret: docker_username - PUSHRM_FILE: README.md - PUSHRM_SHORT: Drone plugin to execute git actions - PUSHRM_TARGET: thegeeklab/${DRONE_REPO_NAME} - when: - status: - - success - - - name: pushrm-quay - image: chko/docker-pushrm:1 - environment: - APIKEY__QUAY_IO: - from_secret: quay_token - PUSHRM_FILE: README.md - PUSHRM_TARGET: quay.io/thegeeklab/${DRONE_REPO_NAME} - when: - status: - - success - - - name: matrix - image: thegeeklab/drone-matrix - settings: - homeserver: - from_secret: matrix_homeserver - password: - from_secret: matrix_password - roomid: - from_secret: matrix_roomid - template: "Status: **{{ .Build.Status }}**
Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}
Message: {{ .Commit.Message.Title }}" - username: - from_secret: matrix_username - when: - status: - - success - - failure - -trigger: - ref: - - refs/heads/main - - refs/tags/** - status: - - success - - failure - -depends_on: - - docs - ---- -kind: signature -hmac: f05ebaf01c9bc2d0d7937b58d7e70a58d00512b67f516bf0f0816e9138df46a3 - -... diff --git a/.github/settings.yml b/.github/settings.yml index 7d8a68d..429581a 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -1,8 +1,8 @@ repository: - name: drone-git-action - description: Drone plugin to execute git actions - homepage: https://drone-plugin-index.geekdocs.de/plugins/drone-git-action - topics: drone, drone-plugin + name: wp-git-action + description: Woodpecker CI plugin to execute git actions + homepage: https://wp-plugin-index.geekdocs.de/plugins/wp-git-action + topics: woodpecker, wp-plugin private: false has_issues: true @@ -51,8 +51,11 @@ branches: required_status_checks: strict: false contexts: - - continuous-integration/drone/pr - enforce_admins: true + - ci/woodpecker/pr/test + - ci/woodpecker/pr/build-binary + - ci/woodpecker/pr/build-container + - ci/woodpecker/pr/docs + enforce_admins: false required_linear_history: true restrictions: null - name: docs diff --git a/.gitignore b/.gitignore index 7eedee7..d8e597a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /dist/ /release/ -/drone-git-action* +/wp-git-action* coverage.out CHANGELOG.md diff --git a/.prettierignore b/.prettierignore index 23a4f05..135c35d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,2 @@ -.drone.yml *.tpl.md LICENSE diff --git a/.woodpecker/build-binary.yml b/.woodpecker/build-binary.yml new file mode 100644 index 0000000..21ee508 --- /dev/null +++ b/.woodpecker/build-binary.yml @@ -0,0 +1,44 @@ +--- +when: + - event: [pull_request, tag] + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + +steps: + build: + image: docker.io/techknowlogick/xgo:go-1.20.x + commands: + - ln -s $(pwd) /source + - make release + + executable: + image: docker.io/library/alpine + commands: + - $(find dist/ -executable -type f -iname ${CI_REPO_NAME}-linux-amd64) --help + + changelog-generate: + image: quay.io/thegeeklab/git-chglog + commands: + - git fetch -tq + - git-chglog --no-color --no-emoji -o CHANGELOG.md ${CI_COMMIT_TAG:---next-tag unreleased unreleased} + + changelog-format: + image: quay.io/thegeeklab/alpine-tools + commands: + - prettier CHANGELOG.md + - prettier -w CHANGELOG.md + + publish-github: + image: docker.io/plugins/github-release + settings: + api_key: + from_secret: github_token + note: CHANGELOG.md + overwrite: true + title: ${CI_COMMIT_TAG} + when: + - event: [tag] + +depends_on: + - test diff --git a/.woodpecker/build-container.yml b/.woodpecker/build-container.yml new file mode 100644 index 0000000..8f39dab --- /dev/null +++ b/.woodpecker/build-container.yml @@ -0,0 +1,66 @@ +--- +when: + - event: [pull_request, tag] + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + +steps: + dryrun: + image: quay.io/thegeeklab/wp-docker-buildx + settings: + containerfile: Containerfile.multiarch + dry_run: true + platforms: + - linux/amd64 + - linux/arm64 + provenance: false + repo: ${CI_REPO} + when: + - event: [pull_request] + + publish-dockerhub: + group: container + image: quay.io/thegeeklab/wp-docker-buildx + settings: + auto_tag: true + containerfile: Containerfile.multiarch + password: + from_secret: docker_password + platforms: + - linux/amd64 + - linux/arm64 + provenance: false + repo: ${CI_REPO} + username: + from_secret: docker_username + when: + - event: [tag] + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + + publish-quay: + group: container + image: quay.io/thegeeklab/wp-docker-buildx + settings: + auto_tag: true + containerfile: Containerfile.multiarch + password: + from_secret: quay_password + platforms: + - linux/amd64 + - linux/arm64 + provenance: false + registry: quay.io + repo: quay.io/${CI_REPO} + username: + from_secret: quay_username + when: + - event: [tag] + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + +depends_on: + - test diff --git a/.woodpecker/docs.yml b/.woodpecker/docs.yml new file mode 100644 index 0000000..9ea4401 --- /dev/null +++ b/.woodpecker/docs.yml @@ -0,0 +1,72 @@ +--- +when: + - event: [pull_request, tag] + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + +steps: + markdownlint: + image: quay.io/thegeeklab/markdownlint-cli + commands: + - markdownlint 'README.md' 'CONTRIBUTING.md' + + spellcheck: + image: quay.io/thegeeklab/alpine-tools + commands: + - spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions + environment: + FORCE_COLOR: "true" + NPM_CONFIG_LOGLEVEL: "error" + + # publish: + # image: quay.io/thegeeklab/drone-git-action + # settings: + # action: + # - pages + # author_email: bot@thegeeklab.de + # author_name: thegeeklab-bot + # branch: docs + # message: auto-update documentation + # netrc_password: + # from_secret: github_token + # pages_directory: _docs/ + # when: + # - event: [push, manual] + # branch: + # - ${CI_REPO_DEFAULT_BRANCH} + + pushrm-dockerhub: + image: docker.io/chko/docker-pushrm:1 + secrets: + - source: docker_password + target: DOCKER_PASS + - source: docker_username + target: DOCKER_USER + environment: + PUSHRM_FILE: README.md + PUSHRM_SHORT: Woodpecker CI plugin to execute git actions + PUSHRM_TARGET: ${CI_REPO} + when: + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + status: [success] + + pushrm-quay: + image: docker.io/chko/docker-pushrm:1 + secrets: + - source: quay_token + target: APIKEY__QUAY_IO + environment: + PUSHRM_FILE: README.md + PUSHRM_TARGET: quay.io/${CI_REPO} + when: + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + status: [success] + +depends_on: + - build-binary + - build-container diff --git a/.woodpecker/notify.yml b/.woodpecker/notify.yml new file mode 100644 index 0000000..9028f78 --- /dev/null +++ b/.woodpecker/notify.yml @@ -0,0 +1,30 @@ +--- +when: + - event: [tag] + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + +runs_on: [success, failure] + +steps: + matrix: + image: quay.io/thegeeklab/drone-matrix + settings: + homeserver: + from_secret: matrix_homeserver + password: + from_secret: matrix_password + roomid: + from_secret: matrix_roomid + template: >- + Status: **{{ .Build.Status }}**
+ Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}
+ Message: {{ .Commit.Message.Title }} + username: + from_secret: matrix_username + when: + - status: [success, failure] + +depends_on: + - docs diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml new file mode 100644 index 0000000..01952de --- /dev/null +++ b/.woodpecker/test.yml @@ -0,0 +1,22 @@ +--- +when: + - event: [pull_request, tag] + - event: [push, manual] + branch: + - ${CI_REPO_DEFAULT_BRANCH} + +steps: + deps: + image: docker.io/library/golang:1.20 + commands: + - make deps + + lint: + image: docker.io/library/golang:1.20 + commands: + - make lint + + test: + image: docker.io/library/golang:1.20 + commands: + - make test diff --git a/Dockerfile.multiarch b/Containerfile.multiarch similarity index 75% rename from Dockerfile.multiarch rename to Containerfile.multiarch index d424f78..b1bb6c6 100644 --- a/Dockerfile.multiarch +++ b/Containerfile.multiarch @@ -12,14 +12,14 @@ FROM alpine:3.18@sha256:7144f7bab3d4c2648d7e59409f15ec52a18006a128c733fcff20d3a4 LABEL maintainer="Robert Kaussow " LABEL org.opencontainers.image.authors="Robert Kaussow " -LABEL org.opencontainers.image.title="drone-git-action" -LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-git-action" -LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-git-action" -LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-git-action" +LABEL org.opencontainers.image.title="wp-git-action" +LABEL org.opencontainers.image.url="https://github.com/thegeeklab/wp-git-action" +LABEL org.opencontainers.image.source="https://github.com/thegeeklab/wp-git-action" +LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/wp-git-action" RUN apk --update add --no-cache git rsync && \ rm -rf /var/cache/apk/* && \ rm -rf /tmp/* -COPY --from=build /src/dist/drone-git-action /bin/drone-git-action -ENTRYPOINT ["/bin/drone-git-action"] +COPY --from=build /src/dist/wp-git-action /bin/wp-git-action +ENTRYPOINT ["/bin/wp-git-action"] diff --git a/Makefile b/Makefile index b27b3f9..f4bd114 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ GOFUMPT_PACKAGE_VERSION := v0.5.0 # renovate: datasource=github-releases depName=golangci/golangci-lint GOLANGCI_LINT_PACKAGE_VERSION := v1.53.3 -EXECUTABLE := drone-git-action +EXECUTABLE := wp-git-action DIST := dist DIST_DIRS := $(DIST) @@ -30,8 +30,8 @@ endif TAGS ?= netgo,osusergo ifndef VERSION - ifneq ($(DRONE_TAG),) - VERSION ?= $(subst v,,$(DRONE_TAG)) + ifneq ($(CI_COMMIT_TAG),) + VERSION ?= $(subst v,,$(CI_COMMIT_TAG)) else VERSION ?= $(shell git rev-parse --short HEAD) endif diff --git a/README.md b/README.md index a97cf96..34e7389 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ -# drone-git-action +# wp-git-action -Drone plugin to execute git actions +Woodpecker CI plugin to execute git actions -[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-git-action?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-git-action) -[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/drone-git-action) -[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/drone-git-action) -[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/drone-git-action)](https://goreportcard.com/report/github.com/thegeeklab/drone-git-action) -[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-git-action)](https://github.com/thegeeklab/drone-git-action/graphs/contributors) -[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-git-action) -[![License: Apache-2.0](https://img.shields.io/github/license/thegeeklab/drone-git-action)](https://github.com/thegeeklab/drone-git-action/blob/main/LICENSE) +[![Build Status](https://ci.thegeeklab.de/api/badges/thegeeklab/wp-git-action/status.svg)](https://ci.thegeeklab.de/repos/thegeeklab/wp-git-action) +[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/wp-git-action) +[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/wp-git-action) +[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/wp-git-action)](https://goreportcard.com/report/github.com/thegeeklab/wp-git-action) +[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/wp-git-action)](https://github.com/thegeeklab/wp-git-action/graphs/contributors) +[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/wp-git-action) +[![License: Apache-2.0](https://img.shields.io/github/license/thegeeklab/wp-git-action)](https://github.com/thegeeklab/wp-git-action/blob/main/LICENSE) -Drone plugin to execute git actions. You can find the full documentation at [https://drone-plugin-index.geekdocs.de](https://drone-plugin-index.geekdocs.de/plugins/drone-git-action). +Woodpecker CI plugin to execute git actions. You can find the full documentation at [https://wp-plugin-index.geekdocs.de](https://wp-plugin-index.geekdocs.de/plugins/wp-git-action). ## Contributors -Special thanks to all [contributors](https://github.com/thegeeklab/drone-git-action/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/drone-git-action/blob/main/CONTRIBUTING.md). +Special thanks to all [contributors](https://github.com/thegeeklab/wp-git-action/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/wp-git-action/blob/main/CONTRIBUTING.md). ## License -This project is licensed under the Apache-2.0 License - see the [LICENSE](https://github.com/thegeeklab/drone-git-action/blob/main/LICENSE) file for details. +This project is licensed under the Apache-2.0 License - see the [LICENSE](https://github.com/thegeeklab/wp-git-action/blob/main/LICENSE) file for details. diff --git a/_docs/content/_index.md b/_docs/content/_index.md index 21cdf06..f895443 100644 --- a/_docs/content/_index.md +++ b/_docs/content/_index.md @@ -1,15 +1,15 @@ --- -title: drone-git-action +title: wp-git-action --- -[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-git-action?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-git-action) -[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/drone-git-action) -[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/drone-git-action) -[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-git-action)](https://github.com/thegeeklab/drone-git-action/graphs/contributors) -[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-git-action) -[![License: MIT](https://img.shields.io/github/license/thegeeklab/drone-git-action)](https://github.com/thegeeklab/drone-git-action/blob/main/LICENSE) +[![Build Status](https://img.shields.io/wp/build/thegeeklab/wp-git-action?logo=wp&server=https%3A%2F%2Fwp.thegeeklab.de)](https://wp.thegeeklab.de/thegeeklab/wp-git-action) +[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/wp-git-action) +[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/wp-git-action) +[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/wp-git-action)](https://github.com/thegeeklab/wp-git-action/graphs/contributors) +[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/wp-git-action) +[![License: MIT](https://img.shields.io/github/license/thegeeklab/wp-git-action)](https://github.com/thegeeklab/wp-git-action/blob/main/LICENSE) -Drone plugin to execute git actions. +Woodpecker CI plugin to execute git actions. @@ -25,7 +25,7 @@ name: default steps: - name: commit changelog - image: thegeeklab/drone-git-action + image: thegeeklab/wp-git-action settings: action: - commit @@ -40,7 +40,7 @@ steps: -{{< propertylist name=drone-git-action.data sort=name >}} +{{< propertylist name=wp-git-action.data sort=name >}} @@ -56,7 +56,7 @@ name: default steps: - name: publish - image: thegeeklab/drone-git-action + image: thegeeklab/wp-git-action settings: action: - pages @@ -73,31 +73,17 @@ steps: Build the binary with the following command: ```Shell -export GOOS=linux -export GOARCH=amd64 -export CGO_ENABLED=0 -export GO111MODULE=on - make build ``` -Build the Docker image with the following command: +Build the Container image with the following command: ```Shell -docker build --file docker/Dockerfile.amd64 --tag thegeeklab/drone-git-action . +docker build --file Containerfile.multiarch --tag thegeeklab/wp-git-action . ``` ## Test ```Shell -docker run --rm \ - -e DRONE_BUILD_EVENT=pull_request \ - -e DRONE_REPO_OWNER=octocat \ - -e DRONE_REPO_NAME=foo \ - -e DRONE_PULL_REQUEST=1 - -e PLUGIN_API_KEY=abc123 \ - -e PLUGIN_MESSAGE="Demo comment" \ - -v $(pwd):$(pwd) \ - -w $(pwd) \ - thegeeklab/drone-git-action + ``` diff --git a/_docs/data/data.yaml b/_docs/data/data.yaml index 7a3d332..986bddd 100644 --- a/_docs/data/data.yaml +++ b/_docs/data/data.yaml @@ -5,8 +5,8 @@ properties: Git actions to be executed. Supported actions: `clone | commit | push | pages`. Specified actions are executed in the specified order - **clone:** Clones the repository in `remote_url` and checks out the `branch` to `path`. - - **commit:** Adds a commit to the default drone repository or the repository in `remote_url`. - - **push:** Pushes all commits to the default drone repository or the repository set in `remote_url`. + - **commit:** Adds a commit to the default repository or the repository in `remote_url`. + - **push:** Pushes all commits to the default repository or the repository set in `remote_url`. - **pages:** The `pages` action is a special action that cannot be combined with other actions. It is intended for use for GitHub pages. It synchronizes the contents of `pages_directory` with the target `branch` using `rsync` and pushes the changes automatically. required: true diff --git a/cmd/drone-git-action/config.go b/cmd/drone-git-action/config.go index 7fcdc3a..d5c44f1 100644 --- a/cmd/drone-git-action/config.go +++ b/cmd/drone-git-action/config.go @@ -1,7 +1,7 @@ package main import ( - "github.com/thegeeklab/drone-git-action/plugin" + "github.com/thegeeklab/wp-git-action/plugin" "github.com/urfave/cli/v2" ) @@ -19,7 +19,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { &cli.StringFlag{ Name: "author-name", Usage: "git author name", - EnvVars: []string{"PLUGIN_AUTHOR_NAME", "DRONE_COMMIT_AUTHOR"}, + EnvVars: []string{"PLUGIN_AUTHOR_NAME", "CI_COMMIT_AUTHOR"}, Destination: &settings.Repo.Author.Name, Required: true, Category: category, @@ -27,7 +27,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { &cli.StringFlag{ Name: "author-email", Usage: "git author email", - EnvVars: []string{"PLUGIN_AUTHOR_EMAIL", "DRONE_COMMIT_AUTHOR_EMAIL"}, + EnvVars: []string{"PLUGIN_AUTHOR_EMAIL", "CI_COMMIT_AUTHOR_EMAIL"}, Destination: &settings.Repo.Author.Email, Required: true, Category: category, @@ -36,7 +36,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { &cli.StringFlag{ Name: "netrc.machine", Usage: "netrc remote machine name", - EnvVars: []string{"PLUGIN_NETRC_MACHINE", "DRONE_NETRC_MACHINE"}, + EnvVars: []string{"PLUGIN_NETRC_MACHINE", "CI_NETRC_MACHINE"}, Destination: &settings.Netrc.Machine, Value: "github.com", Category: category, @@ -44,7 +44,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { &cli.StringFlag{ Name: "netrc.username", Usage: "netrc login user on the remote machine", - EnvVars: []string{"PLUGIN_NETRC_USERNAME", "DRONE_NETRC_USERNAME"}, + EnvVars: []string{"PLUGIN_NETRC_USERNAME", "CI_NETRC_USERNAME"}, Destination: &settings.Netrc.Login, Value: "token", Category: category, @@ -52,7 +52,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { &cli.StringFlag{ Name: "netrc.password", Usage: "netrc login password on the remote machine", - EnvVars: []string{"PLUGIN_NETRC_PASSWORD", "DRONE_NETRC_PASSWORD"}, + EnvVars: []string{"PLUGIN_NETRC_PASSWORD", "CI_NETRC_PASSWORD"}, Destination: &settings.Netrc.Password, Category: category, }, @@ -67,7 +67,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { &cli.StringFlag{ Name: "remote-url", Usage: "url of the remote repository", - EnvVars: []string{"PLUGIN_REMOTE_URL", "DRONE_REMOTE_URL"}, + EnvVars: []string{"PLUGIN_REMOTE_URL", "CI_REPO_CLONE_URL"}, Destination: &settings.Repo.RemoteURL, Category: category, }, diff --git a/cmd/drone-git-action/main.go b/cmd/drone-git-action/main.go index 8ee2888..a65e17d 100644 --- a/cmd/drone-git-action/main.go +++ b/cmd/drone-git-action/main.go @@ -2,13 +2,9 @@ package main import ( "fmt" - "os" - "github.com/joho/godotenv" - "github.com/sirupsen/logrus" - "github.com/thegeeklab/drone-git-action/plugin" - "github.com/thegeeklab/drone-plugin-lib/v2/urfave" - "github.com/urfave/cli/v2" + "github.com/thegeeklab/wp-git-action/plugin" + wp "github.com/thegeeklab/wp-plugin-go/plugin" ) //nolint:gochecknoglobals @@ -19,46 +15,13 @@ var ( func main() { settings := &plugin.Settings{} - - if _, err := os.Stat("/run/drone/env"); err == nil { - _ = godotenv.Overload("/run/drone/env") - } - - cli.VersionPrinter = func(c *cli.Context) { - fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate) + options := wp.Options{ + Name: "wp-git-action", + Description: "Perform git operations.", + Version: BuildVersion, + VersionMetadata: fmt.Sprintf("date=%s", BuildDate), + Flags: settingsFlags(settings, wp.FlagsPluginCategory), } - app := &cli.App{ - Name: "drone-git-action", - Usage: "handle comments to github issues or pull requests", - Version: BuildVersion, - Flags: append(settingsFlags(settings, urfave.FlagsPluginCategory), urfave.Flags()...), - Action: run(settings), - } - - if err := app.Run(os.Args); err != nil { - logrus.Fatal(err) - } -} - -func run(settings *plugin.Settings) cli.ActionFunc { - return func(ctx *cli.Context) error { - urfave.LoggingFromContext(ctx) - - plugin := plugin.New( - *settings, - urfave.PipelineFromContext(ctx), - urfave.NetworkFromContext(ctx), - ) - - if err := plugin.Validate(); err != nil { - return fmt.Errorf("validation failed: %w", err) - } - - if err := plugin.Execute(); err != nil { - return fmt.Errorf("execution failed: %w", err) - } - - return nil - } + plugin.New(options, settings).Run() } diff --git a/git/status.go b/git/status.go index 7bca2f1..c4bc3e6 100644 --- a/git/status.go +++ b/git/status.go @@ -4,7 +4,7 @@ import ( "bytes" "os" - "github.com/sirupsen/logrus" + "github.com/rs/zerolog/log" "golang.org/x/sys/execabs" ) @@ -35,7 +35,7 @@ func IsDirty(repo Repository) bool { } if res.Len() > 0 { - logrus.Debug(res.String()) + log.Debug().Msg(res.String()) return true } diff --git a/go.mod b/go.mod index a9c2872..5994ad8 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,20 @@ -module github.com/thegeeklab/drone-git-action +module github.com/thegeeklab/wp-git-action go 1.20 require ( - github.com/joho/godotenv v1.5.1 - github.com/sirupsen/logrus v1.9.3 - github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4 - github.com/urfave/cli/v2 v2.25.5 - golang.org/x/sys v0.10.0 + github.com/rs/zerolog v1.30.0 + github.com/thegeeklab/wp-plugin-go v0.1.0 + github.com/urfave/cli/v2 v2.25.7 + golang.org/x/sys v0.11.0 ) require ( github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/joho/godotenv v1.5.1 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/net v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index 78f9ed1..3b94ef8 100644 --- a/go.sum +++ b/go.sum @@ -1,28 +1,28 @@ +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= 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= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= +github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4 h1:Quzrike/xRAR0izxQ0d+ocJyIUm4h1497Oyo9grcRzg= -github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4/go.mod h1:qWVUZCmwL0Ntwa/hvyqM03EeIr1ReBR2XJsmIc7MGus= -github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc= -github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/thegeeklab/wp-plugin-go v0.1.0 h1:X00VQDaaYhiemtms8fz+pT852Uv2wdT6bbIVdqpbf9A= +github.com/thegeeklab/wp-plugin-go v0.1.0/go.mod h1:7PWAZiTnZ2fAvjsedopQJ6w873KuSxUWsAml1Yib8a0= +github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= +github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/plugin/impl.go b/plugin/impl.go index cfa75b4..7a8ff99 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -1,37 +1,16 @@ package plugin import ( + "context" "errors" "fmt" "os" "path/filepath" - "github.com/thegeeklab/drone-git-action/git" + "github.com/thegeeklab/wp-git-action/git" "github.com/urfave/cli/v2" ) -type Netrc struct { - Machine string - Login string - Password string -} - -type Pages struct { - Directory string - Exclude cli.StringSlice - Delete bool -} - -// Settings for the Plugin. -type Settings struct { - Action cli.StringSlice - SSHKey string - - Netrc Netrc - Pages Pages - Repo git.Repository -} - var ( ErrAuthSourceNotSet = errors.New("either SSH key or netrc password is required") ErrPagesDirectoryNotExist = errors.New("pages directory must exist") @@ -42,53 +21,68 @@ var ( ErrGitCloneDestintionNotValid = errors.New("destination not valid") ) +// Execute provides the implementation of the plugin. +// +//nolint:revive +func (p *Plugin) run(ctx context.Context, cCtx *cli.Context) error { + if err := p.Validate(); err != nil { + return fmt.Errorf("validation failed: %w", err) + } + + if err := p.Execute(); err != nil { + return fmt.Errorf("execution failed: %w", err) + } + + return nil +} + // Validate handles the settings validation of the plugin. func (p *Plugin) Validate() error { var err error - p.settings.Repo.Autocorrect = "never" - p.settings.Repo.RemoteName = "origin" - p.settings.Repo.Add = "" + p.Settings.Repo.Autocorrect = "never" + p.Settings.Repo.RemoteName = "origin" + p.Settings.Repo.Add = "" - if p.settings.Repo.WorkDir == "" { - p.settings.Repo.WorkDir, err = os.Getwd() + if p.Settings.Repo.WorkDir == "" { + p.Settings.Repo.WorkDir, err = os.Getwd() } if err != nil { return err } - for _, action := range p.settings.Action.Value() { + for _, action := range p.Settings.Action.Value() { switch action { case "clone": continue case "commit": continue case "push": - if p.settings.SSHKey == "" && p.settings.Netrc.Password == "" { + if p.Settings.SSHKey == "" && p.Settings.Netrc.Password == "" { return ErrAuthSourceNotSet } case "pages": - p.settings.Pages.Directory = filepath.Join(p.settings.Repo.WorkDir, p.settings.Pages.Directory) - p.settings.Repo.WorkDir = filepath.Join(p.settings.Repo.WorkDir, ".tmp") + p.Settings.Pages.Directory = filepath.Join(p.Settings.Repo.WorkDir, p.Settings.Pages.Directory) + p.Settings.Repo.WorkDir = filepath.Join(p.Settings.Repo.WorkDir, ".tmp") - if _, err := os.Stat(p.settings.Pages.Directory); os.IsNotExist(err) { - return fmt.Errorf("%w: '%s' not found", ErrPagesDirectoryNotExist, p.settings.Pages.Directory) + if _, err := os.Stat(p.Settings.Pages.Directory); os.IsNotExist(err) { + return fmt.Errorf("%w: '%s' not found", ErrPagesDirectoryNotExist, p.Settings.Pages.Directory) } - if info, _ := os.Stat(p.settings.Pages.Directory); !info.IsDir() { - return fmt.Errorf("%w: '%s' not a directory", ErrPagesDirectoryNotValid, p.settings.Pages.Directory) + if info, _ := os.Stat(p.Settings.Pages.Directory); !info.IsDir() { + return fmt.Errorf("%w: '%s' not a directory", ErrPagesDirectoryNotValid, p.Settings.Pages.Directory) } - if p.settings.SSHKey == "" && p.settings.Netrc.Password == "" { + if p.Settings.SSHKey == "" && p.Settings.Netrc.Password == "" { return ErrAuthSourceNotSet } - if p.settings.Pages.Directory == "" { + if p.Settings.Pages.Directory == "" { return ErrPagesSourceNotSet } - if len(p.settings.Action.Value()) > 1 { + if len(p.Settings.Action.Value()) > 1 { return ErrPagesActionNotExclusive } default: @@ -124,33 +118,33 @@ func (p *Plugin) Execute() error { return err } - if err := git.ConfigAutocorrect(p.settings.Repo).Run(); err != nil { + if err := git.ConfigAutocorrect(p.Settings.Repo).Run(); err != nil { return err } - if err := git.ConfigUserName(p.settings.Repo).Run(); err != nil { + if err := git.ConfigUserName(p.Settings.Repo).Run(); err != nil { return err } - if err := git.ConfigUserEmail(p.settings.Repo).Run(); err != nil { + if err := git.ConfigUserEmail(p.Settings.Repo).Run(); err != nil { return err } - if err := git.ConfigSSLVerify(p.settings.Repo).Run(); err != nil { + if err := git.ConfigSSLVerify(p.Settings.Repo).Run(); err != nil { return err } - if p.settings.SSHKey != "" { - if err := git.WriteSSHKey(p.settings.SSHKey); err != nil { + if p.Settings.SSHKey != "" { + if err := git.WriteSSHKey(p.Settings.SSHKey); err != nil { return err } } - if err := git.WriteNetrc(p.settings.Netrc.Machine, p.settings.Netrc.Login, p.settings.Netrc.Password); err != nil { + if err := git.WriteNetrc(p.Settings.Netrc.Machine, p.Settings.Netrc.Login, p.Settings.Netrc.Password); err != nil { return err } - for _, action := range p.settings.Action.Value() { + for _, action := range p.Settings.Action.Value() { switch action { case "clone": if err := p.handleClone(); err != nil { @@ -176,54 +170,54 @@ func (p *Plugin) Execute() error { // handleInit initializes the repository. func (p *Plugin) handleInit() error { - path := filepath.Join(p.settings.Repo.WorkDir, ".git") + path := filepath.Join(p.Settings.Repo.WorkDir, ".git") - if err := os.MkdirAll(p.settings.Repo.WorkDir, os.ModePerm); err != nil { + if err := os.MkdirAll(p.Settings.Repo.WorkDir, os.ModePerm); err != nil { return err } if _, err := os.Stat(path); !os.IsNotExist(err) { - p.settings.Repo.InitExists = true + p.Settings.Repo.InitExists = true return nil } - return execute(git.Init(p.settings.Repo)) + return execute(git.Init(p.Settings.Repo)) } // HandleClone clones remote. func (p *Plugin) handleClone() error { - if p.settings.Repo.InitExists { - return fmt.Errorf("%w: %s exists and not empty", ErrGitCloneDestintionNotValid, p.settings.Repo.WorkDir) + if p.Settings.Repo.InitExists { + return fmt.Errorf("%w: %s exists and not empty", ErrGitCloneDestintionNotValid, p.Settings.Repo.WorkDir) } - if p.settings.Repo.RemoteURL != "" { - if err := execute(git.RemoteAdd(p.settings.Repo)); err != nil { + if p.Settings.Repo.RemoteURL != "" { + if err := execute(git.RemoteAdd(p.Settings.Repo)); err != nil { return err } } - if err := execute(git.FetchSource(p.settings.Repo)); err != nil { + if err := execute(git.FetchSource(p.Settings.Repo)); err != nil { return err } - return execute(git.CheckoutHead(p.settings.Repo)) + return execute(git.CheckoutHead(p.Settings.Repo)) } // HandleCommit commits changes locally. func (p *Plugin) handleCommit() error { - if err := execute(git.Add(p.settings.Repo)); err != nil { + if err := execute(git.Add(p.Settings.Repo)); err != nil { return err } - if err := execute(git.TestCleanTree(p.settings.Repo)); err != nil { - if err := execute(git.ForceCommit(p.settings.Repo)); err != nil { + if err := execute(git.TestCleanTree(p.Settings.Repo)); err != nil { + if err := execute(git.ForceCommit(p.Settings.Repo)); err != nil { return err } } - if p.settings.Repo.EmptyCommit { - if err := execute(git.EmptyCommit(p.settings.Repo)); err != nil { + if p.Settings.Repo.EmptyCommit { + if err := execute(git.EmptyCommit(p.Settings.Repo)); err != nil { return err } } @@ -233,19 +227,19 @@ func (p *Plugin) handleCommit() error { // HandlePush pushs changes to remote. func (p *Plugin) handlePush() error { - return execute(git.RemotePush(p.settings.Repo)) + return execute(git.RemotePush(p.Settings.Repo)) } // HandlePages syncs, commits and pushes the changes from the pages directory to the pages branch. func (p *Plugin) handlePages() error { - defer os.RemoveAll(p.settings.Repo.WorkDir) + defer os.RemoveAll(p.Settings.Repo.WorkDir) if err := p.handleClone(); err != nil { return err } if err := execute( - rsyncDirectories(p.settings.Pages, p.settings.Repo), + rsyncDirectories(p.Settings.Pages, p.Settings.Repo), ); err != nil { return err } diff --git a/plugin/plugin.go b/plugin/plugin.go index 85551fc..1006235 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -1,21 +1,46 @@ package plugin import ( - "github.com/thegeeklab/drone-plugin-lib/v2/drone" + "github.com/thegeeklab/wp-git-action/git" + wp "github.com/thegeeklab/wp-plugin-go/plugin" + "github.com/urfave/cli/v2" ) -// Plugin implements drone.Plugin to provide the plugin implementation. +// Plugin implements provide the plugin implementation. type Plugin struct { - settings Settings - pipeline drone.Pipeline - network drone.Network + *wp.Plugin + Settings *Settings } -// New initializes a plugin from the given Settings, Pipeline, and Network. -func New(settings Settings, pipeline drone.Pipeline, network drone.Network) *Plugin { - return &Plugin{ - settings: settings, - pipeline: pipeline, - network: network, - } +// Settings for the Plugin. +type Settings struct { + Action cli.StringSlice + SSHKey string + + Netrc Netrc + Pages Pages + Repo git.Repository +} + +type Netrc struct { + Machine string + Login string + Password string +} + +type Pages struct { + Directory string + Exclude cli.StringSlice + Delete bool +} + +func New(options wp.Options, settings *Settings) *Plugin { + p := &Plugin{} + + options.Execute = p.run + + p.Plugin = wp.New(options) + p.Settings = settings + + return p } diff --git a/plugin/utils.go b/plugin/utils.go index d0914a0..a95c295 100644 --- a/plugin/utils.go +++ b/plugin/utils.go @@ -4,14 +4,14 @@ import ( "os" "strings" - "github.com/sirupsen/logrus" - "github.com/thegeeklab/drone-git-action/git" + "github.com/rs/zerolog/log" + "github.com/thegeeklab/wp-git-action/git" "golang.org/x/sys/execabs" ) // helper function to simply wrap os execte command. func execute(cmd *execabs.Cmd) error { - logrus.Debug("+", strings.Join(cmd.Args, " ")) + log.Debug().Msgf("+ %s", strings.Join(cmd.Args, " ")) cmd.Env = os.Environ() cmd.Stderr = os.Stderr