Skip to content

Commit 80f1c54

Browse files
authored
Merge pull request #161 from commander-cli/add-circleci
Move to circleci
2 parents 4675a95 + 2b65f06 commit 80f1c54

12 files changed

Lines changed: 237 additions & 139 deletions

File tree

.circleci/config.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
version: 2.1
2+
orbs:
3+
win: circleci/windows@2.2.0
4+
5+
runOnAllTagsAndBranches: &runOnAllTagsAndBranches
6+
filters:
7+
tags:
8+
only: /.*/
9+
branches:
10+
only: /.*/
11+
12+
runOnDefaultBranchAndTags: &runOnDefaultBranchAndTags
13+
filters:
14+
tags:
15+
only: /.*/
16+
branches:
17+
only: master
18+
19+
jobs:
20+
style:
21+
docker:
22+
- image: circleci/golang:1.15
23+
steps:
24+
- checkout
25+
- run: go vet ./...
26+
- run: if [ $(go fmt ./... | wc -l) -eq 0 ]; then exit 0; else exit 0; fi
27+
28+
test:
29+
docker:
30+
- image: circleci/golang:1.15
31+
32+
steps:
33+
- checkout
34+
- setup_remote_docker:
35+
version: 19.03.13
36+
- run:
37+
name: Run tests
38+
command: |
39+
make test-coverage-all-dockerized-with-codeclimate
40+
41+
# higher support plan is necessary
42+
# test-macos:
43+
# macos:
44+
# xcode: 11.7.0
45+
# steps:
46+
# - checkout
47+
# - run: go test ./...
48+
49+
test-windows:
50+
executor:
51+
name: win/default
52+
shell: powershell.exe
53+
steps:
54+
- checkout
55+
- run: choco install make
56+
- run: choco install golang --version 1.15
57+
- run: make test
58+
59+
integration:
60+
docker:
61+
- image: circleci/golang:1.15
62+
steps:
63+
- checkout
64+
- setup_remote_docker:
65+
version: 19.03.13
66+
- run:
67+
name: Install commander
68+
command: |
69+
mkdir -p ~/.local/bin/
70+
curl -L https://github.com/commander-cli/commander/releases/download/v2.1.0/commander-linux-amd64 -o ~/.local/bin/commander
71+
chmod +x ~/.local/bin/commander
72+
- run: make integration-linux-dockerized
73+
74+
integration-windows:
75+
executor:
76+
name: win/default
77+
shell: cmd.exe
78+
steps:
79+
- checkout
80+
- run: choco install make
81+
- run: choco install curl
82+
- run: curl -L https://github.com/commander-cli/commander/releases/download/v2.1.0/commander-windows-amd64 -o C:\Windows\system32\commander.exe
83+
- run: make integration-windows
84+
85+
deploy:
86+
environment:
87+
GIT_RELEASE_TAG: << pipeline.git.tag >>
88+
docker:
89+
- image: circleci/golang:1.15
90+
steps:
91+
- checkout
92+
- run: go get -u github.com/tcnksm/ghr
93+
- run: make release
94+
- run:
95+
name: Publish release
96+
command: ghr $GIT_RELEASE_TAG release/
97+
98+
workflows:
99+
version: 2.1
100+
workflow:
101+
jobs:
102+
- style:
103+
<<: *runOnAllTagsAndBranches
104+
- test:
105+
<<: *runOnAllTagsAndBranches
106+
- test-windows:
107+
<<: *runOnDefaultBranchAndTags
108+
- integration:
109+
<<: *runOnAllTagsAndBranches
110+
- integration-windows:
111+
<<: *runOnDefaultBranchAndTags
112+
- deploy:
113+
requires:
114+
- style
115+
- test
116+
- test-windows
117+
- integration
118+
- integration-windows
119+
filters:
120+
tags:
121+
only: /.*/
122+
branches:
123+
ignore: /.*/

.travis.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

