diff --git a/.github/golang/Dockerfile b/.github/golang/Dockerfile new file mode 100644 index 0000000..24c447b --- /dev/null +++ b/.github/golang/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.10 + +LABEL "name"="golang tools action" +LABEL "maintainer"="Stefan Prodan " +LABEL "version"="1.0.0" + +LABEL "com.github.actions.icon"="code" +LABEL "com.github.actions.color"="gray-dark" +LABEL "com.github.actions.name"="Go Tools" +LABEL "com.github.actions.description"="This is an Action to run go and dep commands." + +ENV DEP_VERSION="v0.5.0" + +RUN curl -fL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/${DEP_VERSION}/dep-linux-amd64 \ + && chmod +x /usr/local/bin/dep + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + diff --git a/.github/golang/entrypoint.sh b/.github/golang/entrypoint.sh new file mode 100755 index 0000000..14ce034 --- /dev/null +++ b/.github/golang/entrypoint.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail +set -e + +APP_DIR="/go/src/github.com/${GITHUB_REPOSITORY}/" + +mkdir -p ${APP_DIR} && cp -r ./ ${APP_DIR} && cd ${APP_DIR} + +if [[ "$1" == "fmt" ]]; then + echo "Running gofmt" + files=$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1) + if [ "$files" ]; then + echo "These files did not pass the gofmt check:" + echo ${files} + exit 1 + fi +fi + +if [[ "$1" == "test" ]]; then + echo "Running go test" + go test $(go list ./... | grep -v /vendor/) -cover +fi + diff --git a/.github/main.workflow b/.github/main.workflow index e20523b..0aac113 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -3,13 +3,25 @@ workflow "Publish container" { resolves = ["Docker tag and push"] } -action "Test and build" { +action "Lint" { + uses = "./.github/actions/golang" + args = "fmt" +} + +action "Test" { + needs = ["Lint"] + uses = "./.github/actions/golang" + args = "test" +} + +action "Build" { + needs = ["Test"] uses = "actions/docker/cli@master" args = "build -t app -f Dockerfile.ci ." } action "Docker login" { - needs = ["Test and build"] + needs = ["Build"] uses = "actions/docker/login@master" secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] }