@@ -3,13 +3,15 @@ import * as path from 'path'
33import * as process from 'process'
44
55import {
6- createInitializedTempGitDir ,
6+ createInitializedGitRepo ,
77 createInitializedTempGnuPGHomeDir ,
88 dummyPayload ,
99 getLatestCommitHash ,
1010 gitLogForLatestCommit
1111} from '../../src/__tests__/helpers'
1212
13+ import { GitRepo } from '../../src/git-repo'
14+
1315import { expect } from '@jest/globals'
1416import { getErrorMessage } from '../../src/error'
1517import { testConfiguration } from '../../src/__tests__/config'
@@ -32,11 +34,11 @@ function executeAction(env): string | Buffer {
3234 return output
3335}
3436
35- function createJob ( gitRepoDir ) : string | Buffer {
37+ function createJob ( gitRepo : GitRepo ) : string | Buffer {
3638 const env = {
3739 ...process . env ,
3840 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
39- INPUT_GIT_REPO_DIR : gitRepoDir ,
41+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
4042 INPUT_ACTION : 'create-job' ,
4143 INPUT_JOB_PAYLOAD : dummyPayload ( ) ,
4244 INPUT_GIT_COMMIT_NO_GPG_SIGN : true
@@ -67,12 +69,12 @@ function getOutputVariable(
6769
6870describe ( 'GitHub Action' , ( ) => {
6971 it ( 'should print the git repo dir at the beginning of the action execution' , async ( ) => {
70- const gitRepoDir = await createInitializedTempGitDir ( )
72+ const gitRepo = await createInitializedGitRepo ( )
7173
7274 const env = {
7375 ...process . env ,
7476 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
75- INPUT_GIT_REPO_DIR : gitRepoDir ,
77+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
7678 INPUT_ACTION : 'next-job' ,
7779 INPUT_JOB_PAYLOAD : dummyPayload ( ) ,
7880 INPUT_GIT_COMMIT_NO_GPG_SIGN : true
@@ -81,17 +83,17 @@ describe('GitHub Action', () => {
8183 const output = executeAction ( env )
8284
8385 expect ( output ) . toEqual (
84- expect . stringContaining ( `git_repo_dir: ${ gitRepoDir } ` )
86+ expect . stringContaining ( `git_repo_dir: ${ gitRepo . getDirPath ( ) } ` )
8587 )
8688 } )
8789
8890 it ( 'should return an error for invalid actions' , async ( ) => {
89- const gitRepoDir = await createInitializedTempGitDir ( )
91+ const gitRepo = await createInitializedGitRepo ( )
9092
9193 const env = {
9294 ...process . env ,
9395 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
94- INPUT_GIT_REPO_DIR : gitRepoDir ,
96+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
9597 INPUT_ACTION : 'INVALID ACTION' ,
9698 INPUT_JOB_PAYLOAD : dummyPayload ( ) ,
9799 INPUT_GIT_COMMIT_NO_GPG_SIGN : true
@@ -107,12 +109,12 @@ describe('GitHub Action', () => {
107109 } )
108110
109111 it ( 'should create a new job' , async ( ) => {
110- const gitRepoDir = await createInitializedTempGitDir ( )
112+ const gitRepo = await createInitializedGitRepo ( )
111113
112114 const env = {
113115 ...process . env ,
114116 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
115- INPUT_GIT_REPO_DIR : gitRepoDir ,
117+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
116118 INPUT_ACTION : 'create-job' ,
117119 INPUT_JOB_PAYLOAD : dummyPayload ( ) ,
118120 INPUT_GIT_COMMIT_NO_GPG_SIGN : true
@@ -122,19 +124,19 @@ describe('GitHub Action', () => {
122124
123125 expect ( getOutputVariable ( 'job_created' , output . toString ( ) ) ) . toBe ( 'true' )
124126 expect ( getOutputVariable ( 'job_commit' , output . toString ( ) ) ) . toBe (
125- getLatestCommitHash ( gitRepoDir )
127+ getLatestCommitHash ( gitRepo . getDirPath ( ) )
126128 )
127129 } )
128130
129131 it ( 'should get the next job' , async ( ) => {
130- const gitRepoDir = await createInitializedTempGitDir ( )
132+ const gitRepo = await createInitializedGitRepo ( )
131133
132- createJob ( gitRepoDir )
134+ createJob ( gitRepo )
133135
134136 const env = {
135137 ...process . env ,
136138 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
137- INPUT_GIT_REPO_DIR : gitRepoDir ,
139+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
138140 INPUT_ACTION : 'next-job' ,
139141 INPUT_GIT_COMMIT_NO_GPG_SIGN : 'true'
140142 }
@@ -145,19 +147,19 @@ describe('GitHub Action', () => {
145147 dummyPayload ( )
146148 )
147149 expect ( getOutputVariable ( 'job_commit' , output . toString ( ) ) ) . toBe (
148- getLatestCommitHash ( gitRepoDir )
150+ getLatestCommitHash ( gitRepo . getDirPath ( ) )
149151 )
150152 } )
151153
152154 it ( 'should mark the pending job as started' , async ( ) => {
153- const gitRepoDir = await createInitializedTempGitDir ( )
155+ const gitRepo = await createInitializedGitRepo ( )
154156
155- createJob ( gitRepoDir )
157+ createJob ( gitRepo )
156158
157159 const env = {
158160 ...process . env ,
159161 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
160- INPUT_GIT_REPO_DIR : gitRepoDir ,
162+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
161163 INPUT_ACTION : 'start-job' ,
162164 INPUT_GIT_COMMIT_NO_GPG_SIGN : 'true'
163165 }
@@ -166,44 +168,44 @@ describe('GitHub Action', () => {
166168
167169 expect ( getOutputVariable ( 'job_started' , output . toString ( ) ) ) . toBe ( 'true' )
168170 expect ( getOutputVariable ( 'job_commit' , output . toString ( ) ) ) . toBe (
169- getLatestCommitHash ( gitRepoDir )
171+ getLatestCommitHash ( gitRepo . getDirPath ( ) )
170172 )
171173 } )
172174
173175 it ( 'should mark the pending job as finished' , async ( ) => {
174- const gitRepoDir = await createInitializedTempGitDir ( )
176+ const gitRepo = await createInitializedGitRepo ( )
175177
176- createJob ( gitRepoDir )
178+ createJob ( gitRepo )
177179
178180 executeAction ( {
179181 ...process . env ,
180182 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
181- INPUT_GIT_REPO_DIR : gitRepoDir ,
183+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
182184 INPUT_ACTION : 'start-job' ,
183185 INPUT_GIT_COMMIT_NO_GPG_SIGN : 'true'
184186 } )
185187
186188 const output = executeAction ( {
187189 ...process . env ,
188190 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
189- INPUT_GIT_REPO_DIR : gitRepoDir ,
191+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
190192 INPUT_ACTION : 'finish-job' ,
191193 INPUT_GIT_COMMIT_NO_GPG_SIGN : 'true'
192194 } )
193195
194196 expect ( getOutputVariable ( 'job_finished' , output . toString ( ) ) ) . toBe ( 'true' )
195197 expect ( getOutputVariable ( 'job_commit' , output . toString ( ) ) ) . toBe (
196- getLatestCommitHash ( gitRepoDir )
198+ getLatestCommitHash ( gitRepo . getDirPath ( ) )
197199 )
198200 } )
199201
200202 it ( 'should allow to overwrite commit author' , async ( ) => {
201- const gitRepoDir = await createInitializedTempGitDir ( )
203+ const gitRepo = await createInitializedGitRepo ( )
202204
203205 const env = {
204206 ...process . env ,
205207 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
206- INPUT_GIT_REPO_DIR : gitRepoDir ,
208+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
207209 INPUT_ACTION : 'create-job' ,
208210 INPUT_JOB_PAYLOAD : dummyPayload ( ) ,
209211 INPUT_GIT_COMMIT_NO_GPG_SIGN : 'true' ,
@@ -212,23 +214,23 @@ describe('GitHub Action', () => {
212214
213215 executeAction ( env )
214216
215- const gitLogOutput = gitLogForLatestCommit ( gitRepoDir )
217+ const gitLogOutput = gitLogForLatestCommit ( gitRepo . getDirPath ( ) )
216218
217219 expect ( gitLogOutput ) . toEqual (
218220 expect . stringContaining ( 'Author: A committer <[email protected] >' ) 219221 )
220222 } )
221223
222224 it ( 'should allow to overwrite commit signing key' , async ( ) => {
223- const gitRepoDir = await createInitializedTempGitDir ( )
225+ const gitRepo = await createInitializedGitRepo ( )
224226 const gnuPGHomeDir = await createInitializedTempGnuPGHomeDir ( )
225227 const signingKeyFingerprint =
226228 testConfiguration ( ) . gpg_signing_key . fingerprint
227229
228230 const env = {
229231 ...process . env ,
230232 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
231- INPUT_GIT_REPO_DIR : gitRepoDir ,
233+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
232234 INPUT_ACTION : 'create-job' ,
233235 INPUT_JOB_PAYLOAD : dummyPayload ( ) ,
234236 INPUT_GIT_COMMIT_GPG_SIGN : signingKeyFingerprint ,
@@ -237,7 +239,7 @@ describe('GitHub Action', () => {
237239
238240 executeAction ( env )
239241
240- const gitLogOutput = gitLogForLatestCommit ( gitRepoDir )
242+ const gitLogOutput = gitLogForLatestCommit ( gitRepo . getDirPath ( ) )
241243
242244 expect ( gitLogOutput ) . toEqual (
243245 expect . stringContaining (
@@ -247,20 +249,20 @@ describe('GitHub Action', () => {
247249 } )
248250
249251 it ( 'should allow to disable commit signing for a given commit' , async ( ) => {
250- const gitRepoDir = await createInitializedTempGitDir ( )
252+ const gitRepo = await createInitializedGitRepo ( )
251253
252254 const env = {
253255 ...process . env ,
254256 INPUT_QUEUE_NAME : 'QUEUE-NAME' ,
255- INPUT_GIT_REPO_DIR : gitRepoDir ,
257+ INPUT_GIT_REPO_DIR : gitRepo . getDirPath ( ) ,
256258 INPUT_ACTION : 'create-job' ,
257259 INPUT_JOB_PAYLOAD : dummyPayload ( ) ,
258260 INPUT_GIT_COMMIT_NO_GPG_SIGN : 'true'
259261 }
260262
261263 executeAction ( env )
262264
263- const gitLogOutput = gitLogForLatestCommit ( gitRepoDir )
265+ const gitLogOutput = gitLogForLatestCommit ( gitRepo . getDirPath ( ) )
264266
265267 expect ( ! gitLogOutput . includes ( 'gpg: Signature' ) ) . toBe ( true )
266268
0 commit comments