Skip to content

Commit

Permalink
fix: ensure tests are properly running against broken main
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Sep 6, 2023
1 parent 08a0b0a commit b24ad36
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/integration-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ jobs:
- name: Verify default Push Workflow
if: ${{ github.event_name != 'pull_request' }}
run: |
BASE_SHA=$(echo $(git rev-parse HEAD~1))
echo "BASE SHA: $NX_BASE"
if git merge-base --is-ancestor $NX_BASE HEAD; then
BASE_SHA=$NX_BASE;
else
BASE_SHA="";
fi
HEAD_SHA=$(echo $(git rev-parse HEAD))
node -e "if(process.env.NX_BASE == '${BASE_SHA}') console.log('Base set correctly'); else { throw new Error('Base not set correctly!');}"
node -e "if(process.env.NX_HEAD == '${HEAD_SHA}') console.log('Head set correctly'); else { throw new Error('Head not set correctly!');}"
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ jobs:
if: github.event_name != 'pull_request'
shell: bash
run: |
BASE_SHA=$(echo $(git rev-parse HEAD~1))
echo "BASE SHA: $NX_BASE"
if git merge-base --is-ancestor $NX_BASE HEAD; then
BASE_SHA=$NX_BASE;
else
BASE_SHA="";
fi
HEAD_SHA=$(echo $(git rev-parse HEAD))
node -e "if(process.env.NX_BASE == '${BASE_SHA}') console.log('Base set correctly'); else { throw new Error('Base not set correctly!');}"
node -e "if(process.env.NX_HEAD == '${HEAD_SHA}') console.log('Head set correctly'); else { throw new Error('Head not set correctly!');}"
17 changes: 11 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13709,7 +13709,7 @@ var __webpack_exports__ = {};
const { Octokit } = __nccwpck_require__(1231);
const core = __nccwpck_require__(2186);
const github = __nccwpck_require__(5438);
const { execSync } = __nccwpck_require__(2081);
const { spawnSync } = __nccwpck_require__(2081);
const { existsSync } = __nccwpck_require__(7147);

const { runId, repo: { repo, owner }, eventName } = github.context;
Expand All @@ -13732,10 +13732,13 @@ let BASE_SHA;
}
}

const HEAD_SHA = execSync(`git rev-parse HEAD`, { encoding: 'utf-8' });
const headResult = spawnSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf-8' });
const HEAD_SHA = headResult.stdout;

if (eventName === 'pull_request') {
BASE_SHA = execSync(`git merge-base origin/${mainBranchName} HEAD`, { encoding: 'utf-8' });

if (['pull_request','pull_request_target'].includes(eventName)) {
const baseResult = spawnSync('git', ['merge-base', `origin/${mainBranchName}`, 'HEAD'], { encoding: 'utf-8' });
BASE_SHA = baseResult.stdout;
} else {
try {
BASE_SHA = await findSuccessfulCommit(workflowId, runId, owner, repo, mainBranchName, lastSuccessfulEvent);
Expand All @@ -13755,7 +13758,9 @@ let BASE_SHA;
process.stdout.write('\n');
process.stdout.write(`NOTE: You can instead make this a hard error by setting 'error-on-no-successful-workflow' on the action in your workflow.\n`);

BASE_SHA = execSync(`git rev-parse origin/${mainBranchName}~1`, { encoding: 'utf-8' });
const baseRes = spawnSync('git', ['rev-parse', `origin/${mainBranchName}~1`], { encoding: 'utf-8' });
BASE_SHA = baseRes.stdout;

core.setOutput('noPreviousBuild', 'true');
}
} else {
Expand Down Expand Up @@ -13836,7 +13841,7 @@ async function findExistingCommit(shas) {
*/
async function commitExists(commitSha) {
try {
execSync(`git cat-file -e ${commitSha}`, { stdio: ['pipe', 'pipe', null] });
spawnSync('git', ['cat-file', '-e', commitSha], { stdio: ['pipe', 'pipe', null] });
return true;
} catch {
return false;
Expand Down

0 comments on commit b24ad36

Please sign in to comment.