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

Versions: keep type of version in sync with the project #10606

Merged
merged 6 commits into from
Aug 10, 2023
Merged

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Aug 8, 2023

So, there are a couple of problems here:

  • Versions have been created with the type set as unknown, and where never updated to the correct type. I was able to track down this to projects created before 2018, so probably an old bug allowed this to happen.
  • Stable machine versions are basically an alias for the latest stable version of the project, and they can be a branch or a tag, this means that if this version is a branch, so will be the "stable" version, same for tags. Currently, we aren't updating the version type, if the stable version was created as a branch, it will remain as a branch, even if the latest stable version is a tag, and vice versa.
  • Latest machine versions are basically an alias for the default branch of the project, they are always branches. Since we allow having non-machine latest versions, they can be a branch or a tag. If this version was changed back to be a non-machine version, currently it will remain as branch or tag, this was incorrect.

Our new clone/checkout pattern relies on the type of the version always being correct, so it was failing for some projects.

After deploy, we need to clean up the invalid versions (versions with "unknown" type). We can do that by:

  • Updating all latest machine versions to be branches.

    Version.objects.filter(type="unknown", machine=True, slug='latest').update(type="branch")
  • Re-evaluate the stable version of all projects that have a machine stable version, so they can have the correct type.

    for project in Project.objects.filter(versions__machine=True).distinct():
        project.update_stable_version()
  • Check all remaining active versions with "unknown" type, and update them to be branches or tags (324). We can use a simple regex to see the version identifier looks like a commit.

    vesions = Version.objects.filter(type="unknown", active=True)
    commit_regex = re.compile(r"^([a-f0-9]{40})|([a-f0-9]{7})$")
    for version in versions:
      if commit_regex.match(version.identifier):
        version.type = "tag"
      else:
        version.type = "branch"
      version.save()

So, there are a couple of problems here:

- Versions have been created with the type set as unknown,
  and where never updated to the correct type.
  I was able to track down this to projects created before 2018,
  so probably an old bug allowed this to happen.
- Stable machine versions are basically an alias for the latest stable version
  of the project, and they can be a branch or a tag,
  this means that if this version is a branch,
  so will be the "stable" version, same for tags.
  Currently, we aren't updating the version type,
  if the stable version was created as a branch,
  it will remain as a branch, even if the latest stable version
  is a tag, and vice versa.
- Latest machine versions are basically an alias for the default branch
  of the project, they are always branches.
  Since we allow to have non-machine latest versions,
  they can be a branch or a tag. If this version was changed
  back to be a non-machine version, currently it will remain as branch
  or tag, this was incorrect.

Our new clone/checkout pattern relies on the type of the version always
being correct, so it was failing for some projects.

- Fixes #10600
- Fixes #10601

After deploy, we need to clean up the invalid versions (versions with
"unknown" type). We can do that by:

- Updating all latest machine versions to be branches.

  ```python
  Version.objects.filter(type="unknown", machine=True).update(type="branch")
  ```

- Re-evaluate the stable version of all projects that have a machine
  stable version, so they can have the correct type.

  ```
  for project in Project.objects.filter(versions__machine=True).distinct():
      project.update_stable_version()
  ```

- Check all remaining active versions with "unknown" type, and update them to
  be branches or tags (324). We can use a simple regex to see the
  version identifier looks like a commit.

  ```python
  vesions = Version.objects.filter(type="unknown", active=True)
  commit_regex = re.compile(r"^([a-f0-9]{40})|([a-f0-9]{7})$")
  for version in versions:
      if commit_regex.match(version.identifier):
          version.type = "tag"
      else:
          version.type = "branch"
      version.save()
  ```
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

This is great! Thanks for fixing this issue. I'm happy to deploy this next week and continue moving forward with our new Git+Clone+Fetch implementation 🚀

@stsewd stsewd marked this pull request as ready for review August 8, 2023 17:45
@stsewd stsewd requested a review from a team as a code owner August 8, 2023 17:45
@stsewd stsewd requested a review from humitos August 8, 2023 17:45
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

This looks good!

I left a question about "stable" and "original stable" that I'd like to understand more so we can update the docstring of that method and make it clearer.

@stsewd stsewd merged commit e11792b into main Aug 10, 2023
@stsewd stsewd deleted the fix-stable-latest branch August 10, 2023 18:27
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.

Building latest fails at checkout git fetch looks for non-existant commit
2 participants