actions / actions/toolkit

Relative path does not work, also error throws exception

Open
#1,496 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

Context: @actions/artifact

According to README.md, relative paths for files are supported as well as absolute path. However, when trying to use relative path I kept running into fatal error:

Error: File <file> does not exist

Also, if file is not found, the error is thrown even if I use continueOnError: true which is contrary to the docs:

If set to true and an error is encountered, the failed file will be skipped and ignored and all other queued files will be attempted to be uploaded.

I've tried try...catch but that did not work either.

I believe the error is due to how path is being checked:

https://github.com/actions/toolkit/blob/c9dab8c79daa06e0897ededaf7de9c351d22fec3/packages/artifact/src/internal/upload/upload-zip-specification.ts#L41-L44

https://github.com/actions/toolkit/blob/c9dab8c79daa06e0897ededaf7de9c351d22fec3/packages/artifact/src/internal/upload/upload-zip-specification.ts#L77-L80

As you can see, rootDirectory is not concatenated with filesToZip.

To Reproduce

const client = artifact.create();
const filePath = path.resolve(__dirname, 'file');
this.spawnSync.call('touch', [filePath]);
fs.openSync(filePath, 'a');
this.spawnSync.call('ls', ['-l', __dirname]);
console.log(fs.existsSync(filePath));
client.uploadArtifact('file-abs-path', [filePath], __dirname, { 
continueOnError: true }); // works
client.uploadArtifact('file-rel-path', ['file'], __dirname, { 
continueOnError: true }); // does not work, throws error

Expected behavior

  • relative path to be functional
  • continueOnError: true to not throw error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/artifact/src/internal/upload/upload-zip-specification.ts at the referenced path checks, then reproduce the behavior with client.uploadArtifact using a relative file and continueOnError: true. Done means relative paths upload successfully and missing files are skipped without throwing when continueOnError is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.