Skip to content

Commit 3f53e9c

Browse files
authored
Add a hint to user agent when running in a know CI provider (#380)
1 parent f277cc2 commit 3f53e9c

File tree

2 files changed

+173
-5
lines changed

2 files changed

+173
-5
lines changed

lib/aptible/cli/agent.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,30 @@ def version_string
349349
"v#{Aptible::CLI::VERSION}"
350350
]
351351
bits << 'toolbelt' if toolbelt?
352+
bits << "(#{ci_string})" if ci?
352353
bits.join ' '
353354
end
354355

356+
def ci_string
357+
if ENV['GITHUB_ACTIONS'] == 'true'
358+
'GitHub Actions'
359+
elsif ENV['CIRCLECI'] == 'true'
360+
'CircleCI'
361+
elsif ENV['TRAVIS'] == 'true'
362+
'Travis CI'
363+
elsif ENV['GITLAB_CI'] == 'true'
364+
'GitLab CI'
365+
elsif ENV['DRONE'] == 'true'
366+
'Harness'
367+
else
368+
'CI'
369+
end
370+
end
371+
372+
def ci?
373+
ENV['CI'] == 'true'
374+
end
375+
355376
def toolbelt?
356377
ENV['APTIBLE_TOOLBELT']
357378
end

spec/aptible/cli/agent_spec.rb

Lines changed: 152 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88
end
99

1010
describe '#version' do
11+
before do
12+
# Reset CI-related environment variables before each test
13+
ENV['APTIBLE_TOOLBELT'] = nil
14+
ENV['CI'] = nil
15+
ENV['GITHUB_ACTIONS'] = nil
16+
ENV['CIRCLECI'] = nil
17+
ENV['TRAVIS'] = nil
18+
ENV['GITLAB_CI'] = nil
19+
ENV['DRONE'] = nil
20+
end
21+
1122
it 'should print the version' do
12-
ClimateControl.modify(APTIBLE_TOOLBELT: nil) do
13-
version = Aptible::CLI::VERSION
14-
subject.version
15-
expect(captured_output_text).to eq("aptible-cli v#{version}\n")
16-
end
23+
version = Aptible::CLI::VERSION
24+
subject.version
25+
expect(captured_output_text).to eq("aptible-cli v#{version}\n")
1726
end
1827

1928
it 'should print the version (with toolbelt)' do
@@ -23,6 +32,144 @@
2332
expect(captured_output_text).to eq("aptible-cli v#{version} toolbelt\n")
2433
end
2534
end
35+
36+
it 'should print the version with CI suffix' do
37+
ClimateControl.modify(CI: 'true') do
38+
version = Aptible::CLI::VERSION
39+
subject.version
40+
expect(captured_output_text).to eq("aptible-cli v#{version} (CI)\n")
41+
end
42+
end
43+
44+
it 'should print the version (with toolbelt and CI)' do
45+
ClimateControl.modify(APTIBLE_TOOLBELT: '1', CI: 'true') do
46+
version = Aptible::CLI::VERSION
47+
subject.version
48+
expect(captured_output_text).to eq(
49+
"aptible-cli v#{version} toolbelt (CI)\n"
50+
)
51+
end
52+
end
53+
54+
it 'should print the version with GHA suffix' do
55+
ClimateControl.modify(CI: 'true', GITHUB_ACTIONS: 'true') do
56+
version = Aptible::CLI::VERSION
57+
subject.version
58+
expect(captured_output_text).to eq(
59+
"aptible-cli v#{version} (GitHub Actions)\n"
60+
)
61+
end
62+
end
63+
64+
it 'should print the version (with toolbelt and GHA)' do
65+
ClimateControl.modify(
66+
APTIBLE_TOOLBELT: '1',
67+
CI: 'true',
68+
GITHUB_ACTIONS: 'true'
69+
) do
70+
version = Aptible::CLI::VERSION
71+
subject.version
72+
expect(captured_output_text).to eq(
73+
"aptible-cli v#{version} toolbelt (GitHub Actions)\n"
74+
)
75+
end
76+
end
77+
78+
it 'should print the version with Circle suffix' do
79+
ClimateControl.modify(CI: 'true', CIRCLECI: 'true') do
80+
version = Aptible::CLI::VERSION
81+
subject.version
82+
expect(captured_output_text).to eq(
83+
"aptible-cli v#{version} (CircleCI)\n"
84+
)
85+
end
86+
end
87+
88+
it 'should print the version (with toolbelt and Circle)' do
89+
ClimateControl.modify(
90+
APTIBLE_TOOLBELT: '1',
91+
CI: 'true',
92+
CIRCLECI: 'true'
93+
) do
94+
version = Aptible::CLI::VERSION
95+
subject.version
96+
expect(captured_output_text).to eq(
97+
"aptible-cli v#{version} toolbelt (CircleCI)\n"
98+
)
99+
end
100+
end
101+
102+
it 'should print the version with Travis suffix' do
103+
ClimateControl.modify(CI: 'true', TRAVIS: 'true') do
104+
version = Aptible::CLI::VERSION
105+
subject.version
106+
expect(captured_output_text).to eq(
107+
"aptible-cli v#{version} (Travis CI)\n"
108+
)
109+
end
110+
end
111+
112+
it 'should print the version (with toolbelt and Travis)' do
113+
ClimateControl.modify(
114+
APTIBLE_TOOLBELT: '1',
115+
CI: 'true',
116+
TRAVIS: 'true'
117+
) do
118+
version = Aptible::CLI::VERSION
119+
subject.version
120+
expect(captured_output_text).to eq(
121+
"aptible-cli v#{version} toolbelt (Travis CI)\n"
122+
)
123+
end
124+
end
125+
126+
it 'should print the version with GitLab suffix' do
127+
ClimateControl.modify(CI: 'true', GITLAB_CI: 'true') do
128+
version = Aptible::CLI::VERSION
129+
subject.version
130+
expect(captured_output_text).to eq(
131+
"aptible-cli v#{version} (GitLab CI)\n"
132+
)
133+
end
134+
end
135+
136+
it 'should print the version (with toolbelt and GitLab)' do
137+
ClimateControl.modify(
138+
APTIBLE_TOOLBELT: '1',
139+
CI: 'true',
140+
GITLAB_CI: 'true'
141+
) do
142+
version = Aptible::CLI::VERSION
143+
subject.version
144+
expect(captured_output_text).to eq(
145+
"aptible-cli v#{version} toolbelt (GitLab CI)\n"
146+
)
147+
end
148+
end
149+
150+
it 'should print the version with Harness suffix' do
151+
ClimateControl.modify(CI: 'true', DRONE: 'true') do
152+
version = Aptible::CLI::VERSION
153+
subject.version
154+
expect(captured_output_text).to eq(
155+
"aptible-cli v#{version} (Harness)\n"
156+
)
157+
end
158+
end
159+
160+
it 'should print the version (with toolbelt and Harness)' do
161+
ClimateControl.modify(
162+
APTIBLE_TOOLBELT: '1',
163+
CI: 'true',
164+
DRONE: 'true'
165+
) do
166+
version = Aptible::CLI::VERSION
167+
subject.version
168+
expect(captured_output_text).to eq(
169+
"aptible-cli v#{version} toolbelt (Harness)\n"
170+
)
171+
end
172+
end
26173
end
27174

28175
describe '#login' do

0 commit comments

Comments
 (0)