@@ -8,7 +8,7 @@ import * as exec from '@actions/exec'
88import * as build from '../src/build'
99import * as tools from '../src/tools'
1010
11- const default_base = 'core20 '
11+ const default_base = 'core22 '
1212
1313afterEach ( ( ) => {
1414 jest . restoreAllMocks ( )
@@ -21,8 +21,9 @@ test('SnapcraftBuilder expands tilde in project root', () => {
2121 'stable' ,
2222 '' ,
2323 '' ,
24- '' ,
25- false
24+ [ ] ,
25+ false ,
26+ ''
2627 )
2728 expect ( builder . projectRoot ) . toBe ( os . homedir ( ) )
2829
@@ -32,8 +33,9 @@ test('SnapcraftBuilder expands tilde in project root', () => {
3233 'stable' ,
3334 '' ,
3435 '' ,
35- '' ,
36- false
36+ [ ] ,
37+ false ,
38+ ''
3739 )
3840 expect ( builder . projectRoot ) . toBe ( path . join ( os . homedir ( ) , 'foo/bar' ) )
3941} )
@@ -65,7 +67,7 @@ for (const base of ['core', 'core18', 'core20', 'core22']) {
6567}
6668for ( const [ base , arch , channel ] of matrix ) {
6769 test ( `SnapcraftBuilder.build runs a snap build using Docker with base: ${ base } ; and arch: ${ arch } ` , async ( ) => {
68- expect . assertions ( 3 )
70+ expect . assertions ( 4 )
6971
7072 const ensureDockerExperimentalMock = jest
7173 . spyOn ( tools , 'ensureDockerExperimental' )
@@ -75,6 +77,9 @@ for (const [base, arch, channel] of matrix) {
7577 . mockImplementation (
7678 async ( projectRoot : string ) : Promise < string > => Promise . resolve ( base )
7779 )
80+ const detectCGroupsV1Mock = jest
81+ . spyOn ( tools , 'detectCGroupsV1' )
82+ . mockImplementation ( async ( ) : Promise < boolean > => Promise . resolve ( true ) )
7883 const execMock = jest
7984 . spyOn ( exec , 'exec' )
8085 . mockImplementation (
@@ -90,8 +95,9 @@ for (const [base, arch, channel] of matrix) {
9095 'stable' ,
9196 '' ,
9297 arch ,
93- '' ,
94- false
98+ [ ] ,
99+ false ,
100+ ''
95101 )
96102 await builder . build ( )
97103
@@ -102,6 +108,11 @@ for (const [base, arch, channel] of matrix) {
102108
103109 expect ( ensureDockerExperimentalMock ) . toHaveBeenCalled ( )
104110 expect ( detectBaseMock ) . toHaveBeenCalled ( )
111+ if ( base === 'core ') {
112+ expect ( detectCGroupsV1Mock ) . toHaveBeenCalled ( )
113+ } else {
114+ expect ( detectCGroupsV1Mock ) . not . toHaveBeenCalled ( )
115+ }
105116 expect ( execMock ) . toHaveBeenCalledWith (
106117 'docker' ,
107118 [
@@ -130,8 +141,7 @@ for (const [base, arch, channel] of matrix) {
130141 } )
131142
132143 test ( `SnapcraftBuilder.build runs a snap build using Podman with base: ${ base } ; and arch: ${ arch } ` , async ( ) => {
133- expect . assertions ( 3 )
134-
144+ expect . assertions ( 4 )
135145 const ensureDockerExperimentalMock = jest
136146 . spyOn ( tools , 'ensureDockerExperimental' )
137147 . mockImplementation ( async ( ) : Promise < void > => Promise . resolve ( ) )
@@ -140,6 +150,9 @@ for (const [base, arch, channel] of matrix) {
140150 . mockImplementation (
141151 async ( projectRoot : string ) : Promise < string > => Promise . resolve ( base )
142152 )
153+ const detectCGroupsV1Mock = jest
154+ . spyOn ( tools , 'detectCGroupsV1' )
155+ . mockImplementation ( async ( ) : Promise < boolean > => Promise . resolve ( true ) )
143156 const execMock = jest
144157 . spyOn ( exec , 'exec' )
145158 . mockImplementation (
@@ -155,13 +168,19 @@ for (const [base, arch, channel] of matrix) {
155168 'stable' ,
156169 '' ,
157170 arch ,
158- '' ,
159- true
171+ [ ] ,
172+ true ,
173+ ''
160174 )
161175 await builder . build ( )
162176
163177 expect ( ensureDockerExperimentalMock ) . not . toHaveBeenCalled ( )
164178 expect ( detectBaseMock ) . toHaveBeenCalled ( )
179+ if ( base === 'core' ) {
180+ expect ( detectCGroupsV1Mock ) . toHaveBeenCalled ( )
181+ } else {
182+ expect ( detectCGroupsV1Mock ) . not . toHaveBeenCalled ( )
183+ }
165184 expect ( execMock ) . toHaveBeenCalledWith (
166185 'sudo podman' ,
167186 [
@@ -214,8 +233,9 @@ test('SnapcraftBuilder.build can disable build info', async () => {
214233 'stable' ,
215234 '' ,
216235 '' ,
217- '' ,
218- false
236+ [ ] ,
237+ false ,
238+ ''
219239 )
220240 await builder . build ( )
221241
@@ -266,8 +286,62 @@ test('SnapcraftBuilder.build can pass additional arguments', async () => {
266286 'stable' ,
267287 '--foo --bar' ,
268288 '' ,
289+ [ ] ,
290+ false ,
291+ ''
292+ )
293+ await builder . build ( )
294+
295+ expect ( execMock ) . toHaveBeenCalledWith (
296+ 'docker' ,
297+ [
298+ 'run' ,
299+ '--rm' ,
300+ '--tty' ,
301+ '--privileged' ,
302+ '--volume' ,
303+ `${ process . cwd ( ) } :/data` ,
304+ '--workdir' ,
305+ '/data' ,
306+ '--env' ,
307+ `SNAPCRAFT_IMAGE_INFO={"build_url":"https://github.com/user/repo/actions/runs/42"}` ,
308+ '--env' ,
309+ 'USE_SNAPCRAFT_CHANNEL=stable' ,
310+ `diddledani/snapcraft:${ default_base } ` ,
311+ 'snapcraft' ,
312+ '--foo' ,
313+ '--bar'
314+ ] ,
315+ expect . anything ( )
316+ )
317+ } )
318+
319+ test ( 'SnapcraftBuilder.build can pass extra environment variables' , async ( ) => {
320+ expect . assertions ( 1 )
321+
322+ const ensureDockerExperimentalMock = jest
323+ . spyOn ( tools , 'ensureDockerExperimental' )
324+ . mockImplementation ( async ( ) : Promise < void > => Promise . resolve ( ) )
325+ const detectBaseMock = jest
326+ . spyOn ( tools , 'detectBase' )
327+ . mockImplementation (
328+ async ( projectRoot : string ) : Promise < string > => default_base
329+ )
330+ const execMock = jest
331+ . spyOn ( exec , 'exec' )
332+ . mockImplementation (
333+ async ( program : string , args ?: string [ ] ) : Promise < number > => 0
334+ )
335+
336+ const builder = new build . SnapcraftBuilder (
337+ '.' ,
338+ false ,
339+ 'stable' ,
340+ '--foo --bar' ,
269341 '' ,
270- false
342+ [ 'FOO=bar' , 'BAZ=qux' ] ,
343+ false ,
344+ ''
271345 )
272346 await builder . build ( )
273347
@@ -283,6 +357,10 @@ test('SnapcraftBuilder.build can pass additional arguments', async () => {
283357 '--workdir' ,
284358 '/data' ,
285359 '--env' ,
360+ 'FOO=bar' ,
361+ '--env' ,
362+ 'BAZ=qux' ,
363+ '--env' ,
286364 `SNAPCRAFT_IMAGE_INFO={"build_url":"https://github.com/user/repo/actions/runs/42"}` ,
287365 '--env' ,
288366 'USE_SNAPCRAFT_CHANNEL=stable' ,
@@ -295,6 +373,61 @@ test('SnapcraftBuilder.build can pass additional arguments', async () => {
295373 )
296374} )
297375
376+ test ( 'SnapcraftBuilder.build adds store credentials' , async ( ) => {
377+ expect . assertions ( 1 )
378+
379+ const ensureDockerExperimentalMock = jest
380+ . spyOn ( tools , 'ensureDockerExperimental' )
381+ . mockImplementation ( async ( ) : Promise < void > => Promise . resolve ( ) )
382+ const detectBaseMock = jest
383+ . spyOn ( tools , 'detectBase' )
384+ . mockImplementation (
385+ async ( projectRoot : string ) : Promise < string > => default_base
386+ )
387+ const execMock = jest
388+ . spyOn ( exec , 'exec' )
389+ . mockImplementation (
390+ async ( program : string , args ?: string [ ] ) : Promise < number > => 0
391+ )
392+
393+ const builder = new build . SnapcraftBuilder (
394+ '.' ,
395+ false ,
396+ 'stable' ,
397+ '--foo --bar' ,
398+ '' ,
399+ [ ] ,
400+ false ,
401+ 'TEST_STORE_CREDENTIALS'
402+ )
403+ await builder . build ( )
404+
405+ expect ( execMock ) . toHaveBeenCalledWith (
406+ 'docker' ,
407+ [
408+ 'run' ,
409+ '--rm' ,
410+ '--tty' ,
411+ '--privileged' ,
412+ '--volume' ,
413+ `${ process . cwd ( ) } :/data` ,
414+ '--workdir' ,
415+ '/data' ,
416+ '--env' ,
417+ `SNAPCRAFT_IMAGE_INFO={"build_url":"https://github.com/user/repo/actions/runs/42"}` ,
418+ '--env' ,
419+ 'USE_SNAPCRAFT_CHANNEL=stable' ,
420+ '--env' ,
421+ 'SNAPCRAFT_STORE_CREDENTIALS=TEST_STORE_CREDENTIALS' ,
422+ `diddledani/snapcraft:${ default_base } ` ,
423+ 'snapcraft' ,
424+ '--foo' ,
425+ '--bar'
426+ ] ,
427+ expect . anything ( )
428+ )
429+ } )
430+
298431test ( 'SnapcraftBuilder.outputSnap fails if there are no snaps' , async ( ) => {
299432 expect . assertions ( 2 )
300433
@@ -305,8 +438,9 @@ test('SnapcraftBuilder.outputSnap fails if there are no snaps', async () => {
305438 'stable' ,
306439 '' ,
307440 '' ,
308- '' ,
309- false
441+ [ ] ,
442+ false ,
443+ ''
310444 )
311445
312446 const readdir = jest
@@ -331,8 +465,9 @@ test('SnapcraftBuilder.outputSnap returns the first snap', async () => {
331465 'stable' ,
332466 '' ,
333467 '' ,
334- '' ,
335- false
468+ [ ] ,
469+ false ,
470+ ''
336471 )
337472
338473 const readdir = jest
0 commit comments