Makefile

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,120 @@
11
exe = cmd/commander/*
22
cmd = commander
3-
TRAVIS_TAG ?= "0.0.0"
3+
GIT_RELEASE_TAG ?= "0.0.0"
44
CWD = $(shell pwd)
55

6-
.PHONY: deps lint test integration integration-windows git-hooks init
7-
6+
.PHONY: init
87
init: git-hooks
98

9+
.PHONY: git-hooks
1010
git-hooks:
1111
$(info INFO: Starting build $@)
1212
ln -sf ../../.githooks/pre-commit .git/hooks/pre-commit
1313

14+
.PHONY: deps
1415
deps:
1516
$(info INFO: Starting build $@)
1617
go mod vendor
1718

19+
.PHONY: build
1820
build:
1921
$(info INFO: Starting build $@)
2022
go build $(exe)
2123

24+
.PHONY: lint
2225
lint:
2326
$(info INFO: Starting build $@)
2427
golint pkg/ cmd/
2528

29+
.PHONY: test
2630
test:
2731
$(info INFO: Starting build $@)
2832
go test ./...
2933

34+
.PHONY: test-coverage
3035
test-coverage:
3136
$(info INFO: Starting build $@)
3237
go test -coverprofile c.out ./...
3338

39+
.PHONY: test-coverage-all-dockerized
40+
test-coverage-all-dockerized:
41+
$(info INFO: Starting build $@)
42+
./test.sh
43+
44+
.PHONY: test-coverage-all-dockerized-with-codeclimate
45+
test-coverage-all-dockerized-with-codeclimate:
46+
$(info INFO: Starting build $@)
47+
CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} ./test.sh
3448

3549
test-coverage-all: export COMMANDER_TEST_ALL = 1
3650
test-coverage-all: export COMMANDER_SSH_TEST = 1
37-
test-coverage-all: export COMMANDER_TEST_SSH_HOST = localhost:2222
51+
test-coverage-all: export COMMANDER_TEST_SSH_HOST = 172.28.0.2:22
3852
test-coverage-all: export COMMANDER_TEST_SSH_USER = root
3953
test-coverage-all: export COMMANDER_TEST_SSH_IDENTITY_FILE = $(CWD)/integration/containers/ssh/id_rsa
54+
.PHONY: test-coverage-all
4055
test-coverage-all:
4156
$(info INFO: Starting build $@)
42-
./integration/setup_unix.sh
4357
go test -coverprofile c.out ./...
44-
./integration/teardown_unix.sh
4558

59+
test-coverage-all: export COMMANDER_TEST_ALL = 1
60+
test-coverage-all: export COMMANDER_SSH_TEST = 1
61+
test-coverage-all: export COMMANDER_TEST_SSH_HOST = 172.28.0.2:22
62+
test-coverage-all: export COMMANDER_TEST_SSH_USER = root
63+
test-coverage-all: export COMMANDER_TEST_SSH_IDENTITY_FILE = $(CWD)/integration/containers/ssh/id_rsa
64+
.PHONY: test-coverage-all-codeclimate
65+
test-coverage-all-codeclimate:
66+
$(info INFO: Starting build $@)
67+
./test-reporter before-build
68+
go test -coverprofile c.out ./...; \
69+
./test-reporter after-build -t gocov --prefix=github.com/commander-cli/commander --exit-code $$?
70+
71+
.PHONY: integration-unix
4672
integration-unix: build
4773
$(info INFO: Starting build $@)
4874
commander test commander_unix.yaml
4975

76+
.PHONY: integration-linux
5077
integration-linux: build
5178
$(info INFO: Starting build $@)
52-
./integration/setup_unix.sh
53-
commander test commander_unix.yaml
54-
commander test commander_linux.yaml
55-
./integration/teardown_unix.sh
79+
DOCKER_HOST=${DOCKER_HOST} DOCKER_CERT_PATH=${DOCKER_CERT_PATH} commander test commander_unix.yaml
80+
DOCKER_HOST=${DOCKER_HOST} DOCKER_CERT_PATH=${DOCKER_CERT_PATH} commander test commander_linux.yaml --verbose
5681

82+
.PHONY: integration-linux-dockerized
83+
integration-linux-dockerized:
84+
$(info INFO: Starting build $@)
85+
./test.sh integration-linux
86+
87+
.PHONY: integration-windows
5788
integration-windows: build
5889
$(info INFO: Starting build $@)
5990
commander test commander_windows.yaml
6091

6192
release-amd64:
6293
$(info INFO: Starting build $@)
63-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-linux-amd64 $(exe)
94+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(GIT_RELEASE_TAG) -s -w" -o release/$(cmd)-linux-amd64 $(exe)
6495

6596
release-arm:
6697
$(info INFO: Starting build $@)
67-
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-linux-arm $(exe)
98+
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "-X main.version=$(GIT_RELEASE_TAG) -s -w" -o release/$(cmd)-linux-arm $(exe)
6899

69100
release-386:
70101
$(info INFO: Starting build $@)
71-
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-linux-386 $(exe)
102+
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-X main.version=$(GIT_RELEASE_TAG) -s -w" -o release/$(cmd)-linux-386 $(exe)
72103

73104
release-darwin-amd64:
74105
$(info INFO: Starting build $@)
75-
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-darwin-amd64 $(exe)
106+
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$(GIT_RELEASE_TAG) -s -w" -o release/$(cmd)-darwin-amd64 $(exe)
76107

77108
release-darwin-386:
78109
$(info INFO: Starting build $@)
79-
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-darwin-386 $(exe)
110+
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -ldflags "-X main.version=$(GIT_RELEASE_TAG) -s -w" -o release/$(cmd)-darwin-386 $(exe)
80111

81112
release-windows-amd64:
82113
$(info INFO: Starting build $@)
83-
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-windows-amd64.exe $(exe)
114+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$(GIT_RELEASE_TAG) -s -w" -o release/$(cmd)-windows-amd64.exe $(exe)
84115

85116
release-windows-386:
86117
$(info INFO: Starting build $@)
87-
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-windows-386.exe $(exe)
88-
118+
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-X main.version=$(GIT_RELEASE_TAG) -s -w" -o release/$(cmd)-windows-386.exe $(exe)
89119

90-
release: release-amd64 release-arm release-386 release-darwin-amd64 release-darwin-386 release-windows-amd64 release-windows-386
120+
release: release-amd64 release-arm release-386 release-darwin-amd64 release-darwin-386 release-windows-amd64 release-windows-386

docs/development.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $ make test
5353
$ make test-coverage
5454
5555
# Coverage with more complex tests like ssh execution
56-
$ make test-coverage-all
56+
$ make test-coverage-all-dockerized
5757
5858
# Integration tests for linux and macos
5959
$ make integration-unix
@@ -265,4 +265,3 @@ It is always necessary to execute the test suite with a stable version of comman
265265

266266
- The working directory is by default the project root, even for tests located inside `integration/*`
267267
- Execute `commander` inside the `commander_*.yaml` files with a given suite and assert the result which is returned
268-

integration/containers/ssh/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/s
1010

1111
WORKDIR /root
1212
RUN mkdir .ssh
13-
COPY id_rsa .ssh/id_rsa
14-
COPY id_rsa.pub .ssh/id_rsa.pub
15-
COPY id_rsa.pub .ssh/authorized_keys
13+
COPY integration/containers/ssh/id_rsa .ssh/id_rsa
14+
COPY integration/containers/ssh/id_rsa.pub .ssh/id_rsa.pub
15+
COPY integration/containers/ssh/id_rsa.pub .ssh/authorized_keys
1616

1717
RUN chmod 700 ~/.ssh
1818
RUN chmod 644 ~/.ssh/authorized_keys
@@ -24,4 +24,4 @@ EXPOSE 22
2424
RUN echo "test file ssh" >> /root/int-test
2525
RUN chmod 777 /root/int-test
2626

27-
CMD ["/usr/sbin/sshd", "-D"]
27+
CMD ["/usr/sbin/sshd", "-D"]

0 commit comments

Comments
 (0)