Skip to content

Commit

Permalink
Add version info (#52)
Browse files Browse the repository at this point in the history
* add version info

* add default value
  • Loading branch information
morphy2k authored May 28, 2021
1 parent a40e399 commit 0a537cd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:

- name: Build image
run: |
export IMAGE_TAG=${GITHUB_REF#refs/tags/}
export IMAGE_TAG_MINOR=$(echo ${IMAGE_TAG} | awk '{match($0,"v[0-9].[0-9]",a)}END{print a[0]}')
export IMAGE_TAG_MAJOR=$(echo ${IMAGE_TAG} | awk '{match($0,"v[0-9]",a)}END{print a[0]}')
docker build \
export VERSION=${GITHUB_REF#refs/tags/}
export VERSION_MINOR=$(echo ${VERSION} | awk '{match($0,"v[0-9].[0-9]",a)}END{print a[0]}')
export VERSION_MAJOR=$(echo ${VERSION} | awk '{match($0,"v[0-9]",a)}END{print a[0]}')
docker build --build-arg ACTION_VERSION=${VERSION} \
-t morphy/revive-action \
-t morphy/revive-action:${IMAGE_TAG} \
-t morphy/revive-action:${IMAGE_TAG_MINOR} \
-t morphy/revive-action:${IMAGE_TAG_MAJOR} .
-t morphy/revive-action:${VERSION} \
-t morphy/revive-action:${VERSION_MINOR} \
-t morphy/revive-action:${VERSION_MAJOR} .
- name: Publish image
run: docker push --all-tags morphy/revive-action
Expand Down
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
FROM golang:1.16.4 as build-env

ARG ACTION_VERSION=unknown
ARG REVIVE_VERSION=v1.0.7

ENV CGO_ENABLED=0

RUN go get -v github.com/mgechev/revive@v1.0.7
RUN go install -v -ldflags="-X 'main.version=${REVIVE_VERSION}'" \
github.com/mgechev/revive@${REVIVE_VERSION}

WORKDIR /tmp/github.com/morphy2k/revive-action
COPY . .

RUN go install
RUN go install -ldflags="-X 'main.version=${ACTION_VERSION}'"

FROM alpine:3.13.5

Expand All @@ -23,6 +27,6 @@ LABEL com.github.actions.color="blue"
COPY --from=build-env ["/go/bin/revive", "/go/bin/revive-action", "/bin/"]
COPY --from=build-env /tmp/github.com/morphy2k/revive-action/entrypoint.sh /

RUN apk add --no-cache bash
RUN apk add --no-cache bash gawk

ENTRYPOINT ["/entrypoint.sh"]
6 changes: 6 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -o pipefail

cd "$GITHUB_WORKSPACE"

ACTION_VERSION=$(revive-action -version)
REVIVE_VERSION=$(revive -version | gawk '{match($0,"v[0-9].[0-9].[0-9]",a)}END{print a[0]}')

LINT_PATH="./..."

if [ ! -z "${INPUT_PATH}" ]; then LINT_PATH=$INPUT_PATH; fi
Expand All @@ -16,4 +19,7 @@ done

if [ ! -z "${INPUT_CONFIG}" ]; then CONFIG="-config=$INPUT_CONFIG"; fi

echo "ACTION: $ACTION_VERSION
REVIVE: $REVIVE_VERSION"

eval "revive $CONFIG $EXCLUDES -formatter ndjson $LINT_PATH | revive-action"
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package main

import (
"encoding/json"
"flag"
"fmt"
"go/token"
"os"
"sync"
)

var version = "unknown"

type failure struct {
Failure string
RuleName string
Expand Down Expand Up @@ -60,6 +63,14 @@ func printFailure(f *failure, wg *sync.WaitGroup) {
}

func main() {
printVersion := flag.Bool("version", false, "Print version")
flag.Parse()

if *printVersion {
fmt.Println(version)
os.Exit(0)
}

stats := &statistics{}

ch := make(chan *failure)
Expand Down

0 comments on commit 0a537cd

Please sign in to comment.