Skip to content

Commit

Permalink
feat(debpacker): add some new features for debpacker (#3571)
Browse files Browse the repository at this point in the history
* feat(debpacker): Allow to set an output directory for copy files

* feat(debpacker): Allow to copy folder recursively

* feat(debpacker): Allow to set the working directory, add force option to make cmd

* feat(debpacker): Fix user override, allow to set root

* feat(debpacker): User #DEBHELPER# to enable and start service after installed

* refact(debpacker): Create writer struct for os actions, add unit tests for packer

* chore(debpacker): Add test target in makefile
  • Loading branch information
richardlt authored and yesnault committed Nov 27, 2018
1 parent 056e5b4 commit 81cbfa4
Show file tree
Hide file tree
Showing 12 changed files with 520 additions and 238 deletions.
3 changes: 2 additions & 1 deletion cli/cdsctl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ test-xunit-report: $(GO_GO2XUNIT) $(TARGET_DIR)
done; \
for XML in `find . -name "tests.log.xml"`; do \
if [ "$$XML" = "./tests.log.xml" ]; then \
mv $$XML $(TARGET_DIR)/`basename `pwd``.xml; \
PWD=`pwd`; \
mv $$XML $(TARGET_DIR)/`basename $(PWD)`.xml; \
else \
mv $$XML $(TARGET_DIR)/`echo $$XML | sed 's|./||' | sed 's|/|_|g' | sed 's|_tests.log||'`; \
fi; \
Expand Down
3 changes: 2 additions & 1 deletion engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ test-xunit-report: $(GO_GO2XUNIT) $(TARGET_DIR)
done; \
for XML in `find .. -name "tests.log.xml"`; do \
if [ "$$XML" = "./tests.log.xml" ]; then \
mv $$XML $(TARGET_DIR)/`basename `pwd``.xml; \
PWD=`pwd`; \
mv $$XML $(TARGET_DIR)/`basename $(PWD)`.xml; \
else \
mv $$XML $(TARGET_DIR)/`echo $$XML | sed 's|./||' | sed 's|/|_|g' | sed 's|_tests.log||'`; \
fi; \
Expand Down
3 changes: 2 additions & 1 deletion engine/worker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ test-xunit-report: $(GO_GO2XUNIT) $(TARGET_DIR)
done; \
for XML in `find . -name "tests.log.xml"`; do \
if [ "$$XML" = "./tests.log.xml" ]; then \
mv $$XML $(TARGET_DIR)/`basename `pwd``.xml; \
PWD=`pwd`; \
mv $$XML $(TARGET_DIR)/`basename $(PWD)`.xml; \
else \
mv $$XML $(TARGET_DIR)/`echo $$XML | sed 's|./||' | sed 's|/|_|g' | sed 's|_tests.log||'`; \
fi; \
Expand Down
3 changes: 2 additions & 1 deletion tools/debpacker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
debpacker
.debpacker.yml
.debpacker.yml
dist
71 changes: 71 additions & 0 deletions tools/debpacker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386)

GO_BUILD = go build -v
GO_LINT = ${GOPATH}/bin/gometalinter
GO_COV_MERGE = ${GOPATH}/bin/gocovmerge
GO_GOVERALLS = ${GOPATH}/bin/goveralls
GO_GO2XUNIT = ${GOPATH}/bin/go2xunit

TEST_PKGS = $(shell go list ./... | grep -v vendor)
TEST_CMD = go test -v -timeout 180s -coverprofile=profile.coverprofile

$(TARGET_DIR):
$(info create $(TARGET_DIR) directory)
Expand All @@ -20,10 +26,25 @@ $(TARGET_DIR):
$(GO_LINT):
go get -u github.com/alecthomas/gometalinter

$(GO_COV_MERGE):
go get -u github.com/wadey/gocovmerge

$(GO_GOVERALLS):
go get -u github.com/mattn/goveralls

$(GO_GO2XUNIT):
go get -u github.com/tebeka/go2xunit

default: build

clean:
@rm -rf $(TARGET_DIR)
@for TST in `find . -name "tests.log"`; do \
rm $$TST; \
done;
@for profile in `find . -name "*.coverprofile"`; do \
rm $$profile; \
done;

build: $(TARGET_DIR)
@for GOOS in $(TARGET_OS); do \
Expand All @@ -35,6 +56,56 @@ build: $(TARGET_DIR)
done; \
done

test: clean
@for PKG in $(TEST_PKGS); do \
echo "Running tests in package $$PKG"; \
cd ${GOPATH}/src/$$PKG; \
$(TEST_CMD) > ${GOPATH}/src/$$PKG/tests.log; \
done; \
$(MAKE) test-coverage
$(MAKE) test-xunit-report

test-coverage: $(GO_GOVERALLS) $(GO_COV_MERGE) $(TARGET_DIR)
@$(GO_COV_MERGE) ./*.coverprofile > $(TARGET_DIR)/cover.out
@go tool cover -html=$(TARGET_DIR)/cover.out -o=$(TARGET_DIR)/cover.html
ifneq ($(VERSION), snapshot)
echo "Pushing results to coveralls"
@$(GO_GOVERALLS) -coverprofile=$(TARGET_DIR)/cover.out -service=cds -repotoken ${CDS_PROJ_COVERALLS_TOKEN}
endif

test-xunit-report: $(GO_GO2XUNIT) $(TARGET_DIR)
@for TST in `find . -name "tests.log"`; do \
if [ -s $$TST ]; then \
FAILED=`grep -E '(FAIL)+\s([a-z\.\/]*)\s\[build failed\]' $$TST | wc -l`; \
if [ $$FAILED -gt 0 ]; then \
echo "Build Failed \t\t\t($$TST)"; \
echo "Build Failed \t\t\t($$TST)" >> $(TARGET_DIR)/fail; \
else \
NO_TESTS=`grep -E '\?+\s+([a-z\.\/]*)\s\[no test files\]' $$TST | wc -l`; \
if [ $$NO_TESTS -gt 0 ]; then \
echo "No tests found \t\t\t($$TST)"; \
else \
echo "Generating xUnit report \t$$TST.xml $(GO_GO2XUNIT) -input $$TST -output $$TST.xml"; \
$(GO_GO2XUNIT) -input $$TST -output $$TST.xml; \
fi; \
fi; \
else \
echo "Ignoring empty file \t\t$$TST"; \
fi; \
done; \
for XML in `find . -name "tests.log.xml"`; do \
if [ "$$XML" = "./tests.log.xml" ]; then \
PWD=`pwd`; \
mv $$XML $(TARGET_DIR)/`basename $(PWD)`.xml; \
else \
mv $$XML $(TARGET_DIR)/`echo $$XML | sed 's|./||' | sed 's|/|_|g' | sed 's|_tests.log||'`; \
fi; \
done; \
if [ -e $(TARGET_DIR)/fail ]; then \
echo "ERROR: Test compilation failure"; \
cat $(TARGET_DIR)/fail; \
exit 1; \
fi;

lint: $(GO_LINT)
$(GO_LINT) --install --force
Expand Down
Loading

0 comments on commit 81cbfa4

Please sign in to comment.