Skip to content

Commit ec0c682

Browse files
Fix/upload artifact error windows (#27802)
From issue #27314 When act_runner in `host` mode on Windows. `upload_artifact@v3` actions use `path.join` to generate `itemPath` params when uploading artifact chunk. `itemPath` is encoded as `${artifact_name}\${artifact_path}`. <del>It's twice query escaped from ${artifact_name}/${artifact_path} that joined by Windows slash \.</del> **So we need convert Windows slash to linux**. In #27314, runner shows logs from `upload_artifact@v3` like with `%255C`: ``` [artifact-cases/test-artifact-cases] | ::error::Unexpected response. Unable to upload chunk to http://192.168.31.230:3000/api/actions_pipeline/_apis/pipelines/workflows/6/artifacts/34d628a422db9367c869d3fb36be81f5/upload?itemPath=more-files%255Css.json ``` But in gitea server at the same time, But shows `%5C` ``` 2023/10/27 19:29:51 ...eb/routing/logger.go:102:func1() [I] router: completed PUT /api/actions_pipeline/_apis/pipelines/workflows/6/artifacts/34d628a422db9367c869d3fb36be81f5/upload?itemPath=more-files%5Css.json for 192.168.31.230:55340, 400 Bad Request in 17.6ms @ <autogenerated>:1(actions.artifactRoutes.uploadArtifact-fm) ``` I found `%255C` is escaped by `https://github.com/actions/upload-artifact/blob/main/dist/index.js#L2329`. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent e5f19dd commit ec0c682

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

routers/api/actions/artifacts_utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func validateArtifactHash(ctx *ArtifactContext, artifactName string) bool {
5858
func parseArtifactItemPath(ctx *ArtifactContext) (string, string, bool) {
5959
// itemPath is generated from upload-artifact action
6060
// it's formatted as {artifact_name}/{artfict_path_in_runner}
61-
itemPath := util.PathJoinRel(ctx.Req.URL.Query().Get("itemPath"))
61+
// act_runner in host mode on Windows, itemPath is joined by Windows slash '\'
62+
itemPath := util.PathJoinRelX(ctx.Req.URL.Query().Get("itemPath"))
6263
artifactName := strings.Split(itemPath, "/")[0]
6364
artifactPath := strings.TrimPrefix(itemPath, artifactName+"/")
6465
if !validateArtifactHash(ctx, artifactName) {

0 commit comments

Comments
 (0)