diff --git a/scripts/ci/check-connect-data.ts b/scripts/ci/check-connect-data.ts index a2a9408ebf73..a15dcf5a7d76 100644 --- a/scripts/ci/check-connect-data.ts +++ b/scripts/ci/check-connect-data.ts @@ -78,6 +78,14 @@ const updateConfigFromJSON = async () => { console.log('Checking if there were changes.'); const changes = await exec('git', ['diff', CONFIG_FILE_PATH]); + // Use the content to generate the hash in the branch so it is the same with same content. + // If we would use the hash provided by Git it would be different because it contains date as well. + const fileContent = await fs.readFile(CONFIG_FILE_PATH, 'utf8'); + const hash = crypto.createHash('sha256').update(fileContent).digest('hex'); + + // Use the hash to create branch name to avoid using a branch that already exists. + const branchName = `chore/update-device-authenticity-config-${hash}`; + if (changes.stdout !== '') { console.log('There were changes in keys.'); @@ -120,17 +128,17 @@ const updateConfigFromJSON = async () => { console.error(`Failed to close PR #${prNumber}:`, error.message); } } + try { + console.log(`Deleting branch ${trimmedBranchName}`); + await exec('gh', ['branch', '-d', branchName, '--repo', 'trezor/trezor-suite']); + console.log(`Deleted branch ${trimmedBranchName}`); + } catch (error) { + console.error(`Failed to delete branch ${branchName}:`, error.message); + } } else { console.log(`No open pull requests found.`); } - // Use the content to generate the hash in the branch so it is the same with same content. - // If we would use the hash provided by Git it would be different because it contains date as well. - const fileContent = await fs.readFile(CONFIG_FILE_PATH, 'utf8'); - const hash = crypto.createHash('sha256').update(fileContent).digest('hex'); - - // Use the hash to create branch name to avoid using a branch that already exists. - const branchName = `chore/update-device-authenticity-config-${hash}`; const commitMessage = 'chore(connect): update device authenticity config'; await exec('git', ['checkout', '-b', branchName]); commit({