Skip to content

Commit 03a794e

Browse files
authored
Merge pull request #8 from yoichiro/fix-git-issue
Fix git issue
2 parents 45a8f92 + 44f0d7d commit 03a794e

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

index.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
const { Toolkit } = require('actions-toolkit');
22
const fs = require('fs');
3+
const path = require('path');
34

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+
// }
89

910
Toolkit.run(async tools => {
1011
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');
1118
// 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+
);
1324
console.log(`Target file: ${targetFile}`);
14-
const content = fs.readFileSync(`./${targetFile}`, 'utf8');
25+
const content = fs.readFileSync(targetFile, 'utf8');
1526
// Increment value
1627
const prefix = process.env.INPUT_PREFIX;
28+
console.log(`prefix: ${prefix}`);
1729
const suffix = process.env.INPUT_SUFFIX;
30+
console.log(`suffix: ${suffix}`);
1831
const firstPart = content.substring(0, content.indexOf(prefix) + prefix.length);
1932
const lastPart = content.substring(content.indexOf(suffix));
2033
const targetPart = content.substring(content.indexOf(prefix) + prefix.length, content.indexOf(suffix));
@@ -25,8 +38,12 @@ Toolkit.run(async tools => {
2538
fs.writeFileSync(targetFile, newContent);
2639
console.log(`Incremented the value from ${current} to ${next}.`);
2740
// 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}"`);
3047
// Fetch current branch name
3148
let currentBranch = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF)[1];
3249
let isPullRequest = false;
@@ -38,9 +55,11 @@ Toolkit.run(async tools => {
3855
// Commit
3956
const commitMessage = process.env.INPUT_COMMIT_MESSAGE;
4057
await tools.exec(`git commit -a -m "ci: ${commitMessage} ${next}"`);
58+
console.log('Committing was successfully.');
4159
// Push
4260
const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
4361
await tools.exec(`git push ${remoteRepo}`);
62+
console.log('Pushing was successfully.');
4463
tools.exit.success('Incrementing the value successfully.');
4564
} catch (e) {
4665
tools.log.fatal(e);

0 commit comments

Comments
 (0)