@@ -4,64 +4,79 @@ import jsyaml from 'js-yaml'
4
4
import { execSync } from 'node:child_process'
5
5
import core from '@actions/core'
6
6
import github from '@actions/github'
7
- import { MAIN_BRANCHES } from './const.mjs' ;
7
+ import { MAIN_BRANCHES , RELEASE_BRANCHES } from './const.mjs' ;
8
8
import { glob } from 'glob'
9
9
10
10
const context = github . context
11
11
const branch = getBranch ( )
12
12
const typeOfDeployment = getTypeOfDeployment ( )
13
13
const sha = context . sha
14
- const name = getArtifactname ( )
15
- const url = `https://api.github.com/repos/island-is/island.is/actions/artifacts?name=${ name } `
16
14
17
15
const _KEY_HAS_OUTPUT = 'MQ_HAS_OUTPUT'
18
16
const _KEY_CHANGED_FILES = 'MQ_CHANGED_FILES'
17
+ const changedFiles = [ ]
19
18
20
- const GITHUB_TOKEN = process . env . GITHUB_TOKEN
21
- const STAGE_NAME = typeOfDeployment . dev
22
- ? 'dev'
23
- : typeOfDeployment . staging
24
- ? 'staging'
25
- : typeOfDeployment . prod
26
- ? 'prod'
27
- : 'dev'
28
19
29
- // Read all manifest files
30
- const _MANIFEST_PATHS = [
31
- 'charts/islandis-services' ,
32
- 'charts/judicial-system-services' ,
33
- 'charts/identity-server-services' ,
34
- ]
35
- const files = await glob (
36
- `{${ _MANIFEST_PATHS . join ( ',' ) } }/**/values.${ STAGE_NAME } .yaml` ,
37
- )
38
- const changedFiles = [ ]
39
- const IMAGE_OBJECT = { }
40
- for ( const file of files ) {
41
- const textContent = readFileSync ( file , 'utf8' )
42
- const yamlContent = await jsyaml . load ( textContent )
43
- if (
44
- yamlContent &&
45
- typeof yamlContent === 'object' &&
46
- 'image' in yamlContent &&
47
- yamlContent . image &&
48
- typeof yamlContent . image === 'object' &&
49
- 'repository' in yamlContent . image
50
- ) {
51
- const repository = yamlContent . image . repository
52
- const imageName =
53
- typeof repository == 'string' ? repository . split ( '/' ) . pop ( ) : ''
54
- IMAGE_OBJECT [ imageName ] ??= [ ]
55
- IMAGE_OBJECT [ imageName ] . push ( {
56
- filePath : file ,
57
- content : yamlContent ,
58
- } )
20
+ if ( typeOfDeployment . dev ) {
21
+ await prepareManifests ( 'dev' ) ;
22
+ }
23
+
24
+ if ( typeOfDeployment . staging ) {
25
+ await prepareManifests ( 'staging' ) ;
26
+ }
27
+
28
+ if ( typeOfDeployment . prod ) {
29
+ await prepareManifests ( 'prod' ) ;
30
+ }
31
+
32
+ if ( changedFiles . length > 0 ) {
33
+ console . log ( `Changed files is ${ changedFiles . join ( ',' ) } ` )
34
+ core . setOutput ( _KEY_HAS_OUTPUT , 'true' )
35
+ core . setOutput ( _KEY_CHANGED_FILES , changedFiles . join ( ',' ) )
36
+ } else {
37
+ console . log ( 'No files changed' )
38
+ core . setOutput ( _KEY_HAS_OUTPUT , 'false' )
39
+ }
40
+
41
+ async function prepareManifests ( STAGE_NAME ) {
42
+ const IMAGE_OBJECT = { }
43
+
44
+ // Read all manifest files
45
+ const _MANIFEST_PATHS = [
46
+ 'charts/islandis-services' ,
47
+ 'charts/judicial-system-services' ,
48
+ 'charts/identity-server-services' ,
49
+ ]
50
+ const files = await glob (
51
+ `{${ _MANIFEST_PATHS . join ( ',' ) } }/**/values.${ STAGE_NAME } .yaml` ,
52
+ )
53
+ for ( const file of files ) {
54
+ const textContent = readFileSync ( file , 'utf8' )
55
+ const yamlContent = await jsyaml . load ( textContent )
56
+ if (
57
+ yamlContent &&
58
+ typeof yamlContent === 'object' &&
59
+ 'image' in yamlContent &&
60
+ yamlContent . image &&
61
+ typeof yamlContent . image === 'object' &&
62
+ 'repository' in yamlContent . image
63
+ ) {
64
+ const repository = yamlContent . image . repository
65
+ const imageName =
66
+ typeof repository == 'string' ? repository . split ( '/' ) . pop ( ) : ''
67
+ IMAGE_OBJECT [ imageName ] ??= [ ]
68
+ IMAGE_OBJECT [ imageName ] . push ( {
69
+ filePath : file ,
70
+ content : yamlContent ,
71
+ } )
72
+ }
59
73
}
74
+
75
+ await parseData ( IMAGE_OBJECT )
60
76
}
61
77
62
- await parseData ( )
63
78
64
- async function parseData ( ) {
79
+ async function parseData ( IMAGE_OBJECT ) {
65
80
const fileName = `/tmp/data.json`
66
81
if ( ! fs . existsSync ( fileName ) ) {
67
82
process . exit ( 0 )
@@ -85,9 +100,6 @@ async function parseData() {
85
100
console . info ( `Skipping ${ imageName } …` )
86
101
}
87
102
}
88
- console . log ( `Changed files is ${ changedFiles . join ( ',' ) } ` )
89
- core . setOutput ( _KEY_HAS_OUTPUT , 'true' )
90
- core . setOutput ( _KEY_CHANGED_FILES , changedFiles . join ( ',' ) )
91
103
}
92
104
93
105
function getBranch ( ) {
@@ -105,27 +117,12 @@ function getTypeOfDeployment() {
105
117
prod : false ,
106
118
}
107
119
}
108
- if ( branch . startsWith ( 'release' ) ) {
120
+ if ( RELEASE_BRANCHES . includes ( branch ) ) {
109
121
return {
110
122
dev : false ,
111
- staging : false ,
123
+ staging : true ,
112
124
prod : true ,
113
125
}
114
126
}
115
- return {
116
- dev : false ,
117
- staging : false ,
118
- prod : false ,
119
- }
120
- }
121
-
122
- function getArtifactname ( ) {
123
- if ( typeOfDeployment . dev ) {
124
- return `main-${ sha } `
125
- }
126
- if ( typeOfDeployment . prod ) {
127
- return `release-${ sha } `
128
- }
129
-
130
- throw new Error ( `Unsupported` )
127
+ throw new Error ( `Unsupported branch: ${ branch } ` )
131
128
}
0 commit comments