Skip to content

Commit

Permalink
Merge branch 'Version-v12.2.0' into v12.2.0-sync-v12.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudahtt authored Sep 3, 2024
2 parents ee3ad72 + 7a5acb3 commit fa444cf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
9 changes: 1 addition & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ develop_master_rc_only: &develop_master_rc_only
- master
- /^Version-v(\d+)[.](\d+)[.](\d+)/

exclude_develop_master_rc: &exclude_develop_master_rc
filters:
branches:
ignore:
- develop
- master
- /^Version-v(\d+)[.](\d+)[.](\d+)/
aliases:
# Shallow Git Clone
- &shallow-git-clone
Expand Down Expand Up @@ -113,7 +106,6 @@ workflows:
- check-pr-tag
- prep-deps
- get-changed-files-with-git-diff:
<<: *exclude_develop_master_rc
requires:
- prep-deps
- test-deps-audit:
Expand Down Expand Up @@ -471,6 +463,7 @@ jobs:
- run: sudo corepack enable
- attach_workspace:
at: .
- gh/install
- run:
name: Get changed files with git diff
command: npx tsx .circleci/scripts/git-diff-develop.ts
Expand Down
45 changes: 41 additions & 4 deletions .circleci/scripts/git-diff-develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ import { promisify } from 'util';

const exec = promisify(execCallback);

const MAIN_BRANCH = 'develop';

/**
* Get the target branch for the given pull request.
*
* @returns The name of the branch targeted by the PR.
*/
async function getBaseRef(): Promise<string | null> {
if (!process.env.CIRCLE_PULL_REQUEST) {
return null;
}

// We're referencing the CIRCLE_PULL_REQUEST environment variable within the script rather than
// passing it in because this makes it easier to use Bash parameter expansion to extract the
// PR number from the URL.
const result = await exec(`gh pr view --json baseRefName "\${CIRCLE_PULL_REQUEST##*/}" --jq '.baseRefName'`);
const baseRef = result.stdout.trim();
return baseRef;
}

/**
* Fetches the git repository with a specified depth.
*
Expand Down Expand Up @@ -76,14 +96,31 @@ async function gitDiff(): Promise<string> {
*/
async function storeGitDiffOutput() {
try {
console.log("Attempting to get git diff...");
const diffOutput = await gitDiff();
console.log(diffOutput);

// Create the directory
// This is done first because our CirleCI config requires that this directory is present,
// even if we want to skip this step.
const outputDir = 'changed-files';
fs.mkdirSync(outputDir, { recursive: true });

console.log(`Determining whether this run is for a PR targetting ${MAIN_BRANCH}`)
if (!process.env.CIRCLE_PULL_REQUEST) {
console.log("Not a PR, skipping git diff");
return;
}

const baseRef = await getBaseRef();
if (baseRef === null) {
console.log("Not a PR, skipping git diff");
return;
} else if (baseRef !== MAIN_BRANCH) {
console.log(`This is for a PR targeting '${baseRef}', skipping git diff`);
return;
}

console.log("Attempting to get git diff...");
const diffOutput = await gitDiff();
console.log(diffOutput);

// Store the output of git diff
const outputPath = path.resolve(outputDir, 'changed-files.txt');
fs.writeFileSync(outputPath, diffOutput);
Expand Down

0 comments on commit fa444cf

Please sign in to comment.