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

Update prettier entrypoint.sh to consider dry run #8

Merged
merged 2 commits into from
Apr 24, 2024
Merged

Conversation

Anu48
Copy link
Contributor

@Anu48 Anu48 commented Apr 23, 2024

When dry-run is set to true and we use the --write flag, we expect to see what files we'll need to reformat without pushing to remote. However, this requires us to commit the updated changes caused by prettier. Previously, the placement of the dry run logic was done before committing the formatted files, resulting to us not seeing the expected files format. And only using the '--write' flag will not result to a failure even if there are files that requires formatting.

By moving the logic after committing the prettier files, it will show us the comparison between two files, without pushing to remote (given that we use dry flag to true). The dry run will exit with code 1 if there are changes done to the files.

This is the following result using the --write flag and dry set to true; when encountering files that need formatting:
https://github.com/GarnerCorp/gala-testing/actions/runs/8802209844

Versus when we don't have any files to format:
https://github.com/GarnerCorp/gala-testing/actions/runs/8802264992

@Anu48 Anu48 force-pushed the update-prettier branch 3 times, most recently from 80a727f to 74a9c2d Compare April 23, 2024 14:41
@Anu48 Anu48 requested a review from jsoref April 23, 2024 14:41
@Anu48 Anu48 marked this pull request as ready for review April 23, 2024 14:41
@Anu48 Anu48 changed the title Update Prettier Update prettier entrypoint.sh to consider dry run Apr 23, 2024
@Anu48 Anu48 requested a review from lzm0 April 24, 2024 15:48
Comment on lines 254 to 268

# case when --write is used with dry-run so if something is unpretty there will always have _git_changed
if _dry_run; then
summarize_changes 'Unpretty Files Changes'
echo "Finishing dry-run. Exiting before committing." | tee -a "$GITHUB_STEP_SUMMARY"
exit 1
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have two git push in this workflow, I think it makes sense to extract the dry-run check into a function and call it immediately before each git push.

@Anu48 Anu48 force-pushed the update-prettier branch 5 times, most recently from 2cd4b3e to af98583 Compare April 24, 2024 17:48
Copy link
Contributor

@jsoref jsoref left a comment

Choose a reason for hiding this comment

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

description: Running the script in dry mode just shows whether there are files that should be prettified or not

Should be changed to clarify that the changes that are made will be included in the github job summary.

Comment on lines 173 to 178
# case when --write is used with dry-run so if something is unpretty there will always have _git_changed
if _dry_run; then
summarize_changes 'Unpretty Files Changes'
echo "Finishing dry-run. Exiting before committing." | tee -a "$GITHUB_STEP_SUMMARY"
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

un-indent by 2 spaces

When dry-run is set to true and we use the --write flag, we expect to
see what files we'll need to reformat without pushing to remote.
However, this requires us to commit the updated changes caused by
prettier. Previously, the placement of the dry run logic was done before
committing the formatted files, resulting to us not seeing the expected
files format. And only using the '--write' flag will not result to a
failure even if there are files that requires formatting.

By moving the logic after committing the prettier files, it will show us
the comparison between two files, without pushing to remote
(given that we use dry flag to true).
@Anu48 Anu48 force-pushed the update-prettier branch 2 times, most recently from b8ac09f to 67de674 Compare April 24, 2024 18:09
@Anu48 Anu48 requested review from jsoref and lzm0 April 24, 2024 18:09
@@ -39,7 +39,7 @@ inputs:
required: false
default: "**"
dry:
description: Running the script in dry mode just shows whether there are files that should be prettified or not
description: Running the script in dry mode just shows whether there are files that should be prettified or not and changes made by prettier will be displayed in github job summary
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: Running the script in dry mode just shows whether there are files that should be prettified or not and changes made by prettier will be displayed in github job summary
description: Run prettier in dry-run mode. Display which files are/aren't prettied and changes made by prettier in the GitHub job summary

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be prettified?

Copy link
Contributor

@jsoref jsoref left a comment

Choose a reason for hiding this comment

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

@lzm0: how about this?

@@ -39,7 +39,7 @@ inputs:
required: false
default: "**"
dry:
description: Running the script in dry mode just shows whether there are files that should be prettified or not
description: Run prettier in dry-run mode. Display which files are/aren't prettied and changes made by prettier in the GitHub job summary
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: Run prettier in dry-run mode. Display which files are/aren't prettied and changes made by prettier in the GitHub job summary
description: Run prettier in dry-run mode. Display which files are/aren't pretty and changes made by prettier (to make them pretty) in the GitHub job summary

@Anu48 Anu48 merged commit 1b90419 into main Apr 24, 2024
7 checks passed
@Anu48 Anu48 deleted the update-prettier branch April 24, 2024 18:30
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.

None yet

3 participants