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

Action artifact upload from Windows act_runner results in HTTP 400 error #27314

Closed
s-ludwig opened this issue Sep 27, 2023 · 3 comments
Closed
Assignees
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug

Comments

@s-ludwig
Copy link

Description

The actions/upload-artifact@v3 action (or the actions toolkit more specifically) apparently uses path.join to generate the artifact file names, resulting in a backslash character being inserted between the name and the file name/path if the workflow runs on Windows. The upload then produces an error status similar to this on the server:

::error::Unexpected response. Unable to upload chunk to http://xyz.org/api/actions_pipeline/_apis/pipelines/workflows/53/artifacts/b3900898524801ca942773cfd2301589/upload?itemPath=library-windows-x86_64%255CFreeImageLib.pdb
##### Begin Diagnostic HTTP information #####
Status Code: 400
Status Message: Bad Request
Header Information: {
  "server": "nginx",
  "date": "Wed, 27 Sep 2023 15:11:51 GMT",
  "content-type": "text/plain; charset=utf-8",
  "content-length": "22",
  "connection": "keep-alive",
  "x-content-type-options": "nosniff"
}
###### End Diagnostic HTTP information ######
::warning::Aborting upload for C:\Users\gitlab3\act_builds\e616ea9d8027ca3a\hostexecutor\Source\FreeImageLib\x64\Release\FreeImageLib.pdb due to failure
::error::aborting artifact upload

Gitea Version

1.21

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.34.1

Operating System

Linux

How are you running Gitea?

Using the official download binary and using act_runner 0.2.6 on Windows.

Database

MySQL/MariaDB

@Zettat123 Zettat123 added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Oct 12, 2023
@psaintmalo
Copy link

psaintmalo commented Oct 13, 2023

Can confirm the same issue happening to me with 1.21rc1 and the 0.2.6 action runner binaries.
This is the upload actions:

     - name: Upload Action Artifact
         uses: actions/upload-artifact@v3
         with:
           name: program_${{ runner.OS }}_${{ matrix.target }}.exe
           path: target/${{ matrix.target }}/release/program.exe

Works fine with the linux action runner but wont upload with the windows action runner.
Action runner is being executed in Ghost Spectre Windows 10 22H2.

@psaintmalo
Copy link

psaintmalo commented Oct 14, 2023

Looking further into the code myself, the backslash that is being inserted might be from safeResolve function used in netkos/act/pkg/artifacts/server.go.

return filepath.Join(baseDir, filepath.Clean(filepath.Join(string(os.PathSeparator), relPath)))

The safeResolve function is then used for the uploads function, which forms part of the Serve function.

The nektos/act/pkg/artifacts is being imported by act_runner in exec.go which then uses the Serve function.

As safeResolves uses the os.PathSeparator, it would default to backslash instead of forward slash for Windows.

Act_runner issue #375.

@fuxiaohei fuxiaohei self-assigned this Oct 26, 2023
lunny pushed a commit that referenced this issue Oct 30, 2023
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 <wxiaoguang@gmail.com>
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Oct 30, 2023
From issue go-gitea#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 go-gitea#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 <wxiaoguang@gmail.com>
@fuxiaohei
Copy link
Contributor

Fixed in #27840

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Projects
None yet
Development

No branches or pull requests

4 participants