This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
118 lines (103 loc) · 3.39 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
image: registry.gitlab.com/shitposting/golang
variables:
REPO_NAME: "gitlab.com/shitposting/admin-bot"
before_script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_rsa
- printf "$SSH_PUBLIC_KEY" >> ~/.ssh/id_rsa.pub
- chmod 700 ~/.ssh
- chmod 600 ~/.ssh/id_rsa
- chmod 644 ~/.ssh/id_rsa.pub
- git config --global [email protected]:.insteadOf https://gitlab.com/
- ssh-add ~/.ssh/id_rsa
- ssh-add -l
- ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
stages:
- format
- test
- build
- staging
- production
.exceptions: &exclude # use <<: *exclude to add this rule to a job
except:
changes:
- README.md
- FEATURE.md
- .gitignore
- config_example.toml
- run_gometalint.sh
go-fmt:
stage: format
script:
- go fmt $(go list ./... | grep -v /vendor/)
<<: *exclude
lint_code:
stage: format
script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
- go get -u golang.org/x/lint/golint
- golint -set_exit_status $(go list ./... | grep -v /vendor/)
allow_failure: true
<<: *exclude
.race_detector:
stage: test
script:
- go test -race -short $(go list ./... | grep -v "documentstore")
<<: *exclude
test:
stage: test
script:
# - go test ./...
- go test -race -short $(go list ./... | grep -v "documentstore")
<<: *exclude
compile:
stage: build
script:
- make build
<<: *exclude
artifacts:
paths:
- admin-bot
.test-deploy:
stage: staging
script:
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e ssh -p $PORT -o stricthostkeychecking=no $USER_ID@$HOSTNAME systemctl --user stop admin-bot
- sshpass -e ssh -p $PORT -o stricthostkeychecking=no $USER_ID@$HOSTNAME mv /home/$USER_ID/go/bin/admin-bot /home/$USER_ID/go/bin/admin-bot_bak
- sshpass -e scp -P $PORT -o stricthostkeychecking=no -r admin-bot $USER_ID@$HOSTNAME:/home/$USER_ID/go/bin/admin-bot
- sshpass -e ssh -p $PORT -o stricthostkeychecking=no $USER_ID@$HOSTNAME systemctl --user start admin-bot
<<: *exclude
.stop-unit:
stage: staging
script:
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e ssh -p $PORT -o stricthostkeychecking=no $USER_ID@$HOSTNAME systemctl --user stop admin-bot
when: manual
<<: *exclude
.start-unit:
stage: staging
script:
- sshpass -V
- export SSHPASS=$USER_PASS
- sshpass -e ssh -p $PORT -o stricthostkeychecking=no $USER_ID@$HOSTNAME systemctl --user start admin-bot
when: manual
<<: *exclude
prod-deploy:
stage: production
script:
- sshpass -V
- export SSHPASS=$PROD_USER_PASS
- sshpass -e ssh -p $PROD_PORT -o stricthostkeychecking=no $PROD_USER_ID@$PROD_HOSTNAME systemctl --user stop admin-bot
- sshpass -e ssh -p $PROD_PORT -o stricthostkeychecking=no $PROD_USER_ID@$PROD_HOSTNAME mv /home/$PROD_USER_ID/go/bin/admin-bot /home/$PROD_USER_ID/go/bin/admin-bot_bak
- sshpass -e scp -P $PROD_PORT -o stricthostkeychecking=no -r admin-bot $PROD_USER_ID@$PROD_HOSTNAME:/home/$PROD_USER_ID/go/bin/admin-bot
- sshpass -e ssh -p $PROD_PORT -o stricthostkeychecking=no $PROD_USER_ID@$PROD_HOSTNAME systemctl --user start admin-bot
when: manual
<<: *exclude