From c09f9ef514e8fa164b93780f86c15998715ac8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Mon, 11 Nov 2024 16:34:52 -0300 Subject: [PATCH 01/28] remove yarn.lock from automation --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 2cf77632a..205ba74e4 100644 --- a/index.js +++ b/index.js @@ -243,6 +243,8 @@ const pkg = getPackageJson(); } else { await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } + await runInWorkspace('git', ['checkout', '--', 'yarn.lock']); + } } catch (e) { // console.warn( From 901d14917de84ea185c7364b64a3153a078277a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Mon, 11 Nov 2024 16:46:06 -0300 Subject: [PATCH 02/28] test --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 205ba74e4..336a34459 100644 --- a/index.js +++ b/index.js @@ -243,7 +243,6 @@ const pkg = getPackageJson(); } else { await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } - await runInWorkspace('git', ['checkout', '--', 'yarn.lock']); } } catch (e) { @@ -267,6 +266,7 @@ const pkg = getPackageJson(); await runInWorkspace('git', ['push', remoteRepo]); } } + await runInWorkspace('git', ['checkout', '--', 'yarn.lock']); } catch (e) { logError(e); exitFailure('Failed to bump version'); From 23bd7521a27d96b432081146d4e0d64139b5f191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Mon, 11 Nov 2024 16:50:22 -0300 Subject: [PATCH 03/28] test --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 336a34459..053f84c03 100644 --- a/index.js +++ b/index.js @@ -266,7 +266,7 @@ const pkg = getPackageJson(); await runInWorkspace('git', ['push', remoteRepo]); } } - await runInWorkspace('git', ['checkout', '--', 'yarn.lock']); + await runInWorkspace('git', ['checkout', '--', '**/yarn.lock']); } catch (e) { logError(e); exitFailure('Failed to bump version'); From f23eb3b697be1b7a96d1672d8256a7d4e1a6c5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Mon, 11 Nov 2024 16:55:09 -0300 Subject: [PATCH 04/28] test --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 053f84c03..21487a88e 100644 --- a/index.js +++ b/index.js @@ -266,7 +266,16 @@ const pkg = getPackageJson(); await runInWorkspace('git', ['push', remoteRepo]); } } - await runInWorkspace('git', ['checkout', '--', '**/yarn.lock']); + try { + // Find all yarn.lock files and checkout each one individually + const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); + yarnLockFiles.forEach(file => { + execSync(`git checkout -- ${file}`); + }); + console.log('Successfully reverted changes to all yarn.lock files.'); + } catch (error) { + console.error('Error resetting yarn.lock files:', error); + } } catch (e) { logError(e); exitFailure('Failed to bump version'); From 19bdd5ec41924fcefc738d244a29bc3e7efac3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Mon, 11 Nov 2024 17:08:57 -0300 Subject: [PATCH 05/28] test --- index.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 21487a88e..9e9cd8211 100644 --- a/index.js +++ b/index.js @@ -255,20 +255,10 @@ const pkg = getPackageJson(); const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@${ process.env['INPUT_CUSTOM-GIT-DOMAIN'] || 'github.com' }/${process.env.GITHUB_REPOSITORY}.git`; - if (process.env['INPUT_SKIP-TAG'] !== 'true') { - await runInWorkspace('git', ['tag', newVersion]); - if (process.env['INPUT_SKIP-PUSH'] !== 'true') { - await runInWorkspace('git', ['push', remoteRepo, '--follow-tags']); - await runInWorkspace('git', ['push', remoteRepo, '--tags']); - } - } else { - if (process.env['INPUT_SKIP-PUSH'] !== 'true') { - await runInWorkspace('git', ['push', remoteRepo]); - } - } try { // Find all yarn.lock files and checkout each one individually const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); + console.info('yarnLockFiles:', yarnLockFiles); yarnLockFiles.forEach(file => { execSync(`git checkout -- ${file}`); }); @@ -281,6 +271,18 @@ const pkg = getPackageJson(); exitFailure('Failed to bump version'); return; } + if (process.env['INPUT_SKIP-TAG'] !== 'true') { + await runInWorkspace('git', ['tag', newVersion]); + if (process.env['INPUT_SKIP-PUSH'] !== 'true') { + await runInWorkspace('git', ['push', remoteRepo, '--follow-tags']); + await runInWorkspace('git', ['push', remoteRepo, '--tags']); + } + } else { + if (process.env['INPUT_SKIP-PUSH'] !== 'true') { + await runInWorkspace('git', ['push', remoteRepo]); + } + } + exitSuccess('Version bumped!'); })(); From a803435297cababa26f517d84ed80029b85cd3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Mon, 11 Nov 2024 17:12:36 -0300 Subject: [PATCH 06/28] test --- index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9e9cd8211..7fc451a71 100644 --- a/index.js +++ b/index.js @@ -243,7 +243,6 @@ const pkg = getPackageJson(); } else { await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } - } } catch (e) { // console.warn( @@ -255,6 +254,8 @@ const pkg = getPackageJson(); const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@${ process.env['INPUT_CUSTOM-GIT-DOMAIN'] || 'github.com' }/${process.env.GITHUB_REPOSITORY}.git`; + + try { // Find all yarn.lock files and checkout each one individually const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); @@ -266,11 +267,8 @@ const pkg = getPackageJson(); } catch (error) { console.error('Error resetting yarn.lock files:', error); } - } catch (e) { - logError(e); - exitFailure('Failed to bump version'); - return; - } + + if (process.env['INPUT_SKIP-TAG'] !== 'true') { await runInWorkspace('git', ['tag', newVersion]); if (process.env['INPUT_SKIP-PUSH'] !== 'true') { @@ -282,7 +280,11 @@ const pkg = getPackageJson(); await runInWorkspace('git', ['push', remoteRepo]); } } - + } catch (e) { + logError(e); + exitFailure('Failed to bump version'); + return; + } exitSuccess('Version bumped!'); })(); From 6fca298cdc71cab8924491a54bbb1e2878a8d751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Mon, 11 Nov 2024 17:17:42 -0300 Subject: [PATCH 07/28] tweaks --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 7fc451a71..65dd8f3e4 100644 --- a/index.js +++ b/index.js @@ -256,10 +256,9 @@ const pkg = getPackageJson(); }/${process.env.GITHUB_REPOSITORY}.git`; + // Find all yarn.lock files and checkout each one individually try { - // Find all yarn.lock files and checkout each one individually const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); - console.info('yarnLockFiles:', yarnLockFiles); yarnLockFiles.forEach(file => { execSync(`git checkout -- ${file}`); }); @@ -268,7 +267,6 @@ const pkg = getPackageJson(); console.error('Error resetting yarn.lock files:', error); } - if (process.env['INPUT_SKIP-TAG'] !== 'true') { await runInWorkspace('git', ['tag', newVersion]); if (process.env['INPUT_SKIP-PUSH'] !== 'true') { From c22663c15864abfac9a1a3da24450c35ddf8071c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 00:24:49 -0300 Subject: [PATCH 08/28] updated remove lock logic --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 65dd8f3e4..d09113c4c 100644 --- a/index.js +++ b/index.js @@ -260,7 +260,9 @@ const pkg = getPackageJson(); try { const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); yarnLockFiles.forEach(file => { - execSync(`git checkout -- ${file}`); + execSync(`git restore --staged ${file}`); // Unstage changes + execSync(`git checkout -- ${file}`); // Revert changes + console.log(`Successfully reverted ${file}`); }); console.log('Successfully reverted changes to all yarn.lock files.'); } catch (error) { From 1508097320c3c367b0ddc8453ba197ee1891b26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 00:31:56 -0300 Subject: [PATCH 09/28] wip --- index.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index d09113c4c..ab919727f 100644 --- a/index.js +++ b/index.js @@ -208,6 +208,19 @@ const pkg = getPackageJson(); let newVersion = parseNpmVersionOutput(execSync(`npm version --git-tag-version=false ${version} --silent`).toString()); console.log('newVersion 1:', newVersion); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; + + // Find all yarn.lock files and checkout each one individually + try { + const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); + yarnLockFiles.forEach(file => { + execSync(`git checkout -- ${file}`); + }); + console.log('Successfully reverted changes to all yarn.lock files.'); + } catch (error) { + console.error('Error resetting yarn.lock files:', error); + } + + if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } @@ -256,18 +269,7 @@ const pkg = getPackageJson(); }/${process.env.GITHUB_REPOSITORY}.git`; - // Find all yarn.lock files and checkout each one individually - try { - const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); - yarnLockFiles.forEach(file => { - execSync(`git restore --staged ${file}`); // Unstage changes - execSync(`git checkout -- ${file}`); // Revert changes - console.log(`Successfully reverted ${file}`); - }); - console.log('Successfully reverted changes to all yarn.lock files.'); - } catch (error) { - console.error('Error resetting yarn.lock files:', error); - } + if (process.env['INPUT_SKIP-TAG'] !== 'true') { await runInWorkspace('git', ['tag', newVersion]); From 98537698b5291d67e98af558c7640edfeadf038e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 00:44:24 -0300 Subject: [PATCH 10/28] wip --- index.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index ab919727f..610fb8df4 100644 --- a/index.js +++ b/index.js @@ -208,19 +208,6 @@ const pkg = getPackageJson(); let newVersion = parseNpmVersionOutput(execSync(`npm version --git-tag-version=false ${version} --silent`).toString()); console.log('newVersion 1:', newVersion); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; - - // Find all yarn.lock files and checkout each one individually - try { - const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); - yarnLockFiles.forEach(file => { - execSync(`git checkout -- ${file}`); - }); - console.log('Successfully reverted changes to all yarn.lock files.'); - } catch (error) { - console.error('Error resetting yarn.lock files:', error); - } - - if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } @@ -269,7 +256,18 @@ const pkg = getPackageJson(); }/${process.env.GITHUB_REPOSITORY}.git`; + // Find all yarn.lock files and checkout each one individually + try { + const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); + const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`).toString().trim().split('\n'); + yarnLockFiles.forEach(file => { + execSync(`git checkout -- ${file}`); + }); + console.log('Successfully reverted changes to all yarn.lock files.'); + } catch (error) { + console.error('Error resetting yarn.lock files:', error); + } if (process.env['INPUT_SKIP-TAG'] !== 'true') { await runInWorkspace('git', ['tag', newVersion]); From 233679101de92e6c02361cb4b08f7e74f991125e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 00:50:08 -0300 Subject: [PATCH 11/28] wip --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 610fb8df4..d1236e780 100644 --- a/index.js +++ b/index.js @@ -260,7 +260,8 @@ const pkg = getPackageJson(); try { const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); - const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`).toString().trim().split('\n'); + const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); + yarnLockFiles.forEach(file => { execSync(`git checkout -- ${file}`); }); From e0fe3aba8e3169ac207298ffd323cc636b66e538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 00:56:18 -0300 Subject: [PATCH 12/28] wip --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d1236e780..f3be0ce98 100644 --- a/index.js +++ b/index.js @@ -263,7 +263,15 @@ const pkg = getPackageJson(); const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); yarnLockFiles.forEach(file => { - execSync(`git checkout -- ${file}`); + if (file) { + // Revert changes to the yarn.lock file + execSync(`git checkout -- ${file}`); + console.log(`Reverted changes to: ${file}`); + + // Unstage the yarn.lock file + execSync(`git reset HEAD ${file}`); + console.log(`Unstaged yarn.lock: ${file}`); + } }); console.log('Successfully reverted changes to all yarn.lock files.'); } catch (error) { From 14ffd9bb01301c5a319360c3b30661c4744c27c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:08:16 -0300 Subject: [PATCH 13/28] wip --- index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index f3be0ce98..cd261750e 100644 --- a/index.js +++ b/index.js @@ -264,13 +264,12 @@ const pkg = getPackageJson(); yarnLockFiles.forEach(file => { if (file) { - // Revert changes to the yarn.lock file + execSync(`git reset HEAD ${file}`); + console.log(`Uncommitted: ${file}`); + + // Revert changes to the file execSync(`git checkout -- ${file}`); console.log(`Reverted changes to: ${file}`); - - // Unstage the yarn.lock file - execSync(`git reset HEAD ${file}`); - console.log(`Unstaged yarn.lock: ${file}`); } }); console.log('Successfully reverted changes to all yarn.lock files.'); From 19d64ffc3a416e259535206f175fe0d80fcdee73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:13:43 -0300 Subject: [PATCH 14/28] wip --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index cd261750e..455e59b15 100644 --- a/index.js +++ b/index.js @@ -264,12 +264,19 @@ const pkg = getPackageJson(); yarnLockFiles.forEach(file => { if (file) { - execSync(`git reset HEAD ${file}`); - console.log(`Uncommitted: ${file}`); + const absolutePath = `${repoRoot}/${file}`; // Ensure full path + + // Uncommit the file: remove it from the last commit + execSync(`git reset HEAD ${absolutePath}`); + console.log(`Uncommitted: ${absolutePath}`); // Revert changes to the file - execSync(`git checkout -- ${file}`); - console.log(`Reverted changes to: ${file}`); + execSync(`git checkout -- ${absolutePath}`); + console.log(`Reverted changes to: ${absolutePath}`); + + // Optional: Temporarily ignore the file to avoid accidental staging + execSync(`echo "${absolutePath}" >> ${repoRoot}/.gitignore`); + console.log(`Temporarily ignored: ${absolutePath}`); } }); console.log('Successfully reverted changes to all yarn.lock files.'); From 1ea612b11e0f35750092b3eb20ef4fd3a2cf0def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:20:46 -0300 Subject: [PATCH 15/28] wip --- index.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 455e59b15..83ad1c645 100644 --- a/index.js +++ b/index.js @@ -262,24 +262,19 @@ const pkg = getPackageJson(); const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); - yarnLockFiles.forEach(file => { + for (const file of yarnLockFiles) { if (file) { - const absolutePath = `${repoRoot}/${file}`; // Ensure full path - + console.log(`Processing yarn.lock file: ${file}`); + // Uncommit the file: remove it from the last commit - execSync(`git reset HEAD ${absolutePath}`); - console.log(`Uncommitted: ${absolutePath}`); + await runInWorkspace('git', ['reset', 'HEAD', file], repoRoot); + console.log(`Uncommitted: ${file}`); // Revert changes to the file - execSync(`git checkout -- ${absolutePath}`); - console.log(`Reverted changes to: ${absolutePath}`); - - // Optional: Temporarily ignore the file to avoid accidental staging - execSync(`echo "${absolutePath}" >> ${repoRoot}/.gitignore`); - console.log(`Temporarily ignored: ${absolutePath}`); + await runInWorkspace('git', ['checkout', '--', file], repoRoot); + console.log(`Reverted changes to: ${file}`); } - }); - console.log('Successfully reverted changes to all yarn.lock files.'); + } } catch (error) { console.error('Error resetting yarn.lock files:', error); } From fc4594a44b84015322a9e82bf8f2a5d8d9e9d1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:25:47 -0300 Subject: [PATCH 16/28] wip --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 83ad1c645..87eb7ba5c 100644 --- a/index.js +++ b/index.js @@ -209,6 +209,8 @@ const pkg = getPackageJson(); console.log('newVersion 1:', newVersion); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { + const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); + console.log(`Git status output (1):\n${statusOutput}`); await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } @@ -236,6 +238,8 @@ const pkg = getPackageJson(); console.log(`::set-output name=newTag::${newVersion}`); } try { + const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); + console.log(`Git status (2) output:\n${statusOutput}`); // to support "actions/checkout@v1" if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { if (process.env['INPUT_COMMIT-NO-VERIFY'] === 'true') { @@ -278,6 +282,8 @@ const pkg = getPackageJson(); } catch (error) { console.error('Error resetting yarn.lock files:', error); } + const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); + console.log(`Git status output (3):\n${statusOutput}`); if (process.env['INPUT_SKIP-TAG'] !== 'true') { await runInWorkspace('git', ['tag', newVersion]); From 99f90b991f94b4c9295b64cc8bb5f261328eea62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:28:53 -0300 Subject: [PATCH 17/28] wip --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 87eb7ba5c..25d755b52 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ const workspace = process.env.GITHUB_WORKSPACE; const pkg = getPackageJson(); (async () => { + const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); const event = process.env.GITHUB_EVENT_PATH ? require(process.env.GITHUB_EVENT_PATH) : {}; if (!event.commits && !process.env['INPUT_VERSION-TYPE']) { @@ -262,7 +263,6 @@ const pkg = getPackageJson(); // Find all yarn.lock files and checkout each one individually try { - const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); From 540c8debc2377604105fac47f8f7320fe518d74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:33:50 -0300 Subject: [PATCH 18/28] wip --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 25d755b52..400dc065c 100644 --- a/index.js +++ b/index.js @@ -265,8 +265,9 @@ const pkg = getPackageJson(); try { const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); + const npmLockFiles = execSync(`git ls-files ${repoRoot} | grep 'package-lock.json'`).toString().trim().split('\n'); - for (const file of yarnLockFiles) { + for (const file of [...yarnLockFiles, ...npmLockFiles]) { if (file) { console.log(`Processing yarn.lock file: ${file}`); From ad45ddd683274d32c6b7e3f0fdea2807ad38816f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:39:16 -0300 Subject: [PATCH 19/28] wip --- index.js | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 400dc065c..c1994d8d9 100644 --- a/index.js +++ b/index.js @@ -239,6 +239,28 @@ const pkg = getPackageJson(); console.log(`::set-output name=newTag::${newVersion}`); } try { + // Find all yarn.lock files and checkout each one individually + try { + + const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); + const npmLockFiles = execSync(`git ls-files ${repoRoot} | grep 'package-lock.json'`).toString().trim().split('\n'); + + for (const file of [...yarnLockFiles, ...npmLockFiles]) { + if (file) { + console.log(`Processing yarn.lock file: ${file}`); + + // Uncommit the file: remove it from the last commit + await runInWorkspace('git', ['reset', 'HEAD', file], repoRoot); + console.log(`Uncommitted: ${file}`); + + // Revert changes to the file + await runInWorkspace('git', ['checkout', '--', file], repoRoot); + console.log(`Reverted changes to: ${file}`); + } + } + } catch (error) { + console.error('Error resetting yarn.lock files:', error); + } const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); console.log(`Git status (2) output:\n${statusOutput}`); // to support "actions/checkout@v1" @@ -261,28 +283,7 @@ const pkg = getPackageJson(); }/${process.env.GITHUB_REPOSITORY}.git`; - // Find all yarn.lock files and checkout each one individually - try { - - const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); - const npmLockFiles = execSync(`git ls-files ${repoRoot} | grep 'package-lock.json'`).toString().trim().split('\n'); - - for (const file of [...yarnLockFiles, ...npmLockFiles]) { - if (file) { - console.log(`Processing yarn.lock file: ${file}`); - - // Uncommit the file: remove it from the last commit - await runInWorkspace('git', ['reset', 'HEAD', file], repoRoot); - console.log(`Uncommitted: ${file}`); - - // Revert changes to the file - await runInWorkspace('git', ['checkout', '--', file], repoRoot); - console.log(`Reverted changes to: ${file}`); - } - } - } catch (error) { - console.error('Error resetting yarn.lock files:', error); - } + const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); console.log(`Git status output (3):\n${statusOutput}`); From c8aec7408e23cd2a9d527c8b11f12a350f6dc8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:44:09 -0300 Subject: [PATCH 20/28] wip --- index.js | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index c1994d8d9..4ea7110d3 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,6 @@ const workspace = process.env.GITHUB_WORKSPACE; const pkg = getPackageJson(); (async () => { - const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); const event = process.env.GITHUB_EVENT_PATH ? require(process.env.GITHUB_EVENT_PATH) : {}; if (!event.commits && !process.env['INPUT_VERSION-TYPE']) { @@ -210,8 +209,6 @@ const pkg = getPackageJson(); console.log('newVersion 1:', newVersion); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { - const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); - console.log(`Git status output (1):\n${statusOutput}`); await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } @@ -238,31 +235,20 @@ const pkg = getPackageJson(); // for runner < 2.297.0 console.log(`::set-output name=newTag::${newVersion}`); } + + try { + const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); + const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); + [...yarnLockFiles, ...npmLockFiles].forEach(file => { + execSync(`git checkout -- ${file}`); + }); + console.log('Successfully reverted changes to all yarn.lock files.'); + } catch (error) { + console.error('Error resetting yarn.lock files:', error); + } + + try { - // Find all yarn.lock files and checkout each one individually - try { - - const yarnLockFiles = execSync(`git ls-files ${repoRoot} | grep 'yarn.lock'`).toString().trim().split('\n'); - const npmLockFiles = execSync(`git ls-files ${repoRoot} | grep 'package-lock.json'`).toString().trim().split('\n'); - - for (const file of [...yarnLockFiles, ...npmLockFiles]) { - if (file) { - console.log(`Processing yarn.lock file: ${file}`); - - // Uncommit the file: remove it from the last commit - await runInWorkspace('git', ['reset', 'HEAD', file], repoRoot); - console.log(`Uncommitted: ${file}`); - - // Revert changes to the file - await runInWorkspace('git', ['checkout', '--', file], repoRoot); - console.log(`Reverted changes to: ${file}`); - } - } - } catch (error) { - console.error('Error resetting yarn.lock files:', error); - } - const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); - console.log(`Git status (2) output:\n${statusOutput}`); // to support "actions/checkout@v1" if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { if (process.env['INPUT_COMMIT-NO-VERIFY'] === 'true') { @@ -283,9 +269,17 @@ const pkg = getPackageJson(); }/${process.env.GITHUB_REPOSITORY}.git`; - - const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); - console.log(`Git status output (3):\n${statusOutput}`); + // Find all yarn.lock files and checkout each one individually + try { + const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); + const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); + [...yarnLockFiles, ...npmLockFiles].forEach(file => { + execSync(`git checkout -- ${file}`); + }); + console.log('Successfully reverted changes to all yarn.lock files.'); + } catch (error) { + console.error('Error resetting yarn.lock files:', error); + } if (process.env['INPUT_SKIP-TAG'] !== 'true') { await runInWorkspace('git', ['tag', newVersion]); From 5ee155a5d5822f672ff9506b6c491be82cf8383c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:49:06 -0300 Subject: [PATCH 21/28] wip --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index 4ea7110d3..8ffefd3da 100644 --- a/index.js +++ b/index.js @@ -209,6 +209,18 @@ const pkg = getPackageJson(); console.log('newVersion 1:', newVersion); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { + + try { + const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); + const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); + [...yarnLockFiles, ...npmLockFiles].forEach(file => { + console.log('Reverting changes to:', file); + execSync(`git checkout -- ${file}`); + }); + console.log('Successfully reverted changes to all yarn.lock files.'); + } catch (error) { + console.error('Error resetting yarn.lock files:', error); + } await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } @@ -240,6 +252,7 @@ const pkg = getPackageJson(); const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); [...yarnLockFiles, ...npmLockFiles].forEach(file => { + console.log('Reverting changes to:', file); execSync(`git checkout -- ${file}`); }); console.log('Successfully reverted changes to all yarn.lock files.'); @@ -274,6 +287,7 @@ const pkg = getPackageJson(); const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); [...yarnLockFiles, ...npmLockFiles].forEach(file => { + console.log('Reverting changes to:', file); execSync(`git checkout -- ${file}`); }); console.log('Successfully reverted changes to all yarn.lock files.'); From 6180d04bf8686d19cb84127258c5dc149b18a71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 01:55:00 -0300 Subject: [PATCH 22/28] wip --- index.js | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8ffefd3da..6f68ddc98 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,8 @@ const pkg = getPackageJson(); return; } + const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); + const versionType = process.env['INPUT_VERSION-TYPE']; const tagPrefix = process.env['INPUT_TAG-PREFIX'] || ''; const tagSuffix = process.env['INPUT_TAG-SUFFIX'] || ''; @@ -211,10 +213,16 @@ const pkg = getPackageJson(); if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { try { - const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); - const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); + const yarnLockFiles = execSync(`git ls-files | grep 'yarn.lock'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); + const npmLockFiles = execSync(`git ls-files | grep 'package-lock.json'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); [...yarnLockFiles, ...npmLockFiles].forEach(file => { - console.log('Reverting changes to:', file); + console.log(`reverting changes to ${file}`); execSync(`git checkout -- ${file}`); }); console.log('Successfully reverted changes to all yarn.lock files.'); @@ -249,10 +257,16 @@ const pkg = getPackageJson(); } try { - const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); - const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); + const yarnLockFiles = execSync(`git ls-files | grep 'yarn.lock'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); + const npmLockFiles = execSync(`git ls-files | grep 'package-lock.json'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); [...yarnLockFiles, ...npmLockFiles].forEach(file => { - console.log('Reverting changes to:', file); + console.log(`reverting changes to ${file}`); execSync(`git checkout -- ${file}`); }); console.log('Successfully reverted changes to all yarn.lock files.'); @@ -284,10 +298,16 @@ const pkg = getPackageJson(); // Find all yarn.lock files and checkout each one individually try { - const yarnLockFiles = execSync('find . -name "yarn.lock"').toString().trim().split('\n'); - const npmLockFiles = execSync('find . -name "package-lock.json"').toString().trim().split('\n'); + const yarnLockFiles = execSync(`git ls-files | grep 'yarn.lock'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); + const npmLockFiles = execSync(`git ls-files | grep 'package-lock.json'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); [...yarnLockFiles, ...npmLockFiles].forEach(file => { - console.log('Reverting changes to:', file); + console.log(`reverting changes to ${file}`); execSync(`git checkout -- ${file}`); }); console.log('Successfully reverted changes to all yarn.lock files.'); From 9f68d2372fbd5e5dc0c95c101707bbb820d96b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 02:02:15 -0300 Subject: [PATCH 23/28] wip --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 6f68ddc98..1710f10e0 100644 --- a/index.js +++ b/index.js @@ -213,11 +213,11 @@ const pkg = getPackageJson(); if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { try { - const yarnLockFiles = execSync(`git ls-files | grep 'yarn.lock'`, { cwd: repoRoot }) + const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`, { cwd: repoRoot }) .toString() .trim() .split('\n'); - const npmLockFiles = execSync(`git ls-files | grep 'package-lock.json'`, { cwd: repoRoot }) + const npmLockFiles = execSync(`find ${repoRoot} -name "package-lock.json"`, { cwd: repoRoot }) .toString() .trim() .split('\n'); @@ -257,11 +257,11 @@ const pkg = getPackageJson(); } try { - const yarnLockFiles = execSync(`git ls-files | grep 'yarn.lock'`, { cwd: repoRoot }) + const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`, { cwd: repoRoot }) .toString() .trim() .split('\n'); - const npmLockFiles = execSync(`git ls-files | grep 'package-lock.json'`, { cwd: repoRoot }) + const npmLockFiles = execSync(`find ${repoRoot} -name "package-lock.json"`, { cwd: repoRoot }) .toString() .trim() .split('\n'); @@ -298,11 +298,11 @@ const pkg = getPackageJson(); // Find all yarn.lock files and checkout each one individually try { - const yarnLockFiles = execSync(`git ls-files | grep 'yarn.lock'`, { cwd: repoRoot }) + const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`, { cwd: repoRoot }) .toString() .trim() .split('\n'); - const npmLockFiles = execSync(`git ls-files | grep 'package-lock.json'`, { cwd: repoRoot }) + const npmLockFiles = execSync(`find ${repoRoot} -name "package-lock.json"`, { cwd: repoRoot }) .toString() .trim() .split('\n'); From cfd2358407b1f2afccbad8ffa445f10106c60e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 02:11:38 -0300 Subject: [PATCH 24/28] wip --- index.js | 105 +++++++++++++++++-------------------------------------- 1 file changed, 33 insertions(+), 72 deletions(-) diff --git a/index.js b/index.js index 1710f10e0..dbb3264fb 100644 --- a/index.js +++ b/index.js @@ -30,8 +30,6 @@ const pkg = getPackageJson(); return; } - const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); - const versionType = process.env['INPUT_VERSION-TYPE']; const tagPrefix = process.env['INPUT_TAG-PREFIX'] || ''; const tagSuffix = process.env['INPUT_TAG-SUFFIX'] || ''; @@ -211,24 +209,39 @@ const pkg = getPackageJson(); console.log('newVersion 1:', newVersion); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { + // Find all yarn.lock files and checkout each one individually + try { + const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); + console.log(`Git status output:\n${statusOutput}`); + const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); + console.log('Repository root detected:', repoRoot); + + + // Find all tracked yarn.lock files in the repository + const yarnLockFiles = execSync(`git ls-files | grep -E 'yarn.lock|package-lock.json'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); + + for (const file of yarnLockFiles) { + if (file) { + console.log(`Processing yarn.lock file: ${file}`); + + // Uncommit the file: remove it from the last commit + await runInWorkspace('git', ['reset', 'HEAD', file], repoRoot); + console.log(`Uncommitted: ${file}`); + + // Revert changes to the file + await runInWorkspace('git', ['checkout', '--', file], repoRoot); + console.log(`Reverted changes to: ${file}`); + } + } + } catch (error) { + console.error('Error while processing yarn.lock files:', error); + } + const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); + console.log(`Git status output (2):\n${statusOutput}`); - try { - const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`, { cwd: repoRoot }) - .toString() - .trim() - .split('\n'); - const npmLockFiles = execSync(`find ${repoRoot} -name "package-lock.json"`, { cwd: repoRoot }) - .toString() - .trim() - .split('\n'); - [...yarnLockFiles, ...npmLockFiles].forEach(file => { - console.log(`reverting changes to ${file}`); - execSync(`git checkout -- ${file}`); - }); - console.log('Successfully reverted changes to all yarn.lock files.'); - } catch (error) { - console.error('Error resetting yarn.lock files:', error); - } await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } @@ -256,64 +269,12 @@ const pkg = getPackageJson(); console.log(`::set-output name=newTag::${newVersion}`); } - try { - const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`, { cwd: repoRoot }) - .toString() - .trim() - .split('\n'); - const npmLockFiles = execSync(`find ${repoRoot} -name "package-lock.json"`, { cwd: repoRoot }) - .toString() - .trim() - .split('\n'); - [...yarnLockFiles, ...npmLockFiles].forEach(file => { - console.log(`reverting changes to ${file}`); - execSync(`git checkout -- ${file}`); - }); - console.log('Successfully reverted changes to all yarn.lock files.'); - } catch (error) { - console.error('Error resetting yarn.lock files:', error); - } - - - try { - // to support "actions/checkout@v1" - if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { - if (process.env['INPUT_COMMIT-NO-VERIFY'] === 'true') { - await runInWorkspace('git', ['commit', '-a', '--no-verify', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); - } else { - await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); - } - } - } catch (e) { - // console.warn( - // 'git commit failed because you are using "actions/checkout@v2" or later; ' + - // 'but that doesnt matter because you dont need that git commit, thats only for "actions/checkout@v1"', - // ); - } - const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@${ process.env['INPUT_CUSTOM-GIT-DOMAIN'] || 'github.com' }/${process.env.GITHUB_REPOSITORY}.git`; - // Find all yarn.lock files and checkout each one individually - try { - const yarnLockFiles = execSync(`find ${repoRoot} -name "yarn.lock"`, { cwd: repoRoot }) - .toString() - .trim() - .split('\n'); - const npmLockFiles = execSync(`find ${repoRoot} -name "package-lock.json"`, { cwd: repoRoot }) - .toString() - .trim() - .split('\n'); - [...yarnLockFiles, ...npmLockFiles].forEach(file => { - console.log(`reverting changes to ${file}`); - execSync(`git checkout -- ${file}`); - }); - console.log('Successfully reverted changes to all yarn.lock files.'); - } catch (error) { - console.error('Error resetting yarn.lock files:', error); - } + if (process.env['INPUT_SKIP-TAG'] !== 'true') { await runInWorkspace('git', ['tag', newVersion]); From 214941393817efa678bd6ab3a93f369adb0b58fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 02:14:04 -0300 Subject: [PATCH 25/28] wip --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index dbb3264fb..ddfe4bc5e 100644 --- a/index.js +++ b/index.js @@ -210,11 +210,12 @@ const pkg = getPackageJson(); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { // Find all yarn.lock files and checkout each one individually + const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); + console.log('Repository root detected:', repoRoot); try { const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); console.log(`Git status output:\n${statusOutput}`); - const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); - console.log('Repository root detected:', repoRoot); + // Find all tracked yarn.lock files in the repository From 4d252f92d9323abf003b0e9c76298d5757be308f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 02:19:48 -0300 Subject: [PATCH 26/28] wip --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ddfe4bc5e..2c2ede821 100644 --- a/index.js +++ b/index.js @@ -226,15 +226,20 @@ const pkg = getPackageJson(); for (const file of yarnLockFiles) { if (file) { + const absolutePath = `${repoRoot}/${file}`; console.log(`Processing yarn.lock file: ${file}`); // Uncommit the file: remove it from the last commit - await runInWorkspace('git', ['reset', 'HEAD', file], repoRoot); - console.log(`Uncommitted: ${file}`); + execSync(`git reset HEAD ${absolutePath}`); + console.log(`Uncommitted: ${absolutePath}`); // Revert changes to the file - await runInWorkspace('git', ['checkout', '--', file], repoRoot); - console.log(`Reverted changes to: ${file}`); + execSync(`git checkout -- ${absolutePath}`); + console.log(`Reverted changes to: ${absolutePath}`); + + // Optional: Temporarily ignore the file to avoid accidental staging + execSync(`echo "${absolutePath}" >> ${repoRoot}/.gitignore`); + console.log(`Temporarily ignored: ${absolutePath}`); } } } catch (error) { From 8addd833baa1b0719a137144f0337fb94c46dd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 02:23:01 -0300 Subject: [PATCH 27/28] wip --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2c2ede821..11c518c22 100644 --- a/index.js +++ b/index.js @@ -238,8 +238,8 @@ const pkg = getPackageJson(); console.log(`Reverted changes to: ${absolutePath}`); // Optional: Temporarily ignore the file to avoid accidental staging - execSync(`echo "${absolutePath}" >> ${repoRoot}/.gitignore`); - console.log(`Temporarily ignored: ${absolutePath}`); + // execSync(`echo "${absolutePath}" >> ${repoRoot}/.gitignore`); + // console.log(`Temporarily ignored: ${absolutePath}`); } } } catch (error) { From 58dc2737910cd0f31a18b1ab6929265411ca0788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20C=C3=A9sar?= Date: Wed, 27 Nov 2024 02:27:29 -0300 Subject: [PATCH 28/28] wip --- index.js | 91 +++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/index.js b/index.js index 11c518c22..bd701be8b 100644 --- a/index.js +++ b/index.js @@ -209,44 +209,34 @@ const pkg = getPackageJson(); console.log('newVersion 1:', newVersion); newVersion = `${tagPrefix}${newVersion}${tagSuffix}`; if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { - // Find all yarn.lock files and checkout each one individually - const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); - console.log('Repository root detected:', repoRoot); - try { - const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); - console.log(`Git status output:\n${statusOutput}`); - - - - // Find all tracked yarn.lock files in the repository - const yarnLockFiles = execSync(`git ls-files | grep -E 'yarn.lock|package-lock.json'`, { cwd: repoRoot }) - .toString() - .trim() - .split('\n'); - - for (const file of yarnLockFiles) { - if (file) { - const absolutePath = `${repoRoot}/${file}`; - console.log(`Processing yarn.lock file: ${file}`); - - // Uncommit the file: remove it from the last commit - execSync(`git reset HEAD ${absolutePath}`); - console.log(`Uncommitted: ${absolutePath}`); - - // Revert changes to the file - execSync(`git checkout -- ${absolutePath}`); - console.log(`Reverted changes to: ${absolutePath}`); - - // Optional: Temporarily ignore the file to avoid accidental staging - // execSync(`echo "${absolutePath}" >> ${repoRoot}/.gitignore`); - // console.log(`Temporarily ignored: ${absolutePath}`); - } + + // find all lock files and rmeove it from commit + // use absolute path to avoid problem with directories + const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim(); + try { + // yarn and npm for now + const lockFiles = execSync(`git ls-files | grep -E 'yarn.lock|package-lock.json'`, { cwd: repoRoot }) + .toString() + .trim() + .split('\n'); + + for (const file of lockFiles) { + if (file) { + const absolutePath = `${repoRoot}/${file}`; + console.log(`Processing yarn.lock file: ${file}`); + + // Uncommit the file: remove it from the last commit + execSync(`git reset HEAD ${absolutePath}`); + console.log(`Uncommitted: ${absolutePath}`); + + // Revert changes to the file + execSync(`git checkout -- ${absolutePath}`); + console.log(`Reverted changes to: ${absolutePath}`); } - } catch (error) { - console.error('Error while processing yarn.lock files:', error); } - const statusOutput = execSync('git status', { cwd: repoRoot }).toString(); - console.log(`Git status output (2):\n${statusOutput}`); + } catch (error) { + console.error('Error while processing lock files:', error); + } await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); } @@ -274,25 +264,26 @@ const pkg = getPackageJson(); // for runner < 2.297.0 console.log(`::set-output name=newTag::${newVersion}`); } + try { + // to support "actions/checkout@v1" + if (process.env['INPUT_SKIP-COMMIT'] !== 'true') { + if (process.env['INPUT_COMMIT-NO-VERIFY'] === 'true') { + await runInWorkspace('git', ['commit', '-a', '--no-verify', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); + } else { + await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]); + } + } + } catch (e) { + // console.warn( + // 'git commit failed because you are using "actions/checkout@v2" or later; ' + + // 'but that doesnt matter because you dont need that git commit, thats only for "actions/checkout@v1"', + // ); + } const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@${ process.env['INPUT_CUSTOM-GIT-DOMAIN'] || 'github.com' }/${process.env.GITHUB_REPOSITORY}.git`; - - - - if (process.env['INPUT_SKIP-TAG'] !== 'true') { - await runInWorkspace('git', ['tag', newVersion]); - if (process.env['INPUT_SKIP-PUSH'] !== 'true') { - await runInWorkspace('git', ['push', remoteRepo, '--follow-tags']); - await runInWorkspace('git', ['push', remoteRepo, '--tags']); - } - } else { - if (process.env['INPUT_SKIP-PUSH'] !== 'true') { - await runInWorkspace('git', ['push', remoteRepo]); - } - } } catch (e) { logError(e); exitFailure('Failed to bump version');