@@ -23,6 +23,8 @@ import * as rimraf from 'rimraf';
2323import { Context } from '../../src/context' ;
2424import { Build } from '../../src/buildx/build' ;
2525
26+ import { GitContextFormat } from '../../src/types/buildx/build' ;
27+
2628const fixturesDir = path . join ( __dirname , '..' , '.fixtures' ) ;
2729const tmpDir = fs . mkdtempSync ( path . join ( process . env . TEMP || os . tmpdir ( ) , 'buildx-build-' ) ) ;
2830const tmpName = path . join ( tmpDir , '.tmpname-jest' ) ;
@@ -41,6 +43,37 @@ afterEach(() => {
4143 rimraf . sync ( tmpDir ) ;
4244} ) ;
4345
46+ describe ( 'gitContext' , ( ) => {
47+ const originalEnv = process . env ;
48+ beforeEach ( ( ) => {
49+ jest . resetModules ( ) ;
50+ process . env = {
51+ ...originalEnv ,
52+ DOCKER_GIT_CONTEXT_PR_HEAD_REF : ''
53+ } ;
54+ } ) ;
55+ afterEach ( ( ) => {
56+ process . env = originalEnv ;
57+ } ) ;
58+ // prettier-ignore
59+ test . each ( [
60+ [ 'refs/heads/master' , 'query' , false , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
61+ [ 'master' , 'query' , false , 'https://github.com/docker/actions-toolkit.git?ref=refs/heads/master&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
62+ [ 'refs/pull/15/merge' , 'query' , false , 'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/merge&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
63+ [ 'refs/tags/v1.0.0' , 'query' , false , 'https://github.com/docker/actions-toolkit.git?ref=refs/tags/v1.0.0&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
64+ [ 'refs/pull/15/merge' , 'query' , true , 'https://github.com/docker/actions-toolkit.git?ref=refs/pull/15/head&checksum=860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
65+ [ 'refs/heads/master' , 'fragment' , false , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
66+ [ 'master' , 'fragment' , false , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
67+ [ 'refs/pull/15/merge' , 'fragment' , false , 'https://github.com/docker/actions-toolkit.git#refs/pull/15/merge' ] ,
68+ [ 'refs/tags/v1.0.0' , 'fragment' , false , 'https://github.com/docker/actions-toolkit.git#860c1904a1ce19322e91ac35af1ab07466440c37' ] ,
69+ [ 'refs/pull/15/merge' , 'fragment' , true , 'https://github.com/docker/actions-toolkit.git#refs/pull/15/head' ] ,
70+ ] ) ( 'given %p and %p, should return %p' , async ( ref : string , format : string , prHeadRef : boolean , expected : string ) => {
71+ process . env . DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF = prHeadRef ? 'true' : '' ;
72+ const build = new Build ( ) ;
73+ expect ( await build . gitContext ( ref , '860c1904a1ce19322e91ac35af1ab07466440c37' , format as GitContextFormat ) ) . toEqual ( expected ) ;
74+ } ) ;
75+ } ) ;
76+
4477describe ( 'resolveImageID' , ( ) => {
4578 it ( 'matches' , async ( ) => {
4679 const imageID = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9' ;
0 commit comments