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

chore(ci): automatically format code #1035

Merged
merged 12 commits into from
Nov 19, 2023
Merged

chore(ci): automatically format code #1035

merged 12 commits into from
Nov 19, 2023

Conversation

ocavue
Copy link
Sponsor Collaborator

@ocavue ocavue commented Nov 17, 2023

Add a CI pipeline to automatically format code using Prettier and push the formated code to the origin branch. This CI won't push any commit to our main branches (main and `dev).

Copy link

codesandbox bot commented Nov 17, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Nov 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2023 0:40am

@sxzz
Copy link
Collaborator

sxzz commented Nov 18, 2023

We can push a commit into PRs as well

@ocavue
Copy link
Sponsor Collaborator Author

ocavue commented Nov 18, 2023

We can push a commit into PRs as well

Sorry I don't get it. What do you mean by "push a commit into PRs"? The current implementation would already push commits if necessary.

@sxzz
Copy link
Collaborator

sxzz commented Nov 19, 2023

I mean, we can also auto-fix it if the PR is not formatted.

.github/workflows/format.yml Outdated Show resolved Hide resolved
name: Fix

on:
push:
Copy link
Collaborator

Choose a reason for hiding this comment

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

add pull_request:

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

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

I actually don't trigger this workflow for pull_request events intentionally, and that's also the reason why I wrote this workflow in a separate YAML file instead of existed ci.yml, as I want a different workflow trigger for this one.

For pull request events, GitHub actions won't run workflows on the development branch. It would first try to merge the development branch and the main branch, then run workflows on that merged commit. This means (a) we cannot run git push directly, as the upstream if not the development branch, and (b) if the main branch has some newer commit, pushing the formatted code to the development branch would also include these new content. Because of these two reasons, It seems adding pull_request is not a good idea.

My current implementation (i.e. run workflow on the push event) can already fix the PR. This PR itself is an example. See the commit history below:

image

.github/workflows/format.yml Outdated Show resolved Hide resolved
@ocavue ocavue merged commit d8a203c into dev Nov 19, 2023
10 checks passed
@ocavue ocavue deleted the ocavue/prettier-ci branch November 19, 2023 12:54
Copy link

🎉 This PR is included in version 8.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants