Skip to content

Commit

Permalink
fix: use pr base branch if available for no remote content access mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Oct 11, 2024
1 parent 0e6df53 commit 459eb33
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/core/src/ci-environment/services/bitrise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const service: Service = {
runAttempt: null,
prNumber: getPrNumber({ env }),
prHeadCommit: null,
prBaseBranch: null,
nonce: env.BITRISEIO_PIPELINE_ID || null,
};
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ci-environment/services/buildkite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const service: Service = {
? Number(env.BUILDKITE_PULL_REQUEST)
: null,
prHeadCommit: null,
prBaseBranch: null,
nonce: env.BUILDKITE_BUILD_ID || null,
};
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ci-environment/services/circleci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const service: Service = {
runAttempt: null,
prNumber: getPrNumber({ env }),
prHeadCommit: null,
prBaseBranch: null,
nonce: env.CIRCLE_WORKFLOW_ID || env.CIRCLE_BUILD_NUM || null,
};
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ci-environment/services/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const service: Service = {
runAttempt: null,
prNumber: null,
prHeadCommit: null,
prBaseBranch: null,
nonce: null,
};
},
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/ci-environment/services/github-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type EventPayload = {
sha: string;
ref: string;
};
base: {
sha: string;
ref: string;
};
number: number;
};
deployment?: {
Expand Down Expand Up @@ -159,6 +163,7 @@ const service: Service = {
branch: pullRequest?.head.ref || payload.deployment.environment || null,
prNumber: pullRequest?.number || null,
prHeadCommit: pullRequest?.head.sha || null,
prBaseBranch: null,
};
}

Expand All @@ -168,6 +173,7 @@ const service: Service = {
payload?.pull_request?.head.ref || getBranch(context, payload) || null,
prNumber: payload?.pull_request?.number || null,
prHeadCommit: payload?.pull_request?.head.sha ?? null,
prBaseBranch: payload?.pull_request?.base.ref ?? null,
};
},
getMergeBaseCommitSha,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ci-environment/services/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const service: Service = {
runAttempt: null,
prNumber: null,
prHeadCommit: null,
prBaseBranch: null,
nonce: env.CI_PIPELINE_ID || null,
};
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ci-environment/services/heroku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const service: Service = {
runAttempt: null,
prNumber: null,
prHeadCommit: null,
prBaseBranch: null,
nonce: env.HEROKU_TEST_RUN_ID || null,
}),
getMergeBaseCommitSha,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ci-environment/services/travis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const service: Service = {
runAttempt: null,
prNumber: getPrNumber(ctx),
prHeadCommit: null,
prBaseBranch: null,
nonce: env.TRAVIS_BUILD_ID || null,
};
},
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/ci-environment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export interface CiEnvironment {
*/
prHeadCommit: string | null;

/**
* The branch name that the pull request is targeting.
*/
prBaseBranch: string | null;

/**
* A unique string for each run of a particular workflow in a repository.
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ const schema = {
default: null,
nullable: true,
},
prBaseBranch: {
env: "ARGOS_PR_BASE_BRANCH",
format: String,
default: null,
nullable: true,
},
parallel: {
env: "ARGOS_PARALLEL",
default: false,
Expand Down Expand Up @@ -177,6 +183,7 @@ export interface Config {
runAttempt: number | null;
prNumber: number | null;
prHeadCommit: string | null;
prBaseBranch: string | null;
mode: "ci" | "monitoring" | null;
ciProvider: string | null;
threshold: number | null;
Expand All @@ -202,6 +209,7 @@ export async function readConfig(options: Partial<Config> = {}) {
prNumber:
options.prNumber || config.get("prNumber") || ciEnv?.prNumber || null,
prHeadCommit: config.get("prHeadCommit") || ciEnv?.prHeadCommit || null,
prBaseBranch: config.get("prBaseBranch") || ciEnv?.prBaseBranch || null,
referenceBranch:
options.referenceBranch || config.get("referenceBranch") || null,
referenceCommit:
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,17 @@ export async function upload(params: UploadParameters) {
return null;
}

const sha = getMergeBaseCommitSha({
base: referenceBranch,
head: config.branch,
});
// We use the pull request as base branch if possible.
const base = config.prBaseBranch || referenceBranch;

const sha = getMergeBaseCommitSha({ base, head: config.branch });

if (sha) {
debug("Found reference commit from git", sha);
} else {
debug("No reference commit found in git");
}

return sha;
})();

Expand Down

0 comments on commit 459eb33

Please sign in to comment.