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

Fix version info #13

Merged
merged 8 commits into from
Dec 23, 2021
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
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ vendor/

coverage.out
plugin-git

.vscode
5 changes: 5 additions & 0 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ pipeline:
commands:
- make test

version:
image: golang:1.16
commands:
- make version

build-dryrun:
image: woodpeckerci/plugin-docker-buildx:latest
settings:
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ TARGETOS ?= linux
TARGETARCH ?= amd64

VERSION ?= next
ifneq ($(DRONE_TAG),)
VERSION := $(DRONE_TAG:v%=%)
ifneq ($(CI_COMMIT_TAG),)
VERSION := $(CI_COMMIT_TAG:v%=%)
endif

# append commit-sha to next version
BUILD_VERSION := $(VERSION)
ifeq ($(BUILD_VERSION),next)
BUILD_VERSION := $(shell echo "next-$(shell echo ${DRONE_COMMIT_SHA} | head -c 8)")
CI_COMMIT_SHA ?= $(shell git rev-parse HEAD)
BUILD_VERSION := $(shell echo "next-$(shell echo ${CI_COMMIT_SHA} | head -c 8)")
endif

LDFLAGS := -s -w -extldflags "-static" -X main.version=${BUILD_VERSION}
Expand Down Expand Up @@ -48,4 +49,4 @@ build:

.PHONY: version
version:
@echo ${VERSION}
@echo ${BUILD_VERSION}
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,34 @@ Clone a commit:

```console
docker run --rm \
-e DRONE_REMOTE_URL=https://github.com/garyburd/redigo.git \
-e DRONE_WORKSPACE=/go/src/github.com/garyburd/redigo \
-e DRONE_BUILD_EVENT=push \
-e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
-e DRONE_COMMIT_REF=refs/heads/master \
-e CI_REPO_REMOTE=https://github.com/garyburd/redigo.git \
-e CI_WORKSPACE=/go/src/github.com/garyburd/redigo \
-e CI_BUILD_EVENT=push \
-e CI_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
-e CI_COMMIT_REF=refs/heads/master \
woodpeckerci/plugin-git
```

Clone a pull request:

```console
docker run --rm \
-e DRONE_REMOTE_URL=https://github.com/garyburd/redigo.git \
-e DRONE_WORKSPACE=/go/src/github.com/garyburd/redigo \
-e DRONE_BUILD_EVENT=pull_request \
-e DRONE_COMMIT_SHA=3b4642018d177bf5fecc5907e7f341a2b5c12b8a \
-e DRONE_COMMIT_REF=refs/pull/74/head \
-e CI_REPO_REMOTE=https://github.com/garyburd/redigo.git \
-e CI_WORKSPACE=/go/src/github.com/garyburd/redigo \
-e CI_BUILD_EVENT=pull_request \
-e CI_COMMIT_SHA=3b4642018d177bf5fecc5907e7f341a2b5c12b8a \
-e CI_COMMIT_REF=refs/pull/74/head \
woodpeckerci/plugin-git
```

Clone a tag:

```console
docker run --rm \
-e DRONE_REMOTE_URL=https://github.com/garyburd/redigo.git \
-e DRONE_WORKSPACE=/go/src/github.com/garyburd/redigo \
-e DRONE_BUILD_EVENT=tag \
-e DRONE_COMMIT_SHA=3b4642018d177bf5fecc5907e7f341a2b5c12b8a \
-e DRONE_COMMIT_REF=refs/tags/74/head \
-e CI_REPO_REMOTE=https://github.com/garyburd/redigo.git \
-e CI_WORKSPACE=/go/src/github.com/garyburd/redigo \
-e CI_BUILD_EVENT=tag \
-e CI_COMMIT_SHA=3b4642018d177bf5fecc5907e7f341a2b5c12b8a \
-e CI_COMMIT_REF=refs/tags/74/head \
woodpeckerci/plugin-git
```
2 changes: 1 addition & 1 deletion docker/Dockerfile.multiarch
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN apk add --no-cache ca-certificates git openssh curl
ENV GODEBUG=netdns=go

COPY --from=build src/release/plugin-git /bin/
ENTRYPOINT ["/bin/plugin-git"]
ENTRYPOINT ["/bin/plugin-git"]
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
&cli.StringFlag{
Name: "remote",
Usage: "git remote url",
EnvVars: []string{"PLUGIN_REMOTE", "CI_REMOTE_URL"},
EnvVars: []string{"PLUGIN_REMOTE", "CI_REPO_REMOTE", "CI_REMOTE_URL"},
},
&cli.StringFlag{
Name: "path",
Expand Down