1
1
const { Toolkit } = require ( 'actions-toolkit' ) ;
2
2
const fs = require ( 'fs' ) ;
3
+ const path = require ( 'path' ) ;
3
4
4
- if ( process . env . INPUT_TARGET_DIRECTORY ) {
5
- process . env . GITHUB_WORKSPACE = `${ process . env . GITHUB_WORKSPACE } /${ process . env . INPUT_TARGET_DIRECTORY } ` ;
6
- process . chdir ( process . env . GITHUB_WORKSPACE ) ;
7
- }
5
+ // if (process.env.INPUT_TARGET_DIRECTORY) {
6
+ // process.env.GITHUB_WORKSPACE = `${process.env.GITHUB_WORKSPACE}/${process.env.INPUT_TARGET_DIRECTORY}`;
7
+ // process.chdir(process.env.GITHUB_WORKSPACE);
8
+ // }
8
9
9
10
Toolkit . run ( async tools => {
10
11
try {
12
+ console . log ( `INPUT_TARGET_DIRECTORY: ${ process . env . INPUT_TARGET_DIRECTORY } ` ) ;
13
+ console . log ( `GITHUB_WORKSPACE: ${ process . env . GITHUB_WORKSPACE } ` ) ;
14
+ await tools . exec ( 'pwd' ) ;
15
+ console . log ( 'Set safe directory' ) ;
16
+ await tools . exec ( `git config --global --add safe.directory ${ process . env . GITHUB_WORKSPACE } ` ) ;
17
+ await tools . exec ( 'git status' ) ;
11
18
// Read the target file
12
- const targetFile = process . env . INPUT_TARGET_FILE ;
19
+ const targetFile = path . join (
20
+ process . env . GITHUB_WORKSPACE ,
21
+ process . env . INPUT_TARGET_DIRECTORY ,
22
+ process . env . INPUT_TARGET_FILE
23
+ ) ;
13
24
console . log ( `Target file: ${ targetFile } ` ) ;
14
- const content = fs . readFileSync ( `./ ${ targetFile } ` , 'utf8' ) ;
25
+ const content = fs . readFileSync ( targetFile , 'utf8' ) ;
15
26
// Increment value
16
27
const prefix = process . env . INPUT_PREFIX ;
28
+ console . log ( `prefix: ${ prefix } ` ) ;
17
29
const suffix = process . env . INPUT_SUFFIX ;
30
+ console . log ( `suffix: ${ suffix } ` ) ;
18
31
const firstPart = content . substring ( 0 , content . indexOf ( prefix ) + prefix . length ) ;
19
32
const lastPart = content . substring ( content . indexOf ( suffix ) ) ;
20
33
const targetPart = content . substring ( content . indexOf ( prefix ) + prefix . length , content . indexOf ( suffix ) ) ;
@@ -25,8 +38,12 @@ Toolkit.run(async tools => {
25
38
fs . writeFileSync ( targetFile , newContent ) ;
26
39
console . log ( `Incremented the value from ${ current } to ${ next } .` ) ;
27
40
// Set git user
28
- await tools . exec ( `git config user.name "${ process . env . GITHUB_USER || 'Automated Increment value' } "` ) ;
29
- await tools . exec ( `git config user.email "${ process . env . GITHUB_EMAIL || '[email protected] ' } "` ) ;
41
+ const gitUserName = process . env . GITHUB_USER || 'Automated Increment value' ;
42
+ console . log ( `Set git user name: ${ gitUserName } ` ) ;
43
+ await tools . exec ( `git config user.name "${ gitUserName } "` ) ;
44
+ const gitUserEmail = process . env . GITHUB_EMAIL || '[email protected] ' ;
45
+ console . log ( `Set git user email: ${ gitUserEmail } ` ) ;
46
+ await tools . exec ( `git config user.email "${ gitUserEmail } "` ) ;
30
47
// Fetch current branch name
31
48
let currentBranch = / r e f s \/ [ a - z A - Z ] + \/ ( .* ) / . exec ( process . env . GITHUB_REF ) [ 1 ] ;
32
49
let isPullRequest = false ;
@@ -38,9 +55,11 @@ Toolkit.run(async tools => {
38
55
// Commit
39
56
const commitMessage = process . env . INPUT_COMMIT_MESSAGE ;
40
57
await tools . exec ( `git commit -a -m "ci: ${ commitMessage } ${ next } "` ) ;
58
+ console . log ( 'Committing was successfully.' ) ;
41
59
// Push
42
60
const remoteRepo = `https://${ process . env . GITHUB_ACTOR } :${ process . env . GITHUB_TOKEN } @github.com/${ process . env . GITHUB_REPOSITORY } .git` ;
43
61
await tools . exec ( `git push ${ remoteRepo } ` ) ;
62
+ console . log ( 'Pushing was successfully.' ) ;
44
63
tools . exit . success ( 'Incrementing the value successfully.' ) ;
45
64
} catch ( e ) {
46
65
tools . log . fatal ( e ) ;
0 commit comments