Skip to content

Commit 238a204

Browse files
committed
Buck2 support
1 parent ef099b6 commit 238a204

File tree

7 files changed

+1271
-40
lines changed

7 files changed

+1271
-40
lines changed

__tests__/main.test.ts

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jest.unstable_mockModule('fs', () => ({
66
default: fs
77
}))
88

9-
jest.spyOn(console, 'log').mockImplementation(() => {})
9+
// jest.spyOn(console, 'log').mockImplementation(() => {})
1010

1111
// The module being tested should be imported dynamically. This ensures that the
1212
// mocks are used in place of any actual dependencies.
@@ -33,14 +33,21 @@ const defaultInputs = {
3333
prefix: 'demo-prefix'
3434
}
3535

36-
const defaultOutput = `build --remote_cache=grpcs://cas-demo-prefix.build-faster.nativelink.net
36+
const defaultBazelOutput = `build --remote_cache=grpcs://cas-demo-prefix.build-faster.nativelink.net
3737
build --remote_header=x-nativelink-api-key=demo-key
3838
build --bes_backend=grpcs://bes-demo-prefix.build-faster.nativelink.net
3939
build --bes_header=x-nativelink-api-key=demo-key
4040
build --bes_results_url=https://app.nativelink.com/a/demo-account/build
4141
build --remote_timeout=600
4242
build --remote_executor=grpcs://scheduler-demo-prefix.build-faster.nativelink.net`
4343

