Skip to content

Swift files can be passed either as file or as form value #34068

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wgr1984
Copy link

@wgr1984 wgr1984 commented Mar 30, 2025

Fix #33990

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 30, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Mar 30, 2025
@wxiaoguang wxiaoguang marked this pull request as draft March 30, 2025 05:04
@KN4CK3R
Copy link
Member

KN4CK3R commented Apr 2, 2025

Alternative fix with minimal changes:

@@ -304,10 +304,18 @@ func UploadPackageFile(ctx *context.Context) {
 
        packageVersion := v.Core().String()
 
-       file, _, err := ctx.Req.FormFile("source-archive")
+       var file io.ReadCloser
+       multipartFile, _, err := ctx.Req.FormFile("source-archive")
        if err != nil {
-               apiError(ctx, http.StatusBadRequest, err)
-               return
+               content := ctx.Req.FormValue("source-archive")
+               if content != "" {
+                       file = io.NopCloser(strings.NewReader(content))
+               } else {
+                       apiError(ctx, http.StatusBadRequest, err)
+                       return
+               }
+       } else {
+               file = multipartFile
        }
        defer file.Close()

+ tests

@hiifong
Copy link
Member

hiifong commented Apr 3, 2025

hi @wgr1984, would you be interested in continuing to complete the pr?

@wgr1984
Copy link
Author

wgr1984 commented Apr 3, 2025 via email

@wgr1984 wgr1984 force-pushed the swift-package-manager-publishing-using-commandline-throws-error branch from a2a92fb to 6ded601 Compare April 6, 2025 19:29
@pull-request-size pull-request-size bot added size/L and removed size/M labels Apr 6, 2025
@wgr1984
Copy link
Author

wgr1984 commented Apr 6, 2025

updated + test. Metadata looks good, too 👍

curl -k --location 'https://127.0.0.1:3000/api/packages/tet/swift/test/TestLib/1.3.19' \
--header 'Accept: application/vnd.swift.registry.v1+json' \
--header 'Authorization: Basic dGV0OmRlZmF1bHQ=' \
--header 'Cookie: _csrf=BuZq7gKCTbJRLox5fIJSVlw_BNI6MTc0Mzk2NDIwODc2MTI2OTAwMA; i_like_gitea=497d7722fdfa170e'

{
   "id":"test.TestLib",
   "version":"1.3.19",
   "resources":[
      {
         "name":"source-archive",
         "type":"application/zip",
         "checksum":"3d4247adb875f627f5afd3ac860ff027ede1bb45f883059d4ceb5a8a025676df"
      }
   ],
   "metadata":{
      "@context":[
         "http://schema.org/"
      ],
      "@type":"SoftwareSourceCode",
      "name":"TestLib",
      "version":"1.3.19",
      "description":"A test Swift package",
      "keywords":[
         "test",
         "swift"
      ],
      "license":"MIT",
      "author":{
         "@type":"Person"
      },
      "programmingLanguage":{
         "@type":"ComputerLanguage",
         "name":"Swift",
         "url":"https://swift.org"
      }
   }
}

image

@lunny lunny added type/bug backport/v1.23 This PR should be backported to Gitea 1.23 labels Apr 6, 2025
@wxiaoguang wxiaoguang added this to the 1.24.0 milestone Apr 7, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 13, 2025
@wxiaoguang wxiaoguang marked this pull request as ready for review April 13, 2025 12:25
@wxiaoguang
Copy link
Contributor

CI failure seems related.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 13, 2025
@hiifong
Copy link
Member

hiifong commented Apr 13, 2025

I was going to run the MySQL tests locally, but very unfortunately I can't.

image

@delvh delvh changed the title Swift Package Manager Publishing using commandline throws error (#33990) Swift source archive can be passed either as file or as form value Apr 13, 2025
@delvh delvh changed the title Swift source archive can be passed either as file or as form value Swift files can be passed either as file or as form value Apr 13, 2025
@github-actions github-actions bot added modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/templates This PR modifies the template files modifies/docs modifies/migrations modifies/internal modifies/dependencies modifies/frontend docs-update-needed The document needs to be updated synchronously labels Apr 13, 2025
@lunny lunny force-pushed the swift-package-manager-publishing-using-commandline-throws-error branch from 914178e to 7101dc2 Compare April 13, 2025 19:24
@github-actions github-actions bot removed modifies/translation modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/templates This PR modifies the template files modifies/docs modifies/migrations modifies/internal modifies/dependencies modifies/frontend docs-update-needed The document needs to be updated synchronously labels Apr 13, 2025
@lunny lunny force-pushed the swift-package-manager-publishing-using-commandline-throws-error branch from 7101dc2 to 7af142a Compare April 13, 2025 19:59
@wxiaoguang
Copy link
Contributor

Need to figure out the root problem and fix.

=== TestPackageSwift/LookupPackageIdentifiers (tests/integration/api_packages_swift_test.go:411)
--- FAIL: TestPackageSwift (0.76s)
    testlogger.go:61: 2025/04/13 23:02:49 modules/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /home/runner/work/gitea/gitea/tests/gitea-lfs-meta
    --- FAIL: TestPackageSwift/UploadMultipart (0.04s)
        testlogger.go:61: 2025/04/13 23:02:50 HTTPRequest [I] router: completed PUT /api/packages/user2/swift/test-scope/test_package/1.0.4 for test-mock:12345, 401 Unauthorized in 1.4ms @ packages/api.go:43(packages.reqPackageAccess)
        testlogger.go:61: 2025/04/13 23:02:50 HTTPRequest [I] router: completed PUT /api/packages/user2/swift/test-scope/test_package/1.0.4 for test-mock:12345, 201 Created in 16.8ms @ swift/swift.go:294(swift.UploadPackageFile)
        api_packages_swift_test.go:248: 
            	Error Trace:	/home/runner/work/gitea/gitea/tests/integration/api_packages_swift_test.go:248
            	Error:      	Not equal: 
            	            	expected: "1.0.4"
            	            	actual  : "1.0.3"
            	            	
            	            	Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -1 +1 @@
            	            	-1.0.4
            	            	+1.0.3
            	Test:       	TestPackageSwift/UploadMultipart
        api_packages_swift_test.go:261: 
            	Error Trace:	/home/runner/work/gitea/gitea/tests/integration/api_packages_swift_test.go:261
            	Error:      	Not equal: 
            	            	expected: "test_package-1.0.4.zip"
            	            	actual  : "test_package-1.0.3.zip"
            	            	
            	            	Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -1 +1 @@
            	            	-test_package-1.0.4.zip
            	            	+test_package-1.0.3.zip
            	Test:       	TestPackageSwift/UploadMultipart
        testlogger.go:61: 2025/04/13 23:02:50 .../packages/packages.go:168:createPackageAndVersion() [E] Error inserting package: package version already exists
        testlogger.go:61: 2025/04/13 23:02:50 HTTPRequest [I] router: completed PUT /api/packages/user2/swift/test-scope/test_package/1.0.4 for test-mock:12345, 409 Conflict in 5.3ms @ swift/swift.go:294(swift.UploadPackageFile)

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

CI fails, need to figure out the root problem and fix.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Apr 14, 2025
@wgr1984
Copy link
Author

wgr1984 commented Apr 14, 2025 via email

@KN4CK3R
Copy link
Member

KN4CK3R commented Apr 14, 2025

Just move the upload test to the bottom or remove the package after uploading.

@wgr1984
Copy link
Author

wgr1984 commented Apr 14, 2025

more fixing the symptom than the issue but sure, will do

@wxiaoguang
Copy link
Contributor

Strange, it doesn't explain why only MySQL fails, other databases succeed ..... anyway we need to make the CI pass to merge .......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v1.23 This PR should be backported to Gitea 1.23 lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code topic/packages type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Swift Package Manager Publishing using commandline throws error
8 participants