loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'fix(cmd): actions artifacts cannot be migrated' (#4085) from earl-warren/forgejo:wip-migration-artifacts into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4085
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>

+84 -10
+16 -2
cmd/migrate_storage.go
··· 5 5 6 6 import ( 7 7 "context" 8 + "errors" 8 9 "fmt" 10 + "io/fs" 9 11 "strings" 10 12 11 13 actions_model "code.gitea.io/gitea/models/actions" ··· 162 164 163 165 func migrateActionsArtifacts(ctx context.Context, dstStorage storage.ObjectStorage) error { 164 166 return db.Iterate(ctx, nil, func(ctx context.Context, artifact *actions_model.ActionArtifact) error { 165 - _, err := storage.Copy(dstStorage, artifact.ArtifactPath, storage.ActionsArtifacts, artifact.ArtifactPath) 166 - return err 167 + if artifact.Status == int64(actions_model.ArtifactStatusExpired) { 168 + return nil 169 + } 170 + 171 + _, err := storage.Copy(dstStorage, artifact.StoragePath, storage.ActionsArtifacts, artifact.StoragePath) 172 + if err != nil { 173 + if errors.Is(err, fs.ErrNotExist) { 174 + log.Warn("ignored: actions artifact %s exists in the database but not in storage", artifact.StoragePath) 175 + return nil 176 + } 177 + return err 178 + } 179 + 180 + return nil 167 181 }) 168 182 } 169 183
+67 -8
cmd/migrate_storage_test.go
··· 5 5 6 6 import ( 7 7 "context" 8 + "io" 8 9 "os" 9 10 "strings" 10 11 "testing" 11 12 13 + "code.gitea.io/gitea/models/actions" 12 14 "code.gitea.io/gitea/models/db" 13 15 "code.gitea.io/gitea/models/packages" 14 16 "code.gitea.io/gitea/models/unittest" ··· 16 18 packages_module "code.gitea.io/gitea/modules/packages" 17 19 "code.gitea.io/gitea/modules/setting" 18 20 "code.gitea.io/gitea/modules/storage" 21 + "code.gitea.io/gitea/modules/test" 19 22 packages_service "code.gitea.io/gitea/services/packages" 20 23 21 24 "github.com/stretchr/testify/assert" 25 + "github.com/stretchr/testify/require" 22 26 ) 27 + 28 + func createLocalStorage(t *testing.T) (storage.ObjectStorage, string) { 29 + t.Helper() 30 + 31 + p := t.TempDir() 32 + 33 + storage, err := storage.NewLocalStorage( 34 + context.Background(), 35 + &setting.Storage{ 36 + Path: p, 37 + }) 38 + require.NoError(t, err) 39 + 40 + return storage, p 41 + } 23 42 24 43 func TestMigratePackages(t *testing.T) { 25 44 assert.NoError(t, unittest.PrepareTestDatabase()) ··· 55 74 56 75 ctx := context.Background() 57 76 58 - p := t.TempDir() 59 - 60 - dstStorage, err := storage.NewLocalStorage( 61 - ctx, 62 - &setting.Storage{ 63 - Path: p, 64 - }) 65 - assert.NoError(t, err) 77 + dstStorage, p := createLocalStorage(t) 66 78 67 79 err = migratePackages(ctx, dstStorage) 68 80 assert.NoError(t, err) ··· 73 85 assert.EqualValues(t, "01", entries[0].Name()) 74 86 assert.EqualValues(t, "tmp", entries[1].Name()) 75 87 } 88 + 89 + func TestMigrateActionsArtifacts(t *testing.T) { 90 + assert.NoError(t, unittest.PrepareTestDatabase()) 91 + 92 + srcStorage, _ := createLocalStorage(t) 93 + defer test.MockVariableValue(&storage.ActionsArtifacts, srcStorage)() 94 + id := int64(0) 95 + 96 + addArtifact := func(storagePath string, status actions.ArtifactStatus) { 97 + id++ 98 + artifact := &actions.ActionArtifact{ 99 + ID: id, 100 + ArtifactName: storagePath, 101 + StoragePath: storagePath, 102 + Status: int64(status), 103 + } 104 + _, err := db.GetEngine(db.DefaultContext).Insert(artifact) 105 + require.NoError(t, err) 106 + srcStorage.Save(storagePath, strings.NewReader(storagePath), -1) 107 + } 108 + 109 + exists := "/exists" 110 + addArtifact(exists, actions.ArtifactStatusUploadConfirmed) 111 + 112 + expired := "/expired" 113 + addArtifact(expired, actions.ArtifactStatusExpired) 114 + 115 + notFound := "/notfound" 116 + addArtifact(notFound, actions.ArtifactStatusUploadConfirmed) 117 + srcStorage.Delete(notFound) 118 + 119 + dstStorage, _ := createLocalStorage(t) 120 + 121 + assert.NoError(t, migrateActionsArtifacts(db.DefaultContext, dstStorage)) 122 + 123 + object, err := dstStorage.Open(exists) 124 + assert.NoError(t, err) 125 + buf, err := io.ReadAll(object) 126 + require.NoError(t, err) 127 + assert.Equal(t, exists, string(buf)) 128 + 129 + _, err = dstStorage.Stat(expired) 130 + assert.Error(t, err) 131 + 132 + _, err = dstStorage.Stat(notFound) 133 + assert.Error(t, err) 134 + }
+1
release-notes/8.0.0/fix/4085.md
··· 1 + - `forgejo migrate-storage --type actions-artifacts` always fails because it picks the wrong path