Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(github): improvement to check config data #15406

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions scripts/ci/check-connect-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,33 @@ const updateConfigFromJSON = async () => {

console.log('Checking if there were changes.');
const changes = await exec('git', ['diff', CONFIG_FILE_PATH]);
if (changes.stdout !== '') {
// 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}`;

// Check if PR with same hash, so no new changes is already open, if so, ignore it, no new changes to add.
const prAlreadyOpen = await exec('gh', [
'search',
'prs',
'--repo=trezor/trezor-suite',
`--head=${branchName}`,
'--state=open',
]);

console.log('prAlreadyOpen', prAlreadyOpen);

const isSamePrAlreadyOpen = prAlreadyOpen.stdout !== '';
const isChangesFromRemote = changes.stdout !== '';

if (isSamePrAlreadyOpen) {
console.log('There is already a PR open with same changes.');
}

if (!isSamePrAlreadyOpen && isChangesFromRemote) {
console.log('There were changes in keys.');

// Before creating the new PR with new keys we check if there was already previous one.
Expand All @@ -92,7 +118,6 @@ const updateConfigFromJSON = async () => {
'--head=chore/update-device-authenticity-config',
'--state=open',
]);

console.log('prList', prList);

if (prList.stdout !== '') {
Expand Down Expand Up @@ -120,17 +145,17 @@ const updateConfigFromJSON = async () => {
console.error(`Failed to close PR #${prNumber}:`, error.message);
}
}
try {
console.log(`Deleting branch ${branchName}`);
await exec('gh', ['branch', '-d', branchName, '--repo', 'trezor/trezor-suite']);
console.log(`Deleted branch ${branchName}`);
} 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({
Expand Down
Loading