From c048807d1ed00cf42b8d25061b0d483d3cb34cbd Mon Sep 17 00:00:00 2001 From: Larsluph <22910497+Larsluph@users.noreply.github.com> Date: Sun, 12 Nov 2023 17:38:52 +0100 Subject: [PATCH] Check commit needed --- dist/index.js | 12 ++++++++++++ src/utils.ts | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/dist/index.js b/dist/index.js index 20020eb..03c3f38 100644 --- a/dist/index.js +++ b/dist/index.js @@ -25568,6 +25568,7 @@ const exec_1 = __nccwpck_require__(1514); const io_1 = __nccwpck_require__(7436); const io_util_1 = __nccwpck_require__(1962); const fs = __importStar(__nccwpck_require__(7147)); +const stream_1 = __nccwpck_require__(2781); const base_url = 'https://app.tolgee.io/v2'; const languages_url = `${base_url}/projects/languages`; const export_url = `${base_url}/projects/export`; @@ -25623,6 +25624,17 @@ async function commitChanges(committer_name, committer_email, commit_message) { return; } const gitPath = await (0, io_1.which)('git', true); + let hasChanged = false; + const outStream = new stream_1.Writable({ + write(chunk, encoding, callback) { + hasChanged = true; + } + }); + await (0, exec_1.exec)(gitPath, ['status', '-s'], { outStream }); + if (!hasChanged) { + core.info('Nothing to commit.'); + return; + } await (0, exec_1.exec)(gitPath, ['add', '.']); await (0, exec_1.exec)(gitPath, ['config', '--global', 'user.name', committer_name]); await (0, exec_1.exec)(gitPath, ['config', '--global', 'user.email', committer_email]); diff --git a/src/utils.ts b/src/utils.ts index ee8a2f6..e293655 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,6 +4,7 @@ import { HttpClient } from '@actions/http-client' import { mkdirP, which } from '@actions/io' import { rm } from '@actions/io/lib/io-util' import * as fs from 'fs' +import { Writable } from 'stream' import { LanguageResponse } from './types' const base_url = 'https://app.tolgee.io/v2' @@ -72,6 +73,20 @@ export async function commitChanges(committer_name: string, committer_email: str } const gitPath = await which('git', true) + + let hasChanged = false + const outStream = new Writable({ + write(chunk, encoding, callback) { + hasChanged = true + } + }) + await exec(gitPath, ['status', '-s'], { outStream }) + + if (!hasChanged) { + core.info('Nothing to commit.') + return + } + await exec(gitPath, ['add', '.']) await exec(gitPath, ['config', '--global', 'user.name', committer_name]) await exec(gitPath, ['config', '--global', 'user.email', committer_email])