@@ -5,8 +5,13 @@ const execAsync = util.promisify(exec);
5
5
6
6
module . exports = async ( { github, context, versionType } ) => {
7
7
async function configureGit ( ) {
8
- await execAsync ( 'git config user.name "github-actions"' ) ;
9
- await execAsync ( 'git config user.email "github-actions@github.com"' ) ;
8
+ try {
9
+ await execAsync ( 'git config user.name "github-actions"' ) ;
10
+ await execAsync ( 'git config user.email "github-actions@github.com"' ) ;
11
+ } catch ( e ) {
12
+ console . log ( "Error in configuring git user" ) ;
13
+ throw Error ( e ) ;
14
+ }
10
15
11
16
console . log ( "Configured git user" ) ;
12
17
}
@@ -16,43 +21,55 @@ module.exports = async ({ github, context, versionType }) => {
16
21
try {
17
22
await execAsync ( `npm version ${ versionType } ` ) ;
18
23
} catch ( e ) {
19
- console . error ( e ) ;
20
- // console.log("Error in incrementing version", e);
24
+ console . log ( "Error in incrementing version" ) ;
21
25
throw Error ( e ) ;
22
26
}
23
- console . log ( "Version incremented" ) ;
24
27
const packageJson = require ( "../../package.json" ) ;
25
- console . log ( "packageJson" ) ;
26
28
const version = packageJson . version ;
27
29
console . log ( `Incremented version to v${ version } (${ versionType } )` ) ;
28
30
const featureBranch = `chore-increment-verion-${ version } -${ versionType } -${ context . runNumber } ` ;
29
31
return { featureBranch, version } ;
30
32
}
31
33
32
34
async function pushChangesAndTags ( featureBranch ) {
33
- await execAsync ( `git push origin HEAD:refs/heads/${ featureBranch } ` ) ;
34
- await execAsync ( "git push origin --tags" ) ;
35
+ try {
36
+ await execAsync ( `git push origin HEAD:refs/heads/${ featureBranch } ` ) ;
37
+ await execAsync ( "git push origin --tags" ) ;
38
+ } catch ( e ) {
39
+ console . log ( "Error in pushing changes and tags" ) ;
40
+ throw Error ( e ) ;
41
+ }
35
42
}
36
43
37
44
async function getPull ( source , target ) {
38
- const existingPr = await github . pulls . list ( {
39
- owner : context . repo . owner ,
40
- repo : context . repo . repo ,
41
- head : source ,
42
- base : target ,
43
- } ) ;
44
- return existingPr . data . length > 0 ;
45
+ try {
46
+ const existingPr = await github . pulls . list ( {
47
+ owner : context . repo . owner ,
48
+ repo : context . repo . repo ,
49
+ head : source ,
50
+ base : target ,
51
+ } ) ;
52
+ return existingPr . data . length > 0 ;
53
+ } catch ( e ) {
54
+ console . log ( "Error in getting pull request" ) ;
55
+ throw Error ( e ) ;
56
+ }
45
57
}
46
58
47
59
async function createPull ( title , source , target ) {
48
- await github . pulls . create ( {
49
- title,
50
- body : `${ title } PR.` ,
51
- owner : context . repo . owner ,
52
- repo : context . repo . repo ,
53
- head : source ,
54
- base : target ,
55
- } ) ;
60
+ try {
61
+ await github . pulls . create ( {
62
+ title,
63
+ body : `${ title } PR.` ,
64
+ owner : context . repo . owner ,
65
+ repo : context . repo . repo ,
66
+ head : source ,
67
+ base : target ,
68
+ } ) ;
69
+ } catch ( e ) {
70
+ console . log ( "Error in creating pull request" ) ;
71
+ throw Error ( e ) ;
72
+ }
56
73
}
57
74
58
75
try {
@@ -69,7 +86,7 @@ module.exports = async ({ github, context, versionType }) => {
69
86
`Created pull request for version increment to v${ version } (${ versionType } ).`
70
87
) ;
71
88
} else {
72
- console . log ( "Pull request already exists for this version increment" ) ;
89
+ throw new Error ( "Pull request already exists for this version increment" ) ;
73
90
}
74
91
} catch ( error ) {
75
92
console . error ( error ) ;
0 commit comments