|
| 1 | +import * as core from '@actions/core' |
| 2 | +import { isFileExist } from './src/isFileExists.js' |
| 3 | +import { spawnProcess } from './src/spawnProcess.js' |
| 4 | + |
| 5 | +try { |
| 6 | + // vars |
| 7 | + const repository = core.getInput('repository') |
| 8 | + const branch = core.getInput('branch') |
| 9 | + const commitMessage = core.getInput('commit_message') |
| 10 | + const pullArgs = core.getInput('pull_args') |
| 11 | + |
| 12 | + // log |
| 13 | + console.log({ |
| 14 | + repository, |
| 15 | + branch, |
| 16 | + commitMessage, |
| 17 | + pullArgs, |
| 18 | + }) |
| 19 | + |
| 20 | + if (!(await isFileExist(repository))) { |
| 21 | + throw new Error("repository directory doesn't exist: " + repository) |
| 22 | + } |
| 23 | + |
| 24 | + await spawnProcess('git', ['add', '.'], repository) |
| 25 | + const diff = await spawnProcess('git', ['diff', '--staged', '--name-only'], repository) |
| 26 | + if (diff.trim() === '') { |
| 27 | + console.log('Working tree is empty. Nothing to commit.') |
| 28 | + } else { |
| 29 | + await spawnProcess( |
| 30 | + 'git', |
| 31 | + [ |
| 32 | + '-c', |
| 33 | + 'user.name="github-actions[bot]"', |
| 34 | + '-c', |
| 35 | + 'user.email="41898282+github-actions[bot]@users.noreply.github.com"', |
| 36 | + 'commit', |
| 37 | + '-m', |
| 38 | + commitMessage, |
| 39 | + '--author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"', |
| 40 | + '--no-verify', |
| 41 | + ], |
| 42 | + repository |
| 43 | + ) |
| 44 | + await spawnProcess('git', ['pull', ...pullArgs.split(' ')], repository) |
| 45 | + await spawnProcess('git', ['push', '--no-verify', 'origin', branch], repository) |
| 46 | + } |
| 47 | +} catch (error) { |
| 48 | + core.setFailed(error.message) |
| 49 | +} |
0 commit comments