Skip to content

Commit 3727d6c

Browse files
Ignore changes on target branch
When computing diff (for transient PR), consider only the changes introduced by this PR. Issue: ZENKO-5132
1 parent ba2acec commit 3727d6c

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

.github/actions/create-component-deployments/action.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ runs:
5757
id: filter
5858
shell: bash
5959
run: |
60-
git fetch origin "${{ inputs.target-branch }}" --depth=1
61-
git show "origin/${{ inputs.target-branch }}:${{ inputs.deps-file }}" > /tmp/base-deps.yaml 2>/dev/null || echo '{}' > /tmp/base-deps.yaml
60+
# Diff against the merge-base (common ancestor with target branch) rather
61+
# than the target branch tip, so deps where the PR branch is merely
62+
# behind on target don't show up as "changed". Requires fetch-depth: 0
63+
# on the caller checkout.
64+
git fetch origin "${{ inputs.target-branch }}"
65+
base_ref=$(git merge-base HEAD "origin/${{ inputs.target-branch }}")
66+
echo "Diffing against merge-base $base_ref"
67+
git show "$base_ref:${{ inputs.deps-file }}" > /tmp/base-deps.yaml 2>/dev/null || echo '{}' > /tmp/base-deps.yaml
6268
6369
yq eval-all '
6470
select(fi == 0) as $curr | select(fi == 1) as $base |

.github/workflows/end2end.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ jobs:
730730
steps:
731731
- name: Checkout
732732
uses: actions/checkout@v6
733+
with:
734+
fetch-depth: 0
735+
filter: blob:none
733736
- name: Determine CI result
734737
id: result
735738
env:

tests/workflows/create-component-deployments.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,62 @@ describe("create-component-deployments action", () => {
235235
expect(deployStep?.status).toBe(0);
236236
});
237237

238+
it("should ignore deps advanced on target branch after the feature branch was created", async () => {
239+
// Simulate a stale feature branch: target branch moves on (backbeat bumped)
240+
// while the feature branch only touches sorbet. Diff should be vs the
241+
// merge-base, not the target tip, so backbeat must not be deployed.
242+
nock("http://api.github.com").delete("/installation/token").reply(204).persist();
243+
244+
const repoPath = github.repo.getPath("zenko");
245+
await exec(`git -C ${repoPath} checkout development/2.11`);
246+
await exec(`yq -i '.backbeat.tag = "9.3.5"' ${repoPath}/solution/deps.yaml`);
247+
await exec(`git -C ${repoPath} commit -m "bump backbeat on target" -- solution/deps.yaml`);
248+
await exec(`git -C ${repoPath} push origin development/2.11`);
249+
await exec(`git -C ${repoPath} checkout improvement/ZENKO-5210`);
250+
251+
act.setEnv("GITHUB_SHA", await getCommitHash());
252+
act.setInput("target-branch", "development/2.11");
253+
254+
const result = await act.runEvent("workflow_dispatch", {
255+
logFile: process.env.ACT_LOG ? path.join(__dirname, "act-delta-stale.log") : undefined,
256+
mockApi: [
257+
moctokit.rest.apps.getRepoInstallation().reply({
258+
status: 200,
259+
data: { id: 1, app_id: 12345, app_slug: "test-app" },
260+
repeat: 5,
261+
}),
262+
moctokit.rest.apps.createInstallationAccessToken().reply({
263+
status: 201,
264+
data: { token: "ghs_fake_token" },
265+
repeat: 5,
266+
}),
267+
268+
// Only sorbet should be deployed (merge-base diff). Backbeat
269+
// differs vs target tip but was not touched by the feature
270+
// branch, so no mock for it.
271+
moctokit.rest.repos.createDeployment({
272+
owner: "scality",
273+
repo: "sorbet",
274+
ref: "v1.2.2",
275+
...commonDeploymentParams,
276+
}).reply({ status: 201, data: { id: 101 } }),
277+
278+
moctokit.rest.repos.createDeploymentStatus({
279+
owner: "scality",
280+
repo: "sorbet",
281+
deployment_id: 101,
282+
state: "in_progress",
283+
log_url: "https://github.com/scality/zenko/actions/runs/1",
284+
description: "Zenko CI running",
285+
}).reply({ status: 201, data: { id: 1 } }),
286+
],
287+
bind: true,
288+
});
289+
290+
expect(findStep(result, "Filter to changed dependencies")?.status).toBe(0);
291+
expect(findStep(result, "Create or update deployments")?.status).toBe(0);
292+
});
293+
238294
it("should skip deployments when no deps changed", async () => {
239295
// Point to the same branch — no diff, so no components
240296
act.setInput("target-branch", "improvement/ZENKO-5210");

0 commit comments

Comments
 (0)