Skip to content

Improve string split to handle whitespace - #343

Merged
dhadka merged 2 commits into
masterfrom
improve-string-split
Jun 2, 2020
Merged

dhadka merged 2 commits into
masterfrom
improve-string-split

Conversation

@dhadka

@dhadka dhadka commented Jun 2, 2020 •

Copy link
Copy Markdown
Contributor

Currently, the following two cache definitions result in two separate caches:

- uses: actions/cache@v2
  with:
    path: |
      ~/cache
      !~/cache/exclude
    key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- uses: actions/cache@v2
  with:
    path: |
      ~/cache 
      !~/cache/exclude
    key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

Don't see any difference? There's an extra whitespace in one. This results in different version hashes, which ends up creating two different caches.

This PR calls trim() on each entry in the path and restore-keys to remove any leading and trailing whitespace. Additionally, this moves the split logic to a separate method and adds unit test coverage.

@joshmgross joshmgross left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@joshmgross
joshmgross self-requested a review June 2, 2020 16:03

@joshmgross joshmgross left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Comment thread dist/save/index.js
return core
.getInput(name, options)
.split("\n")
.map(s => s.trim())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suppose this gets rid of the "\r" on Windows as well, which I believe was the issue observed in #330 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I also added a test for this case.

@dhadka
dhadka force-pushed the improve-string-split branch from 5aa5bf1 to 1c50d1d Compare June 2, 2020 19:19

@mzabaluev mzabaluev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The changes look good.
To further improve robustness, I think, the following normalizations would be useful:

  • Remove any whitespace between ! and the path;
  • Sort the resulting entries.

@dhadka
dhadka force-pushed the improve-string-split branch from 1c50d1d to d60d2be Compare June 2, 2020 22:07
@dhadka
dhadka merged commit ff937cc into master Jun 2, 2020
@dhadka

dhadka commented Jun 2, 2020

Copy link
Copy Markdown
Contributor Author

@mzabaluev Those are both good suggestions. I've filed an enhancement here - #345.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants