Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get git commits in diff #42

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Get git commits in diff #42

wants to merge 1 commit into from

Conversation

jsegaran
Copy link
Contributor

No description provided.

Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good — my main suggestion is to keep the ArtifactRegistryDockerRegistryClient as a thin wrapper around a single AR call (converting inputs and outputs) and put the actual logic in update-docker-tags.ts or its own file or something, so that the logic can be tested with a mock client.

for (const dockerInfo of dockerInfos) {
if (!dockerInfo.version || !dockerInfo.name) continue;

const tag = this.client.pathTemplates.tagPathTemplate.match(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const tag = this.client.pathTemplates.tagPathTemplate.match(
const { tag } = this.client.pathTemplates.tagPathTemplate.match(

if you want

dockerInfo.name,
).tag;

// If it is a number we can ignore the tag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this happen?

const gitCommitMatches = tag.match(/-g([0-9a-fA-F]+)$/);
if (
((tag >= prevTag && tag <= nextTag) ||
(tag <= prevTag && tag >= nextTag)) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this version? for rollbacks or something?

const relevantCommits = new Array<{ tag: string; commit: string }>();

for (const tagBound of tagBoundsMap.values()) {
// We can skip the tag we are just coming from as a min
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we should be skipping the version we came from, whether or not prevTag is itself actually the min for that version?

async getGitCommitsBetweenTags(
options: GitCommitsBetweenTagsOptions,
): Promise<string[]> {
// For now we aren't caching anything since this will on run on promotion prs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguably the thing we want to cache here is the listTags call, not the higher level calculation. but you're right that most of the time there's only one promotion being considered for any given docker image... that said, it might make sense to make the DockerRegistryClient method be just the equivalent of the listTags which would allow you to mock that out and test the "find min" logic directly.

// We only care about the tags between prev and next that have a git commit
const gitCommitMatches = tag.match(/-g([0-9a-fA-F]+)$/);
if (
((tag >= prevTag && tag <= nextTag) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some level it should refuse to opine about the list of changes unless both given tags contain --- with the same string before it. Otherwise the comparison is invalid

gitCommitMatches
) {
const minTag = tagBoundsMap.get(dockerInfo.version);
if (minTag && minTag.tag > tag) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the right algorithm for handling reverts (in the source repo) properly. For example, let's say we have commit 100 currently deployed. 105 makes some change, 110 reverts it (so that the 100 image and the 110 image are the same). This algorithm will ignore the 110 change because it's the same as the original deployed change. The same thing happens if there was some other change 103 too (so that 110 matches 103) — the list would include 103 and 105 but not 110.

I think the right thing to do is sort the tags and process them in order and skip tags if the image is the same as the previous one you kept, but not doing a more global "skip if any smaller tags have the same version".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants