1
1
/* eslint-disable no-console */
2
- import type { HashElementOptions } from 'folder-hash' ;
2
+ import crypto from 'crypto' ;
3
+
3
4
import { hashElement } from 'folder-hash' ;
4
5
6
+ import { toAbsolutePath } from '../common' ;
7
+
5
8
import { getNbGitDiff } from './utils' ;
6
9
7
10
const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript' ;
@@ -16,20 +19,10 @@ const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript';
16
19
*
17
20
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
18
21
*/
19
- const VARIABLES_TO_CHECK : Array < {
20
- name : string ;
21
- path : string [ ] ;
22
- needHash ?: boolean ;
23
- hashOptions ?: HashElementOptions ;
24
- } > = [
22
+ const VARIABLES_TO_CHECK = [
25
23
{
26
24
name : 'GITHUB_ACTIONS_CHANGED' ,
27
25
path : [ '.github/actions' , '.github/workflows' , '.github/.cache_version' ] ,
28
- needHash : true ,
29
- hashOptions : {
30
- folders : { include : [ '.github/actions' , '.github/workflows' ] } ,
31
- files : { include : [ '.github/.cache_version' ] } ,
32
- } ,
33
26
} ,
34
27
{
35
28
name : 'SPECS_CHANGED' ,
@@ -46,10 +39,6 @@ const VARIABLES_TO_CHECK: Array<{
46
39
{
47
40
name : 'SCRIPTS_CHANGED' ,
48
41
path : [ 'scripts' ] ,
49
- needHash : true ,
50
- hashOptions : {
51
- folders : { include : [ 'scripts' ] } ,
52
- } ,
53
42
} ,
54
43
{
55
44
name : 'GENERATORS_CHANGED' ,
@@ -106,6 +95,28 @@ const VARIABLES_TO_CHECK: Array<{
106
95
} ,
107
96
] ;
108
97
98
+ async function computeCommonHash ( ) : Promise < string > {
99
+ const hashGA = await hashElement ( toAbsolutePath ( '.github' ) , {
100
+ encoding : 'hex' ,
101
+ folders : { exclude : [ 'ISSUE_TEMPLATE' ] } ,
102
+ files : { include : [ '*.yml' , '.cache_version' ] } ,
103
+ } ) ;
104
+ const hashScripts = await hashElement ( toAbsolutePath ( 'scripts' ) , {
105
+ encoding : 'hex' ,
106
+ folders : { exclude : [ 'docker' , '__tests__' ] } ,
107
+ } ) ;
108
+ const hashConfig = await hashElement ( toAbsolutePath ( '.' ) , {
109
+ encoding : 'hex' ,
110
+ folders : { include : [ 'config' ] } ,
111
+ files : { include : [ 'openapitools.json' , 'clients.config.json' ] } ,
112
+ } ) ;
113
+
114
+ return crypto
115
+ . createHash ( 'sha256' )
116
+ . update ( `${ hashGA . hash } -${ hashScripts . hash } -${ hashConfig . hash } ` )
117
+ . digest ( 'hex' ) ;
118
+ }
119
+
109
120
/**
110
121
* Outputs variables used in the CI to determine if a job should run.
111
122
*/
@@ -124,14 +135,10 @@ async function setRunVariables({
124
135
125
136
console . log ( `Found ${ diff } changes for '${ check . name } '` ) ;
126
137
console . log ( `::set-output name=${ check . name } ::${ diff } ` ) ;
127
- if ( diff && check . needHash ) {
128
- const hash = (
129
- await hashElement ( '.' , { encoding : 'hex' , ...check . hashOptions } )
130
- ) . hash ;
131
- console . log ( `::set-output name=${ check . name } _HASH::${ hash } ` ) ;
132
- }
133
138
}
134
139
140
+ console . log ( `::set-output name=COMMON_HASH::${ await computeCommonHash ( ) } ` ) ;
141
+
135
142
console . log ( `::set-output name=ORIGIN_BRANCH::${ originBranch } ` ) ;
136
143
}
137
144
0 commit comments