diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index af95efc4..f391b495 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -31,18 +31,11 @@ jobs: env: IMPORT: cedrickring/golang-action PROJECT_PATH: ./tests/projects/go_standard + - name: Install dockerfile_lint + run: sudo npm i -g dockerfile_lint - name: Lint - uses: actions/action-builder/shell@master - with: - entrypoint: make - args: lint + run: make lint - name: Test - uses: actions/action-builder/shell@master - with: - entrypoint: make - args: test + run: make test - name: Build - uses: actions/action-builder/docker@master - with: - entrypoint: make - args: build + run: make build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1ec01a01..3e70e32b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,33 +31,20 @@ jobs: env: IMPORT: cedrickring/golang-action PROJECT_PATH: ./tests/projects/go_standard + - name: Install dockerfile_lint + run: sudo npm i -g dockerfile_lint - name: Lint - uses: actions/action-builder/shell@master - with: - entrypoint: make - args: lint - - name: Docker Tag - uses: actions/action-builder/docker@master - with: - entrypoint: make - args: docker-tag - - name: Docker Login - uses: actions/docker/login@master - env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + run: make lint - name: Test - uses: actions/action-builder/shell@master + run: make test + - name: Docker Login + uses: azure/docker-login@v1 with: - entrypoint: make - args: test + password: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ secrets.DOCKER_USERNAME }} + - name: Docker Tag + run: make docker-tag - name: Build - uses: actions/action-builder/docker@master - with: - entrypoint: make - args: build + run: make test - name: Docker Publish - uses: actions/action-builder/docker@master - with: - entrypoint: make - args: publish + run: make publish \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index bbadeb84..7cf4514f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM golang:1.13 +FROM golang:1.14 LABEL name="Golang Action" LABEL maintainer="Cedric Kring" -LABEL version="1.4.1" +LABEL version="1.5.0" LABEL repository="https://github.com/cedrickring/golang-action" LABEL com.github.actions.name="Golang Action" @@ -10,10 +10,10 @@ LABEL com.github.actions.description="Run Golang commands" LABEL com.github.actions.icon="box" LABEL com.github.actions.color="blue" -# Install dep and check sha256 checksum matches for version 0.5.0 https://github.com/golang/dep/releases/tag/v0.5.0 +# Install dep and check sha256 checksum matches for version 0.5.4 https://github.com/golang/dep/releases/tag/v0.5.4 RUN set -eux; \ - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ - echo "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83 $GOPATH/bin/dep" | sha256sum -c -; \ + curl -L -s https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ + echo "40a78c13753f482208d3f4bea51244ca60a914341050c588dad1f00b1acc116c $GOPATH/bin/dep" | sha256sum -c -; \ chmod +x "${GOPATH}/bin/dep"; COPY entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index 0c4d187e..9da677bb 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@master - name: run - uses: cedrickring/golang-action@1.4.1 + uses: cedrickring/golang-action@1.5.0 ``` @@ -27,7 +27,7 @@ To run a custom command, just use: ```yaml steps: - name: Run custom command - uses: cedrickring/golang-action@1.4.1 + uses: cedrickring/golang-action@1.5.0 with: args: make my-target ``` @@ -39,7 +39,7 @@ source Go project: ```yaml steps: - name: Run with custom import path - uses: cedrickring/golang-action@1.4.1 + uses: cedrickring/golang-action@1.5.0 env: IMPORT: "root/repo" ``` @@ -49,7 +49,7 @@ To use Go Modules add `GO111MODULE=on` to the step: ```yaml steps: - name: Go Modules - uses: cedrickring/golang-action@1.4.1 + uses: cedrickring/golang-action@1.5.0 env: GO111MODULE: "on" ``` @@ -59,7 +59,7 @@ If your go project is not located at the root of the repo you can also specify e ```yaml steps: - name: Custom project path - uses: cedrickring/golang-action@1.4.1 + uses: cedrickring/golang-action@1.5.0 env: PROJECT_PATH: "./path/in/my/project" ``` @@ -68,5 +68,5 @@ To use a specific golang version (1.10, 1.11, 1.12, 1.13), defaults to the lates ```yaml steps: - name: Use Go 1.11 - uses: cedrickring/golang-action/go1.11@1.4.1 + uses: cedrickring/golang-action/go1.11@1.5.0 ``` diff --git a/docker.mk b/docker.mk index 52d7f494..d3881ce2 100644 --- a/docker.mk +++ b/docker.mk @@ -10,6 +10,9 @@ ACTION_MINOR_VERSION=$(shell build/semver get minor $(ACTION_VERSION)) .PHONY: docker-lint docker-lint: update-docker-go-versions ## Run Dockerfile Lint on all dockerfiles. +ifeq (, $(shell which dockerfile_lint)) +$(error "dockerfile_lint not installed") +endif dockerfile_lint -r $(ROOT_DIR)/.dockerfile_lint/github_actions.yaml $(wildcard Dockerfile* */Dockerfile*) .PHONY: docker-build diff --git a/go1.10/Dockerfile b/go1.10/Dockerfile index 099299f1..ae7464a9 100644 --- a/go1.10/Dockerfile +++ b/go1.10/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.10 LABEL name="Golang Action" LABEL maintainer="Cedric Kring" -LABEL version="1.4.1" +LABEL version="1.5.0" LABEL repository="https://github.com/cedrickring/golang-action" LABEL com.github.actions.name="Golang Action" @@ -10,10 +10,10 @@ LABEL com.github.actions.description="Run Golang commands" LABEL com.github.actions.icon="box" LABEL com.github.actions.color="blue" -# Install dep and check sha256 checksum matches for version 0.5.0 https://github.com/golang/dep/releases/tag/v0.5.0 +# Install dep and check sha256 checksum matches for version 0.5.4 https://github.com/golang/dep/releases/tag/v0.5.4 RUN set -eux; \ - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ - echo "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83 $GOPATH/bin/dep" | sha256sum -c -; \ + curl -L -s https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ + echo "40a78c13753f482208d3f4bea51244ca60a914341050c588dad1f00b1acc116c $GOPATH/bin/dep" | sha256sum -c -; \ chmod +x "${GOPATH}/bin/dep"; COPY entrypoint.sh /entrypoint.sh diff --git a/go1.11/Dockerfile b/go1.11/Dockerfile index a1a7f3ab..051fddf7 100644 --- a/go1.11/Dockerfile +++ b/go1.11/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.11 LABEL name="Golang Action" LABEL maintainer="Cedric Kring" -LABEL version="1.4.1" +LABEL version="1.5.0" LABEL repository="https://github.com/cedrickring/golang-action" LABEL com.github.actions.name="Golang Action" @@ -10,10 +10,10 @@ LABEL com.github.actions.description="Run Golang commands" LABEL com.github.actions.icon="box" LABEL com.github.actions.color="blue" -# Install dep and check sha256 checksum matches for version 0.5.0 https://github.com/golang/dep/releases/tag/v0.5.0 +# Install dep and check sha256 checksum matches for version 0.5.4 https://github.com/golang/dep/releases/tag/v0.5.4 RUN set -eux; \ - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ - echo "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83 $GOPATH/bin/dep" | sha256sum -c -; \ + curl -L -s https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ + echo "40a78c13753f482208d3f4bea51244ca60a914341050c588dad1f00b1acc116c $GOPATH/bin/dep" | sha256sum -c -; \ chmod +x "${GOPATH}/bin/dep"; COPY entrypoint.sh /entrypoint.sh diff --git a/go1.12/Dockerfile b/go1.12/Dockerfile index 576edb93..60ed2295 100644 --- a/go1.12/Dockerfile +++ b/go1.12/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.12 LABEL name="Golang Action" LABEL maintainer="Cedric Kring" -LABEL version="1.4.1" +LABEL version="1.5.0" LABEL repository="https://github.com/cedrickring/golang-action" LABEL com.github.actions.name="Golang Action" @@ -10,10 +10,10 @@ LABEL com.github.actions.description="Run Golang commands" LABEL com.github.actions.icon="box" LABEL com.github.actions.color="blue" -# Install dep and check sha256 checksum matches for version 0.5.0 https://github.com/golang/dep/releases/tag/v0.5.0 +# Install dep and check sha256 checksum matches for version 0.5.4 https://github.com/golang/dep/releases/tag/v0.5.4 RUN set -eux; \ - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ - echo "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83 $GOPATH/bin/dep" | sha256sum -c -; \ + curl -L -s https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ + echo "40a78c13753f482208d3f4bea51244ca60a914341050c588dad1f00b1acc116c $GOPATH/bin/dep" | sha256sum -c -; \ chmod +x "${GOPATH}/bin/dep"; COPY entrypoint.sh /entrypoint.sh diff --git a/go1.13/Dockerfile b/go1.13/Dockerfile index bbadeb84..d66ae7b8 100644 --- a/go1.13/Dockerfile +++ b/go1.13/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.13 LABEL name="Golang Action" LABEL maintainer="Cedric Kring" -LABEL version="1.4.1" +LABEL version="1.5.0" LABEL repository="https://github.com/cedrickring/golang-action" LABEL com.github.actions.name="Golang Action" @@ -10,10 +10,10 @@ LABEL com.github.actions.description="Run Golang commands" LABEL com.github.actions.icon="box" LABEL com.github.actions.color="blue" -# Install dep and check sha256 checksum matches for version 0.5.0 https://github.com/golang/dep/releases/tag/v0.5.0 +# Install dep and check sha256 checksum matches for version 0.5.4 https://github.com/golang/dep/releases/tag/v0.5.4 RUN set -eux; \ - curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ - echo "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83 $GOPATH/bin/dep" | sha256sum -c -; \ + curl -L -s https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ + echo "40a78c13753f482208d3f4bea51244ca60a914341050c588dad1f00b1acc116c $GOPATH/bin/dep" | sha256sum -c -; \ chmod +x "${GOPATH}/bin/dep"; COPY entrypoint.sh /entrypoint.sh diff --git a/go1.14/Dockerfile b/go1.14/Dockerfile new file mode 100644 index 00000000..7cf4514f --- /dev/null +++ b/go1.14/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.14 + +LABEL name="Golang Action" +LABEL maintainer="Cedric Kring" +LABEL version="1.5.0" +LABEL repository="https://github.com/cedrickring/golang-action" + +LABEL com.github.actions.name="Golang Action" +LABEL com.github.actions.description="Run Golang commands" +LABEL com.github.actions.icon="box" +LABEL com.github.actions.color="blue" + +# Install dep and check sha256 checksum matches for version 0.5.4 https://github.com/golang/dep/releases/tag/v0.5.4 +RUN set -eux; \ + curl -L -s https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64 -o "$GOPATH/bin/dep"; \ + echo "40a78c13753f482208d3f4bea51244ca60a914341050c588dad1f00b1acc116c $GOPATH/bin/dep" | sha256sum -c -; \ + chmod +x "${GOPATH}/bin/dep"; + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD [""] diff --git a/go1.14/entrypoint.sh b/go1.14/entrypoint.sh new file mode 100644 index 00000000..21a1426e --- /dev/null +++ b/go1.14/entrypoint.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +set -e + +if [ -z "${IMPORT}" ]; then + IMPORT="${GITHUB_REPOSITORY}" +fi +WORKDIR="${GOPATH}/src/github.com/${IMPORT}" + +# PROJECT_PATH specifies the subdirectory in the working directory that the Go project is +if [ -z "${PROJECT_PATH}" ]; then + PROJECT_PATH="." +fi + +# Go can only find dependencies if they're under $GOPATH/src. +# GitHub Actions mounts your repository outside of $GOPATH. +# So symlink the repository into $GOPATH, and then cd to it. +mkdir -p "$(dirname "${WORKDIR}")" +ln -s "${PWD}" "${WORKDIR}" +cd "${WORKDIR}/${PROJECT_PATH}" + +# If a command was specified with `args="..."`, then run it. Otherwise, +# look for something useful to run. +if [ $# -eq 0 ] || [ "$*" = "" ]; then + if [ -r Makefile ]; then + make + else + if [ -r go.mod ]; then + export GO111MODULE=on + # Check if using vendored dependencies + if [ -d "vendor" ]; then + export GOFLAGS="-mod=vendor" + else + # Ensure no go.mod changes are made that weren't committed + export GOFLAGS="-mod=readonly" + fi + else + if [ -r Gopkg.toml ]; then + # Check if using vendored dependencies + if [ -d "vendor" ]; then + # Check that dep is in sync with /vendor dependencies and that running dep ensure doesn't result in modifications to Gopkg.lock/Gopkg.toml + "$GOPATH/bin/dep" ensure && "$GOPATH/bin/dep" check + git_workspace_status="$(git status --porcelain)" + if [ -n "${git_workspace_status}" ]; then + echo "Unexpected changes were found in dep /vendored. Please run $(dep ensure) and commit changes:"; + echo "${git_workspace_status}"; + exit 1; + fi + else + # Run dep ensure to download and sync dependencies + "$GOPATH/bin/dep" ensure + fi + fi + fi + go build ./... + go test ./... + fi +else + sh -c "$*" +fi