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

Releases are deleted when mirror repository is synchronized #22066

Closed
kotovalexarian opened this issue Dec 7, 2022 · 28 comments · Fixed by #28817
Closed

Releases are deleted when mirror repository is synchronized #22066

kotovalexarian opened this issue Dec 7, 2022 · 28 comments · Fixed by #28817
Labels
Milestone

Comments

@kotovalexarian
Copy link

kotovalexarian commented Dec 7, 2022

Description

By some reason the created releases are deleted when mirror repository is synchronized even when the tags have not been recreated.

Steps

  1. Sign-in to Gitea
  2. Click "+"
  3. Click "New Migration"
  4. Click "GitHub"
  5. Put https://github.com/tailix/libkernaux in the field "Migrate / Clone From URL"
  6. Check "This repository will be a mirror"
  7. Click the button "Create repository"
  8. Click "7 tags" in the bar (the number may be different)
  9. Click "New release" on tag "v0.6.1"
  10. Put foobar in the field "Title"
  11. Click "Publish release"
  12. Click on the tab "Settings"
  13. Click the button "Synchronize Now"
  14. Wait a few (2-5) minutes
  15. Refresh the page

Expected

You should see the label "Releases [1]" (the number as a badge) among the tabs.

Got

You see the label "Releases" (without a number) among the tabs.


Gitea Version

1.17.3 (self-hosted), 1.19.0+dev-166-g0a85537c7 (try.gitea.io)

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

2.37.2

Operating System

Ubuntu 22.10

How are you running Gitea?

https://try.gitea.io & self-hosted

Database

PostgreSQL

@lunny
Copy link
Member

lunny commented Dec 8, 2022

Hm, maybe we should not allow to create release on a mirror repository?

@kotovalexarian
Copy link
Author

Why not keep them on sync?

@iarp
Copy link

iarp commented Dec 15, 2022

When setting up a migration from github and selecting the mirroring option, this disables the ability to sync labels, issues, pull requests, releases, milestones. Why would those be touched anyways during a sync when they're not configurable?

I just setup a script to do the mirroring of releases and their assets on a whole bunch of repos only to find everything gone the next day. The attachments still exist in the attachments directory but are no longer associated with any release.

@dboreham
Copy link

Also interested in addressing this problem which arises when you use the new CI features in Gitea on a mirrored repository, with CI publishing local releases.

@mrexodia
Copy link
Contributor

Any pointers where to start fixing this in the code?

@lunny
Copy link
Member

lunny commented Jul 19, 2023

My point is to prevent users to create releases on a mirror repository currently.
The second method is to not delete releases when syncing tags.

@dboreham
Copy link

Please don't prevent release creation on a mirror -- this is how we test/debug our CI processes.

@lunny
Copy link
Member

lunny commented Jul 19, 2023

Please don't prevent release creation on a mirror -- this is how we test/debug our CI processes.

OK. Then you would like the second option. But how should Gitea handle when remote tags are deleted from your view point?

@dboreham
Copy link

Do you mean local tags?

@lunny
Copy link
Member

lunny commented Jul 19, 2023

Do you mean local tags?

I mean as a mirror repository, if the source repository in the remote deleted some tags, when syncing the mirror repository, whether Gitea need to delete the release after the tags deleted?

@mrexodia
Copy link
Contributor

I would suggest to handle it the same as GitHub does. I think if you delete a tag for a release that release gets deleted or converted to draft (not 100% sure). Deleting the release in all cases is undesirable for me.

In my mirror structure I want to manually (with the API) re-create the releases and mirror the binaries too.

@dboreham
Copy link

Do you mean local tags?

I mean as a mirror repository, if the source repository in the remote deleted some tags, when syncing the mirror repository, whether Gitea need to delete the release after the tags deleted?

Not sure I care much about tags being deleted in the source repo since I'd never do that. I thought this problem was about this:

  1. Release created in mirror repo -- a release has a 1:1 relationship with a tag, implying that a tag must be created in the mirror in order to create a release there.
  2. Now sync from the source repo.
  3. The mirror is supposed to be read-only, but in step 1 we create a tag locally, hence it is not read-only.
  4. What to do about that? Delete the locally created tags, so the repo matches the source? But that means deleting the release.

@lunny
Copy link
Member

lunny commented Jul 24, 2023

Yes, that's why I think we need to disable creating releases in a mirror repository.

@dboreham
Copy link

Ok, we're on same page then.

