Skip to content

Commit

Permalink
Error handling on global-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
muradium committed Dec 14, 2024
1 parent 3e686af commit 3fba5ac
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/test/playwright/init/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,31 @@ async function globalSetup() {
fs.mkdirSync(sshDir, { recursive: true });
}

for (const keyName of Object.values(SSH_KEY_NAMES)) {
const sourceKey = path.join(process.cwd(), 'ssh-keys', keyName);
const sourceKeyPub = path.join(process.cwd(), 'ssh-keys', `${keyName}.pub`);
const destKey = path.join(sshDir, keyName);
const destKeyPub = path.join(sshDir, `${keyName}.pub`);

if (!fs.existsSync(destKey)) {
fs.copyFileSync(sourceKey, destKey);
fs.chmodSync(destKey, 0o600);
console.log(`Private SSH key ${keyName} copied.`);
} else {
console.log(`Private SSH key ${keyName} already exists, skipping.`);
}

if (!fs.existsSync(destKeyPub)) {
fs.copyFileSync(sourceKeyPub, destKeyPub);
fs.chmodSync(destKeyPub, 0o644);
console.log(`Public SSH key ${keyName} copied.`);
} else {
console.log(`Public SSH key ${keyName} already exists, skipping.`);
try {
for (const keyName of Object.values(SSH_KEY_NAMES)) {
const sourceKey = path.join(process.cwd(), 'ssh-keys', keyName);
const sourceKeyPub = path.join(process.cwd(), 'ssh-keys', `${keyName}.pub`);
const destKey = path.join(sshDir, keyName);
const destKeyPub = path.join(sshDir, `${keyName}.pub`);

if (!fs.existsSync(destKey)) {
fs.copyFileSync(sourceKey, destKey);
fs.chmodSync(destKey, 0o600);
console.log(`Private SSH key ${keyName} copied.`);
} else {
console.log(`Private SSH key ${keyName} already exists, skipping.`);
}

if (!fs.existsSync(destKeyPub)) {
fs.copyFileSync(sourceKeyPub, destKeyPub);
fs.chmodSync(destKeyPub, 0o644);
console.log(`Public SSH key ${keyName} copied.`);
} else {
console.log(`Public SSH key ${keyName} already exists, skipping.`);
}
}
} catch (error) {
console.error('Error during SSH key setup:', error);
}

console.log('Global setup completed.');
Expand Down

0 comments on commit 3fba5ac

Please sign in to comment.