Skip to content

Commit

Permalink
Only apply replacement build behavior for builds with uncommitted cha…
Browse files Browse the repository at this point in the history
…nges to local builds
  • Loading branch information
ghengeveld committed May 31, 2024
1 parent 3141b14 commit d19eec8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions node-src/git/findAncestorBuildWithCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const AncestorBuildsQuery = gql`
number
commit
uncommittedHash
isLocalBuild
}
}
}
Expand All @@ -26,6 +27,7 @@ export interface AncestorBuildsQueryResult {
number: number;
commit: string;
uncommittedHash: string;
isLocalBuild: boolean;
}[];
};
};
Expand Down
2 changes: 2 additions & 0 deletions node-src/git/getBaselineBuilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const BaselineCommitsQuery = gql`
commit
committedAt
uncommittedHash
isLocalBuild
changeCount
}
}
Expand All @@ -31,6 +32,7 @@ interface BaselineCommitsQueryResult {
commit: string;
committedAt: number;
uncommittedHash: string;
isLocalBuild: boolean;
changeCount: number;
}[];
};
Expand Down
28 changes: 27 additions & 1 deletion node-src/git/getChangedFilesWithReplacement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('getChangedFilesWithReplacements', () => {
number: 3,
commit: 'exists',
uncommittedHash: '',
isLocalBuild: false,
})
).toEqual({
changedFiles: ['changed', 'files'],
Expand All @@ -48,6 +49,7 @@ describe('getChangedFilesWithReplacements', () => {
number: 3,
commit: 'missing',
uncommittedHash: '',
isLocalBuild: false,
})
).toEqual({
changedFiles: ['changed', 'files'],
Expand All @@ -57,7 +59,7 @@ describe('getChangedFilesWithReplacements', () => {
expect(client.runQuery).toHaveBeenCalled();
});

it('uses a replacement when build has uncommitted changes', async () => {
it('uses a replacement when local build has uncommitted changes', async () => {
const replacementBuild = {
id: 'replacement',
number: 2,
Expand All @@ -72,6 +74,7 @@ describe('getChangedFilesWithReplacements', () => {
number: 3,
commit: 'exists',
uncommittedHash: 'abcdef',
isLocalBuild: true,
})
).toEqual({
changedFiles: ['changed', 'files'],
Expand All @@ -81,6 +84,28 @@ describe('getChangedFilesWithReplacements', () => {
expect(client.runQuery).toHaveBeenCalled();
});

it('does not use a replacement when non-local build has uncommitted changes', async () => {
const replacementBuild = {
id: 'replacement',
number: 2,
commit: 'exists',
uncommittedHash: '',
};
client.runQuery.mockReturnValue({ app: { build: { ancestorBuilds: [replacementBuild] } } });

expect(
await getChangedFilesWithReplacement(context, {
id: 'id',
number: 3,
commit: 'exists',
uncommittedHash: 'abcdef',
isLocalBuild: false,
})
).toEqual({
changedFiles: ['changed', 'files'],
});
});

it('throws if there is no replacement', async () => {
const replacementBuild = {
id: 'replacement',
Expand All @@ -96,6 +121,7 @@ describe('getChangedFilesWithReplacements', () => {
number: 3,
commit: 'missing',
uncommittedHash: '',
isLocalBuild: false,
})
).rejects.toThrow(/fatal: bad object missing/);
});
Expand Down
6 changes: 5 additions & 1 deletion node-src/git/getChangedFilesWithReplacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type BuildWithCommitInfo = {
number: number;
commit: string;
uncommittedHash: string;
isLocalBuild: boolean;
};

/**
Expand All @@ -22,7 +23,10 @@ export async function getChangedFilesWithReplacement(
build: BuildWithCommitInfo
): Promise<{ changedFiles: string[]; replacementBuild?: BuildWithCommitInfo }> {
try {
if (build.uncommittedHash) throw new Error('Build had uncommitted changes');
if (build.isLocalBuild && build.uncommittedHash) {
throw new Error('Local build had uncommitted changes');
}

const changedFiles = await getChangedFiles(build.commit);
return { changedFiles };
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions node-src/tasks/gitInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('setGitInfo', () => {
number: 1,
commit: '987bca',
uncommittedHash: '',
isLocalBuild: false,
},
});
const ctx = { log, options: { onlyChanged: true }, client } as any;
Expand Down

0 comments on commit d19eec8

Please sign in to comment.