For my purposes, I don't need tags associated with locally-created releases to be preserved in the mirror.
I would like to have releases created in the mirror be preserved.
If, as @mrexodia suggests above it is already the case that a release on a non-mirror repo will survive if its associated tag is deleted, then I'd like that same behavior on a mirror.

@mrexodia
Copy link
Contributor

Yes, that's why I think we need to disable creating releases in a mirror repository.

In my case this forces me to use a non-mirror repository and manually mirror + recreate releases. My use case is hosting a mirror with release binaries in another region. The GitHub repository I mirror from is the main development place. Currently I’m forced to use a non-mirror already so it’s fine, but in general disabling releases altogether prevents my use case of a mirror completely…

@mrexodia
Copy link
Contributor

And again, I’m happy to try to contribute to the code. I just need some pointers where to start.

@lunny
Copy link
Member

lunny commented Jul 28, 2023

Because #20311 will support mirror releases from upstream. So I think release creation on mirror repositories must be disabled. Otherwise, it will result in possible conflicts.

@lkubb
Copy link

lkubb commented Aug 15, 2023

I think there are two separate use cases for mirrored repositories:

  1. Migrating a project from GitHub etc.
  2. Keeping a local mirror of code dependencies (does not protect from force-pushed deletions ofc).

Mine is the latter. In addition, I'm building my own signed releases from those mirrors. Because of this bug, I have to manually sync a fork instead of having automatic releases.

Two proposals regarding #20311:

  1. When release syncing is available, allow to deselect it to be able to have local releases. When activating it later, warn that all local releases will be deleted if there are any.
  2. Or introduce another repo/migration type that specifically addresses (2) (code mirroring only) and allow local releases there without being able to mirror remote releases/issues etc.

Not sure about the difficulty of those proposals, just throwing it out there. I really appreciate your hard work on Gitea!

@dnviti
Copy link

dnviti commented Aug 30, 2023

This is clearly a bug.
If i mirror a repository it disables all the other options (such as releases) so i understand that it ignores them.
I needed to attach new releases in a public read-only organization and every time it syncs any release uploaded on the mirrored repo will be deleted.

@lunny
Copy link
Member

lunny commented Sep 6, 2023

Or maybe we can convert a release as draft automatically if the related tag has been removed when mirroring.

@xpufx
Copy link

xpufx commented Nov 3, 2023

I am not sure my issue is the same since most people seem to be talking about mirroring from github initially and/or creating the releases on the gitea side.

My use case is a private gitea repo that mirrors to github. The commits sync fine to the remote github repo. I want to take advantage of the Actions on Github so I create the release there - manually for now. Everything works fine until I push another commit to my private gitea instance which then syncs to Github. At this point the releases disappear because they've been converted to drafts. Is this the same issue everyone is having?

Is it happening because the gitea side does not have the tag I have to create on the github side? How should I proceed if I want to keep the same workflow?

EDIT: I just tested this. If I create a tag on the gitea side first, it gets mirrored to github and the release does not get deleted.

@Jinnrry
Copy link

Jinnrry commented Jan 16, 2024

Any results? This bug has been around for a year now. I want to use Gitea to backup Github data, including binaries from releases, but this bug makes it impossible to backup releases at all.

@lunny
Copy link
Member

lunny commented Jan 16, 2024

This bug was introduced by #19125.
Ref: https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481

I think we need a method to not delete all previous releases but also keep better performance.

The bottleneck is upset is very slow and the batch insert is not.
Or maybe we can load all tag names into memory first.

@Jinnrry
Copy link

Jinnrry commented Jan 16, 2024

Also, although the Release list is lost, the uploaded attachment files are not deleted. And every time you upload again, a copy of the attachment will be saved again, and no de-duplication will be done. This had caused me to store 500GB+ of invalid data on my disk. Is there any way I can delete this invalid data now?

@lunny lunny added this to the 1.21.5 milestone Jan 16, 2024
@Jinnrry
Copy link

Jinnrry commented Jan 16, 2024

This bug was introduced by #19125. Ref: https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481

I think we need a method to not delete all previous releases but also keep better performance.

The bottleneck is upset is very slow and the batch insert is not. Or maybe we can load all tag names into memory first.

