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

Closes #143 Add report add process to rename and push test files to git #174

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions config/wp.config.sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const {
WP_SSH_USERNAME = '',
WP_SSH_ADDRESS = '',
WP_SSH_KEY = '',
WP_SSH_ROOT_DIR = ''
WP_SSH_ROOT_DIR = '',
GITHUB_PAT = ''
} = process.env;

/**
Expand Down Expand Up @@ -98,5 +99,6 @@ export {
WP_SSH_ADDRESS,
WP_SSH_KEY,
WP_SSH_ROOT_DIR,
SCENARIO_URLS
SCENARIO_URLS,
GITHUB_PAT
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test:lrc": "$npm_package_config_testCommand --tags @lrc",
"test:performancehints": "$npm_package_config_testCommand --tags @performancehints",
"healthcheck": "ts-node healthcheck.ts",
"push-report": "ts-node report.ts",
"wp-env": "wp-env"
},
"repository": {
Expand Down
82 changes: 82 additions & 0 deletions report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import fs from 'fs';
import path from "path";
import {exec} from "child_process";
import { GITHUB_PAT} from "./config/wp.config";

const GIT_PAT = GITHUB_PAT;
if (!GIT_PAT) {
console.error('Github PAT is not defined in the environment variables.');
process.exit(1);
}

const remoteUrl = `https://${GIT_PAT}@github.com/wp-media/e2e_release_reports.git`;

const testResults = path.join(__dirname, 'test-results');

const args = process.argv.slice(2);
if(args.length < 1) {
console.log(GIT_PAT);
console.error('Please provide the new naming for test folder')
}
const newTestDir = args[0];

const gitCommands = `
git checkout -b ${newTestDir};
git add . && git commit -m "Test report";
git push origin test
`;


//Check if .git directory exists
export async function checkGitInitialized(callback) : Promise<void>{
const gitDir = path.join(newTestDir, '.git');
if (!fs.existsSync(gitDir)) {
console.log('Git is not initialized. Setting it up...');
exec(`git init && git remote add origin ${remoteUrl}`, {cwd: newTestDir}, (initErr) => {
if (initErr) {
console.error('Error initializing Git:', initErr);
process.exit(1);
}
console.log('Git initialized and remote added.');
callback();
});

//Execute command to have username, default it to e2e environment
exec('git config --global user.name "E2E Environment" && git config --global user.email "e2e.report@wp-media.me"', (err) => {
if (err) {
console.error('Error setting global Git config:', err);
} else {
console.log('Global Git config set.');
}
});
} else {
callback();
}
}

// Rename test folder and push
fs.rename(testResults, newTestDir, (err) => {
if (err) {
console.error('Error renaming/moving file:', err);
} else {
checkGitInitialized(() => {
exec(gitCommands, { cwd: newTestDir }, (err, stdout, stderr) => {
if (err) {
console.error('Error executing git commands:', err);
}

if (stderr) {
console.error('Git stderr output:', stderr);
return;
}

//Revert the renaming of test folder to avoid tracking it in e2e
fs.rename(newTestDir, testResults, (err) => {
if (err) {
console.error('Error reverting the directory name:', err);
}
});
});
})
}
});
Loading