44+
const defaultBuckOutput = `[buck2_re_client]
45+
engine_address = "scheduler-demo-prefix.build-faster.nativelink.net:443"
46+
action_cache_address = "cas-demo-prefix.build-faster.nativelink.net:443"
47+
cas_address = "cas-demo-prefix.build-faster.nativelink.net:443"
48+
tls = true
49+
http_headers = "x-nativelink-api-key:demo-key"`
50+
4451
describe('main.ts', () => {
4552
beforeEach(() => {
4653
vol.reset()
@@ -64,7 +71,7 @@ describe('main.ts', () => {
6471
}
6572

6673
it('Writes bazel config', async () => {
67-
writesBazelRc(defaultInputs, defaultOutput)
74+
writesBazelRc(defaultInputs, defaultBazelOutput)
6875
})
6976

7077
it('Writes bazel config for dev', async () => {
@@ -83,7 +90,7 @@ build --remote_executor=grpcs://scheduler-demo-prefix.uc1.scdev.nativelink.net`
8390
it('Writes bazel config with custom cache', async () => {
8491
writesBazelRc(
8592
{ ...defaultInputs, cache_url: 'http://cache-url-foo' },
86-
defaultOutput.replace(
93+
defaultBazelOutput.replace(
8794
'grpcs://cas-demo-prefix.build-faster.nativelink.net',
8895
'http://cache-url-foo'
8996
)
@@ -93,7 +100,7 @@ build --remote_executor=grpcs://scheduler-demo-prefix.uc1.scdev.nativelink.net`
93100
it('Writes bazel config with custom bes', async () => {
94101
writesBazelRc(
95102
{ ...defaultInputs, bes_url: 'http://bes-url-foo' },
96-
defaultOutput.replace(
103+
defaultBazelOutput.replace(
97104
'grpcs://bes-demo-prefix.build-faster.nativelink.net',
98105
'http://bes-url-foo'
99106
)
@@ -103,7 +110,7 @@ build --remote_executor=grpcs://scheduler-demo-prefix.uc1.scdev.nativelink.net`
103110
it('Writes bazel config with custom bes_results_url', async () => {
104111
writesBazelRc(
105112
{ ...defaultInputs, bes_results_url: 'http://bes-results-url-foo' },
106-
defaultOutput.replace(
113+
defaultBazelOutput.replace(
107114
'https://app.nativelink.com/a/demo-account/build',
108115
'http://bes-results-url-foo'
109116
)
@@ -113,7 +120,7 @@ build --remote_executor=grpcs://scheduler-demo-prefix.uc1.scdev.nativelink.net`
113120
it('Writes bazel config with custom scheduler_url', async () => {
114121
writesBazelRc(
115122
{ ...defaultInputs, scheduler_url: 'http://scheduler-url-foo' },
116-
defaultOutput.replace(
123+
defaultBazelOutput.replace(
117124
'grpcs://scheduler-demo-prefix.build-faster.nativelink.net',
118125
'http://scheduler-url-foo'
119126
)
@@ -123,15 +130,15 @@ build --remote_executor=grpcs://scheduler-demo-prefix.uc1.scdev.nativelink.net`
123130
it('Writes bazel config with custom remote timeout', async () => {
124131
writesBazelRc(
125132
{ ...defaultInputs, remote_timeout: '100' },
126-
defaultOutput.replace('600', '100')
133+
defaultBazelOutput.replace('600', '100')
127134
)
128135
})
129136

130137
it('Writes bazel config with existing config', async () => {
131138
fs.writeFileSync('.bazelrc', 'build --existing_config=foo')
132139
writesBazelRc(
133140
defaultInputs,
134-
'build --existing_config=foo\n' + defaultOutput
141+
'build --existing_config=foo\n' + defaultBazelOutput
135142
)
136143
})
137144

@@ -167,14 +174,70 @@ build --remote_executor=grpcs://scheduler-demo-prefix.uc1.scdev.nativelink.net`
167174
)
168175
})
169176

170-
it('Goes boom on non-error', async () => {
171-
fs.readFileSync = () => {
172-
throw 'bad file'
177+
test.each(['bazel', 'buck2'])(
178+
'%s: goes boom on non-error',
179+
async (build_system) => {
180+
const oldFileSync = fs.readFileSync
181+
fs.readFileSync = () => {
182+
throw 'bad file'
183+
}
184+
const core = makeCore({ ...defaultInputs, build_system })
185+
await run(core)
186+
expect(core.setFailed).toHaveBeenCalledWith(
187+
'An unknown error occurred: \"bad file\"'
188+
)
189+
fs.readFileSync = oldFileSync
173190
}
174-
const core = makeCore(defaultInputs)
191+
)
192+
193+
it('Fails on bad build system', async () => {
194+
const core = makeCore({
195+
...defaultInputs,
196+
build_system: 'not-a-build-system'
197+
})
175198
await run(core)
176199
expect(core.setFailed).toHaveBeenCalledWith(
177-
'An unknown error occurred: \"bad file\"'
200+
'Unknown build system: not-a-build-system'
201+
)
202+
})
203+
204+
const writesBuckConfig = async (
205+
inputs: Record<string, string>,
206+
output: string
207+
) => {
208+
const core = makeCore(inputs)
209+
await run(core)
210+
expect(core.setFailed).not.toHaveBeenCalled()
211+
const expected: Record<string, string> = {}
212+
expected[`${process.cwd()}/.buckconfig`] = output
213+
expect(vol.toJSON()).toEqual(expected)
214+
}
215+
216+
it('Writes buck2 config', async () => {
217+
writesBuckConfig(
218+
{
219+
...defaultInputs,
220+
build_system: 'buck2'
221+
},
222+
defaultBuckOutput
223+
)
224+
})
225+
226+
it('Writes buck2 config with existing', async () => {
227+
fs.writeFileSync(
228+
'.buckconfig',
229+
`[cells]
230+
root = "."`
231+
)
232+
writesBuckConfig(
233+
{
234+
...defaultInputs,
235+
build_system: 'buck2'
236+
},
237+
`${defaultBuckOutput}
238+
239+
[cells]
240+
root = "."`
178241
)
179242
})
180243
})

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ inputs:
1919
prefix:
2020
description: Nativelink Cache Prefix
2121
required: true
22+
build_system:
23+
description: 'Build system: bazel or buck2'
24+
default: bazel
2225
cache_url:
2326
description: Nativelink Cache URL
2427
bes_url:

0 commit comments

Comments
 (0)