diff --git a/Dockerfile b/Dockerfile index 13c8ac7a0..79db24d33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN go mod download COPY . /usr/src/airshipctl/ ARG MAKE_TARGET=build -RUN make ${MAKE_TARGET} +RUN for target in $MAKE_TARGET; do make $target; done FROM ${RELEASE_IMAGE} as release COPY --from=builder /usr/src/airshipctl/bin/airshipctl /usr/local/bin/airshipctl diff --git a/Makefile b/Makefile index 91c4207cb..a96d6b9f9 100644 --- a/Makefile +++ b/Makefile @@ -127,6 +127,11 @@ endif print-docker-image-tag: @echo "$(DOCKER_IMAGE)" +.PHONY: docker-image-test-suite +docker-image-test-suite: DOCKER_MAKE_TARGET = "lint cover update-golden check-git-diff" +docker-image-test-suite: DOCKER_TARGET_STAGE = builder +docker-image-test-suite: docker-image + .PHONY: docker-image-unit-tests docker-image-unit-tests: DOCKER_MAKE_TARGET = cover docker-image-unit-tests: DOCKER_TARGET_STAGE = builder @@ -176,3 +181,8 @@ update-golden: unit-tests .PHONY: delete-golden delete-golden: @find . -type f -name "*.golden" -delete + +# Used by gates after unit-tests and update-golden targets to ensure no files are deleted. +.PHONY: check-git-diff +check-git-diff: + @./tools/git_diff_check \ No newline at end of file diff --git a/playbooks/airship-airshipctl-lint-unit.yaml b/playbooks/airship-airshipctl-lint-unit.yaml index cf735a6ef..f3a0e7857 100644 --- a/playbooks/airship-airshipctl-lint-unit.yaml +++ b/playbooks/airship-airshipctl-lint-unit.yaml @@ -12,16 +12,9 @@ - hosts: primary tasks: - - name: Run Linter + - name: Run Linter, Unit Tests, Verify Golden Testdata block: - - name: "make docker-image-lint" + - name: "make docker-image-test-suite" make: chdir: "{{ zuul.project.src_dir }}" - target: docker-image-lint - - - name: Run Unit Tests - block: - - name: "make docker-image-unit-tests" - make: - chdir: "{{ zuul.project.src_dir }}" - target: docker-image-unit-tests + target: docker-image-test-suite diff --git a/tools/git_diff_check b/tools/git_diff_check new file mode 100755 index 000000000..8e6b2511e --- /dev/null +++ b/tools/git_diff_check @@ -0,0 +1,34 @@ +#!/bin/bash + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Update git index +git update-index -q --ignore-submodules --refresh + +# Evaluate git files for difference, if found print message and fail. +git diff-files --quiet --ignore-submodules +if [ $? -ne 0 ] +then + echo "git diff found modified test cases, please run make update-golden" + exit 1 +fi + +# Evaluate git index for differences, if found print message and fail. +git diff-index --cached --quiet --ignore-submodules HEAD -- +if [ $? -ne 0 ] +then + echo "git diff found modified test cases, please run make update-golden" + exit 1 +fi + +echo "no git diff detected, make target completed successfully" \ No newline at end of file