@@ -19,22 +19,41 @@ const mockFileContent = (raw: string) => ({ raw, sha: 'sha' });
19
19
20
20
const latestVersion = '2.325.0' ;
21
21
const archDigests = {
22
- amd64 : 'sha256:amd64digest' ,
23
- arm64 : 'sha256:arm64digest' ,
22
+ amd64 : '2.325.0@ sha256:amd64digest' ,
23
+ arm64 : '2.325.0@ sha256:arm64digest' ,
24
24
} ;
25
25
26
26
const newWinDockerFile = 'ARG RUNNER_VERSION=2.325.0' ;
27
27
const oldWinDockerFile = 'ARG RUNNER_VERSION=2.324.0' ;
28
28
29
29
const oldLinuxImages = {
30
- amd64 : 'ghcr.io/actions/actions-runner: 2.324.0@sha256:oldamd64' ,
31
- arm64 : 'ghcr.io/actions/actions-runner: 2.324.0@sha256:oldarm64' ,
30
+ amd64 : '2.324.0@sha256:oldamd64' ,
31
+ arm64 : '2.324.0@sha256:oldarm64' ,
32
32
} ;
33
33
const newLinuxImages = {
34
34
amd64 : archDigests . amd64 ,
35
35
arm64 : archDigests . arm64 ,
36
36
} ;
37
37
38
+ function generateFileContent ( images ) {
39
+ return `
40
+ {{- if eq .cpuArch "amd64" }}
41
+ image: ghcr.io/actions/actions-runner:${ images . amd64 }
42
+ {{- else }}
43
+ image: ghcr.io/actions/actions-runner:${ images . arm64 }
44
+ {{- end }}
45
+ {{ more content here }}
46
+ {{- if eq .cpuArch "amd64" }}
47
+ image: ghcr.io/actions/actions-runner:${ images . amd64 }
48
+ {{- else }}
49
+ image: ghcr.io/actions/actions-runner:${ images . arm64 }
50
+ {{- end }}
51
+ ` ;
52
+ }
53
+
54
+ const oldLinuxFileContent = generateFileContent ( oldLinuxImages ) ;
55
+ const newLinuxFileContent = generateFileContent ( newLinuxImages ) ;
56
+
38
57
beforeEach ( ( ) => {
39
58
vi . clearAllMocks ( ) ;
40
59
( getOctokit as any ) . mockResolvedValue ( mockOctokit ) ;
@@ -45,7 +64,7 @@ beforeEach(() => {
45
64
vi . mocked ( arcImage . getFileContent ) . mockImplementation ( async ( _octokit : any , file : string ) => {
46
65
if ( file === constants . WINDOWS_DOCKER_FILE ) return mockFileContent ( oldWinDockerFile ) ;
47
66
if ( file === constants . ARC_RUNNER_ENVIRONMENTS . prod )
48
- return mockFileContent ( `amd64: ${ oldLinuxImages . amd64 } \narm64: ${ oldLinuxImages . arm64 } ` ) ;
67
+ return mockFileContent ( generateFileContent ( oldLinuxImages ) ) ;
49
68
return mockFileContent ( '' ) ;
50
69
} ) ;
51
70
vi . mocked ( arcImage . getCurrentWindowsRunnerVersion ) . mockImplementation (
@@ -59,33 +78,69 @@ beforeEach(() => {
59
78
} ) ;
60
79
61
80
describe ( 'rollActionsRunner' , ( ) => {
81
+ it ( 'should update both linx and windows if version is outdated' , async ( ) => {
82
+ await rollActionsRunner ( ) ;
83
+ expect ( rollInfraModule . rollInfra ) . toHaveBeenCalledTimes ( 2 ) ;
84
+ expect ( rollInfraModule . rollInfra ) . toHaveBeenNthCalledWith (
85
+ 1 ,
86
+ 'prod/actions-runner' ,
87
+ 'github actions runner images' ,
88
+ latestVersion ,
89
+ constants . WINDOWS_DOCKER_FILE ,
90
+ newWinDockerFile ,
91
+ ) ;
92
+ expect ( rollInfraModule . rollInfra ) . toHaveBeenNthCalledWith (
93
+ 2 ,
94
+ 'prod/actions-runner' ,
95
+ 'github actions runner images' ,
96
+ latestVersion ,
97
+ constants . ARC_RUNNER_ENVIRONMENTS . prod ,
98
+ newLinuxFileContent ,
99
+ ) ;
100
+ } ) ;
101
+
62
102
it ( 'should update windows runner if version is outdated' , async ( ) => {
103
+ vi . mocked ( arcImage . getFileContent ) . mockImplementation ( async ( _octokit : any , file : string ) => {
104
+ if ( file === constants . WINDOWS_DOCKER_FILE ) return mockFileContent ( oldWinDockerFile ) ;
105
+ if ( file === constants . ARC_RUNNER_ENVIRONMENTS . prod )
106
+ return mockFileContent ( newLinuxFileContent ) ;
107
+ return mockFileContent ( '' ) ;
108
+ } ) ;
63
109
await rollActionsRunner ( ) ;
110
+ expect ( rollInfraModule . rollInfra ) . toHaveBeenCalledTimes ( 1 ) ;
64
111
expect ( rollInfraModule . rollInfra ) . toHaveBeenCalledWith (
65
112
'prod/actions-runner' ,
66
113
'github actions runner images' ,
67
114
latestVersion ,
68
115
constants . WINDOWS_DOCKER_FILE ,
69
- expect . stringContaining ( latestVersion ) ,
116
+ newWinDockerFile ,
70
117
) ;
71
118
} ) ;
72
119
73
120
it ( 'should update linux images if digests are outdated' , async ( ) => {
121
+ vi . mocked ( arcImage . getFileContent ) . mockImplementation ( async ( _octokit : any , file : string ) => {
122
+ if ( file === constants . WINDOWS_DOCKER_FILE ) return mockFileContent ( newWinDockerFile ) ;
123
+ if ( file === constants . ARC_RUNNER_ENVIRONMENTS . prod )
124
+ return mockFileContent ( oldLinuxFileContent ) ;
125
+ return mockFileContent ( '' ) ;
126
+ } ) ;
127
+
74
128
await rollActionsRunner ( ) ;
129
+ expect ( rollInfraModule . rollInfra ) . toHaveBeenCalledTimes ( 1 ) ;
75
130
expect ( rollInfraModule . rollInfra ) . toHaveBeenCalledWith (
76
131
'prod/actions-runner' ,
77
132
'github actions runner images' ,
78
133
latestVersion ,
79
134
constants . ARC_RUNNER_ENVIRONMENTS . prod ,
80
- expect . any ( String ) ,
135
+ newLinuxFileContent ,
81
136
) ;
82
137
} ) ;
83
138
84
139
it ( 'should skip update if everything is up-to-date' , async ( ) => {
85
140
vi . mocked ( arcImage . getFileContent ) . mockImplementation ( async ( _octokit : any , file : string ) => {
86
141
if ( file === constants . WINDOWS_DOCKER_FILE ) return mockFileContent ( newWinDockerFile ) ;
87
142
if ( file === constants . ARC_RUNNER_ENVIRONMENTS . prod )
88
- return mockFileContent ( `amd64: ${ archDigests . amd64 } \narm64: ${ archDigests . arm64 } ` ) ;
143
+ return mockFileContent ( newLinuxFileContent ) ;
89
144
return mockFileContent ( '' ) ;
90
145
} ) ;
91
146
vi . mocked ( arcImage . getCurrentWindowsRunnerVersion ) . mockImplementation (
0 commit comments