I'm not familiar with Gitea code. I've looked over the logic of this code and maybe changed this here to if _, err := db.DeleteByBean(ctx, &repo_model.Release{RepoID: repo.ID, IsTag: true}); err ! = nil { and that fixes the bug? I think the Tag data is just expected to be deleted here, right?

@lunny
Copy link
Member

lunny commented Jan 16, 2024

You can fix them with ./gitea doctor storages commands.

Yes, I think you are right. That's why I added this to 1.21.5.

@lunny
Copy link
Member

lunny commented Jan 16, 2024

I sent #28817. It will not remove mirror releases when mirroring.

lunny added a commit that referenced this issue Jan 26, 2024
Fix #22066

# Purpose

This PR fix the releases will be deleted when mirror repository sync the
tags.

# The problem

In the previous implementation of #19125. All releases record in
databases of one mirror repository will be deleted before sync.
Ref:
https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481

# The Pros

This PR introduced a new method which will load all releases from
databases and all tags on git data into memory. And detect which tags
needs to be inserted, which tags need to be updated or deleted. Only
tags releases(IsTag=true) which are not included in git data will be
deleted, only tags which sha1 changed will be updated. So it will not
delete any real releases include drafts.

# The Cons

The drawback is the memory usage will be higher than before if there are
many tags on this repository. This PR defined a special release struct
to reduce columns loaded from database to memory.
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Jan 26, 2024
…a#28817)

Fix go-gitea#22066

# Purpose

This PR fix the releases will be deleted when mirror repository sync the
tags.

# The problem

In the previous implementation of go-gitea#19125. All releases record in
databases of one mirror repository will be deleted before sync.
Ref:
https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481

# The Pros

This PR introduced a new method which will load all releases from
databases and all tags on git data into memory. And detect which tags
needs to be inserted, which tags need to be updated or deleted. Only
tags releases(IsTag=true) which are not included in git data will be
deleted, only tags which sha1 changed will be updated. So it will not
delete any real releases include drafts.

# The Cons

The drawback is the memory usage will be higher than before if there are
many tags on this repository. This PR defined a special release struct
to reduce columns loaded from database to memory.
henrygoodman pushed a commit to henrygoodman/gitea that referenced this issue Jan 31, 2024
…a#28817)

Fix go-gitea#22066

# Purpose

This PR fix the releases will be deleted when mirror repository sync the
tags.

# The problem

In the previous implementation of go-gitea#19125. All releases record in
databases of one mirror repository will be deleted before sync.
Ref:
https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481

# The Pros

This PR introduced a new method which will load all releases from
databases and all tags on git data into memory. And detect which tags
needs to be inserted, which tags need to be updated or deleted. Only
tags releases(IsTag=true) which are not included in git data will be
deleted, only tags which sha1 changed will be updated. So it will not
delete any real releases include drafts.

# The Cons

The drawback is the memory usage will be higher than before if there are
many tags on this repository. This PR defined a special release struct
to reduce columns loaded from database to memory.
lunny added a commit that referenced this issue Jan 31, 2024
…#28939)

Backport #28817 by @lunny

Fix #22066

# Purpose

This PR fix the releases will be deleted when mirror repository sync the
tags.

# The problem

In the previous implementation of #19125. All releases record in
databases of one mirror repository will be deleted before sync.
Ref:
https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481

# The Pros

This PR introduced a new method which will load all releases from
databases and all tags on git data into memory. And detect which tags
needs to be inserted, which tags need to be updated or deleted. Only
tags releases(IsTag=true) which are not included in git data will be
deleted, only tags which sha1 changed will be updated. So it will not
delete any real releases include drafts.

# The Cons

The drawback is the memory usage will be higher than before if there are
many tags on this repository. This PR defined a special release struct
to reduce columns loaded from database to memory.

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
silverwind pushed a commit to silverwind/gitea that referenced this issue Feb 20, 2024
…a#28817)

Fix go-gitea#22066

# Purpose

This PR fix the releases will be deleted when mirror repository sync the
tags.

# The problem

In the previous implementation of go-gitea#19125. All releases record in
databases of one mirror repository will be deleted before sync.
Ref:
https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481

# The Pros

This PR introduced a new method which will load all releases from
databases and all tags on git data into memory. And detect which tags
needs to be inserted, which tags need to be updated or deleted. Only
tags releases(IsTag=true) which are not included in git data will be
deleted, only tags which sha1 changed will be updated. So it will not
delete any real releases include drafts.

# The Cons

The drawback is the memory usage will be higher than before if there are
many tags on this repository. This PR defined a special release struct
to reduce columns loaded from database to memory.
Copy link

Automatically locked because of our CONTRIBUTING guidelines

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants