From 98739d917a276dec1df6550366c7d8544504b35b Mon Sep 17 00:00:00 2001 From: Cedric Kring <39853520+cedrickring@users.noreply.github.com> Date: Tue, 31 Mar 2020 18:38:20 +0200 Subject: [PATCH] Update workflows (#29) * Update workflows * Add check target to test all golang versions * Fix makefile * Testing * Install dockerlint * Undo tests * Test permissions * Exit with code 1 when docker check fails * Exit with code 1 when docker check fails * Revert permissions --- .github/workflows/pull_request.yml | 38 +++++++++++++++++++++++++++++ .github/workflows/push.yml | 26 +++++++++----------- .github/workflows/release.yml | 39 ++++-------------------------- docker.mk | 14 ++++++++++- 4 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/pull_request.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..3e21630e --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,38 @@ +on: pull_request +name: Run checks +jobs: + go-checks: + name: Run go checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Test Go Modules Vendor + uses: ./ + env: + IMPORT: cedrickring/golang-action + PROJECT_PATH: ./tests/projects/go_modules_vendored + - name: Test Go Modules + uses: ./ + env: + IMPORT: cedrickring/golang-action + PROJECT_PATH: ./tests/projects/go_modules + - name: Test Go Standard + uses: ./ + env: + IMPORT: cedrickring/golang-action + PROJECT_PATH: ./tests/projects/go_standard + action-checks: + name: Run action checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Install dockerfile_lint + run: sudo npm i -g dockerfile_lint + - name: Lint + run: make lint + - name: Test + run: make test + - name: Docker Build + run: make build + - name: Check all versions + run: make docker-check diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index f391b495..93572bb4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,21 +1,14 @@ -on: push -name: Build on Push +on: + push: + branches: + - master +name: Test build on push jobs: - testGoDepVendor: - name: Test Go Dep Vendor + go-test: + name: Test go configurations runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - name: Test Go Dep Vendor - uses: ./ - env: - IMPORT: cedrickring/golang-action - PROJECT_PATH: ./tests/projects/go_dep_vendored - - name: Test Go Dep - uses: ./ - env: - IMPORT: cedrickring/golang-action - PROJECT_PATH: ./tests/projects/go_dep - name: Test Go Modules Vendor uses: ./ env: @@ -31,6 +24,11 @@ jobs: env: IMPORT: cedrickring/golang-action PROJECT_PATH: ./tests/projects/go_standard + test: + name: Run tests and build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master - name: Install dockerfile_lint run: sudo npm i -g dockerfile_lint - name: Lint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3e70e32b..f1c56281 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,50 +1,21 @@ on: release -name: Build and Publish +name: Publish to Docker Hub jobs: - testGoDepVendor: - name: Test Go Dep Vendor + publish: + name: Publish docker images runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - name: Test Go Dep Vendor - uses: ./ - env: - IMPORT: cedrickring/golang-action - PROJECT_PATH: ./tests/projects/go_dep_vendored - - name: Test Go Dep - uses: ./ - env: - IMPORT: cedrickring/golang-action - PROJECT_PATH: ./tests/projects/go_dep - - name: Test Go Modules Vendor - uses: ./ - env: - IMPORT: cedrickring/golang-action - PROJECT_PATH: ./tests/projects/go_modules_vendored - - name: Test Go Modules - uses: ./ - env: - IMPORT: cedrickring/golang-action - PROJECT_PATH: ./tests/projects/go_modules - - name: Test Go Standard - uses: ./ - env: - IMPORT: cedrickring/golang-action - PROJECT_PATH: ./tests/projects/go_standard - name: Install dockerfile_lint run: sudo npm i -g dockerfile_lint - - name: Lint - run: make lint - - name: Test - run: make test - name: Docker Login uses: azure/docker-login@v1 with: password: ${{ secrets.DOCKER_PASSWORD }} username: ${{ secrets.DOCKER_USERNAME }} + - name: Docker Build + run: make build - name: Docker Tag run: make docker-tag - - name: Build - run: make test - name: Docker Publish run: make publish \ No newline at end of file diff --git a/docker.mk b/docker.mk index d3881ce2..5b505b5c 100644 --- a/docker.mk +++ b/docker.mk @@ -23,7 +23,19 @@ docker-build: update-docker-go-versions ## Build the top level Dockerfile using for version in $(GO_VERSIONS) ; do \ docker build $(DOCKER_BUILD_ARG) -t $(IMAGE_NAME) -t $(IMAGE_NAME):$$version go$$version/; \ done - + +.PHONY: docker-check +docker-check: + for version in $(GO_VERSIONS); do \ + cp -r tests/projects/go_standard tests/projects/go_standard_$$version; \ + docker run --rm \ + -v $(shell pwd)/tests/projects/go_standard_$$version:/github/workspace \ + -e GITHUB_REPOSITORY="golang-action" \ + -e GITHUB_WORKSPACE="/github/workspace"\ + --workdir /github/workspace \ + $(IMAGE_NAME):$$version || exit 1; \ + done + .PHONY: docker-tag docker-tag: ## Tag the docker image using the tag script. docker tag $(IMAGE_NAME):latest $(DOCKER_REPOSITORY)/$(IMAGE_NAME):$(ACTION_VERSION)