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

Theme check action fails if no lintable files were changed in a pull request #28

Open
MauriceArikoglu opened this issue May 17, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@MauriceArikoglu
Copy link

https://github.com/Shopify/theme-check-action/blob/fc581c95120e0db82b86ae6fa8c507cba7648aba/entrypoint.sh#LL62C1-L63C8

If no lintable files are found the exit code from the theme-check call causes the action to fail, even though no errors and no warnings were found.

@MauriceArikoglu
Copy link
Author

Bildschirm­foto 2023-05-24 um 15 42 19

@snacsnoc
Copy link
Contributor

snacsnoc commented Jan 5, 2024

@MauriceArikoglu I was able to debug this a bit more and went down a rabbit hole. It seems theme-check returns a few 'offences' when no lintable files are found. Since the theme-check action runs on changed files (see https://github.com/Shopify/theme-check-action/blob/main/entrypoint.sh#L67), the default theme-check categories attempt to run. The changed files are saved to /tmp/diff.log and then the files are added to the themePath` which theme-check will run on (see https://github.com/Shopify/theme-check-action/blob/main/index.js#L37). So, getting to the actual issue, theme-check returns:

No theme files found.

which results in exit code 1, indicating a fail even though that's not necessarily true (in some cases).
theme-check will exit when no matching file/directory patterns are found (see https://github.com/Shopify/theme-check/blob/main/lib/theme_check/cli.rb#L195), which is defined here: https://github.com/Shopify/theme-check/blob/main/lib/theme_check/theme.rb#L55

So in my case, I'm updating a .yml file and theme-check is failing because there are no JSON, liquid files and the assets/ dir doesn't exist. This all makes sense, and defining a solution for non-lintable files is a bit more straightforward now.

I was able to 'solve' this by capturing the output of theme-check and checking for No theme files found. and returning 0 as the code.

Example (from

run theme-check $flags -o json "$theme_root" > /tmp/results.json
):

# Capture both stdout and stderr from theme-check
output=$(run theme-check $flags -o json "$theme_root" 2>&1)
code=$?

# Check if 'No theme files found.' is in the output
if echo "$output" | grep -q "No theme files found."; then
    echo "No theme files found, but proceeding without error."
    code=0
fi

# Output the results to a file
echo "$output" > /tmp/results.json

It's not the most elegant solution, but this resolves the issue. Open to discussion on this, thanks!

@MauriceArikoglu
Copy link
Author

@snacsnoc Thank you Easton, for digging into this and providing a workaround. I came to a similar conclusion with the changed files, but did not dig deep enough to find a suitable workaround.

Would be nice to add this to a caveats section or refactor the action appropriately.

Have a good day and best wishes for your 2024.

@mgmanzella mgmanzella added the bug Something isn't working label Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants