-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
173 lines (158 loc) · 5.68 KB
/
.gitlab-ci.yml
File metadata and controls
173 lines (158 loc) · 5.68 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
image: node:13
cache:
paths:
- node_modules/
build:
stage: build
script:
- npm --color="always" install
- npx tsc
- PACKAGE_PATH=`npm --color="always" pack`
- mv $PACKAGE_PATH hap-server-remote-access.tgz
- cd packages/homebridge-remote-access
- node -e "fs.writeFileSync('package.json', JSON.stringify((p => (p.version = require('../../package').version, p.peerDependencies['@hap-server/remote-access'] = require('../../package').version, p))(JSON.parse(fs.readFileSync('package.json', 'utf-8'))), null, 4) + '\n', 'utf-8')"
- PACKAGE_PATH=`npm --color="always" pack`
- mv $PACKAGE_PATH ../../homebridge-remote-access.tgz
only:
changes:
- .gitlab-ci.yml
- package.json
- package-lock.json
- tsconfig.json
- src/**/*
- packages/homebridge-remote-access/**/*
except:
variables:
- $NPM_AUDIT_SCHEDULE_SKIP_BUILD
artifacts:
paths:
- dist
- hap-server-remote-access.tgz
- homebridge-remote-access.tgz
audit:
stage: test
script:
- npm audit --json > npm-audit.json || true
- npm --color="always" audit
artifacts:
paths:
- npm-audit.json
when: always
only:
changes:
- .gitlab-ci.yml
- package-lock.json
dependencies: []
cache:
paths:
- node_modules/
policy: pull
when: always
allow_failure: true
publish-npm:
stage: deploy
script:
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
- npm --color="always" publish
- cd packages/homebridge-remote-access
- node -e "fs.writeFileSync('package.json', JSON.stringify((p => (p.version = require('../../package').version, p.peerDependencies['@hap-server/remote-access'] = require('../../package').version, p))(JSON.parse(fs.readFileSync('package.json', 'utf-8'))), null, 4) + '\n', 'utf-8')"
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
- npm --color="always" publish
dependencies:
- build
only:
refs:
- /^v.*$/
variables:
- $NPM_TOKEN
except:
- branches
cache:
paths:
- node_modules/
policy: pull
publish-github:
stage: deploy
script:
- echo "//npm.pkg.github.com/:_authToken=${GITHUB_NPM_TOKEN}" > .npmrc
- npm --color="always" --registry=https://npm.pkg.github.com/ publish
- cd packages/homebridge-remote-access
- node -e "fs.writeFileSync('package.json', JSON.stringify((p => (p.version = require('../../package').version, p.peerDependencies['@hap-server/remote-access'] = require('../../package').version, p))(JSON.parse(fs.readFileSync('package.json', 'utf-8'))), null, 4) + '\n', 'utf-8')"
- echo "//npm.pkg.github.com/:_authToken=${GITHUB_NPM_TOKEN}" > .npmrc
- npm --color="always" --registry=https://npm.pkg.github.com/ publish
dependencies:
- build
only:
refs:
- /^v.*$/
variables:
- $GITHUB_NPM_TOKEN
except:
- branches
cache:
paths:
- node_modules/
policy: pull
publish-gitlab:
stage: deploy
script:
- echo "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" | sed s/^https:// > .npmrc
- npm --color="always" --registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/ publish
- cd packages/homebridge-remote-access
- node -e "fs.writeFileSync('package.json', JSON.stringify((p => (p.version = require('../../package').version, p.peerDependencies['@hap-server/remote-access'] = require('../../package').version, p))(JSON.parse(fs.readFileSync('package.json', 'utf-8'))), null, 4) + '\n', 'utf-8')"
- cp ../../.npmrc .
- npm --color="always" --registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/ publish
dependencies:
- build
only:
refs:
- /^v.*$/
variables:
- $GITLAB_NPM_PUBLISH
except:
- branches
cache:
paths:
- node_modules/
policy: pull
test-server:
stage: deploy
script:
# From https://docs.gitlab.com/ee/ci/ssh_keys/
- 'which ssh-agent || ( apt-get update && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- echo "$SSH_CONFIG" >> ~/.ssh/config
- chmod 644 ~/.ssh/known_hosts
- >
ssh test-server "mkdir -p $TEST_SERVER_DIRECTORY &&
cd $TEST_SERVER_DIRECTORY &&
mkdir -p data &&
( rm -rf commit-$CI_COMMIT_SHA || true )
"
- scp -r $(pwd) test-server:$TEST_SERVER_DIRECTORY/commit-$CI_COMMIT_SHA
- >
ssh test-server "cd $TEST_SERVER_DIRECTORY/commit-$CI_COMMIT_SHA &&
npm install &&
ln -s ../data data &&
( rm ../previous || true ) &&
( mv ../current ../previous || true ) &&
ln -s commit-$CI_COMMIT_SHA ../current &&
( kill \`cat ../previous/tunnel-server.pid\` || true )
"
environment: test-server
only:
refs:
- master
variables:
- $SSH_PRIVATE_KEY
- $SSH_KNOWN_HOSTS
- $SSH_CONFIG
- $TEST_SERVER_DIRECTORY
dependencies:
- build
cache:
policy: pull