![]() ![]() ![]() Great! So I now have Laravel Pint running and linting my code and then push it back to my branch so I can also see a diff with the changes and can now make sure that all of the code in my main branch is following laravel Pint rules. name : Commit changes uses : stefanzweifel / git - auto - commit - action v4 with : commit_message : Fixing styling skip_fetch : true In order for me to achieve such behaviour I also have to use a git-auto-commit action. What we really want is Github to also make the suggested changes and push them automatically to our branch as a new commit. So far so good! However, the action above will only notify us about potential code formating issues. The pint.json file in the root of my laravel project will be used for configuration during the run of the Action. I have personally been using Github actions with aglipanci/laravel-pint-action and it works great! name : Check & fix styling on : jobs : phplint : name : Laravel Pint runs - on : ubuntu - latest steps : - uses : actions / checkout v3 with : fetch - depth : 2 - name : Laravel Pint uses : aglipanci / laravel - pint - action 2.0.0 with : preset : laravel configPath : "pint.json" pintVersion : 1.2 Inside the workflows folder is where I place my actions as. github/workflows/pint.yml at the top of my repo. The last thing that we need to do is commit and push this file to our repository, and the next time anyone makes a pull request to our repo on the dev branch, we can see that a new action is running which will perform all of the specified tasks, format the files and commit to our repository, and along with that, we can also see what files this action has changed.Instead of always running PHP CS Fixer or Laravel Pint locally, it might be a good idea to set up a GitHub action, that will reformat the code in Github following the laravel Pint formatting rules after each push. And then, click on Generate TokenĬopy the generated token and head over to the Settings page of your Repository, inside the Secrets tab, click on the Actions link.Ĭlick on New Repository Secret, give the name of the secret as PERSONAL_TOKEN and paste the copied secret token value.Īnd now that everything is set up and ready, the above code will use that auto-commit-action and using that PERSONAL_TOKEN, commit to our repo with the message applied in the commit_message prefix. So, head over to this link (make sure you're logged in to Github), to create a new token, give it a proper name, and make sure to give repo and workflow scopes, select expiration date as per your need. It does perform all the tasks but how do we reflect those changes on our repo? So, to make those changes to our repo, we will be using an auto-commit action called stefanzweifel/git-auto-commit-action and v4 is the latest at the time of writing this article.īut, before using this action, we need to set up a few stuff. Until this time, we have installed packages and formatted files on the virtual system. GITHUB_TOKEN: $Īnd finally, comes the main part. ![]() So, let's take a look at the workflow and I'll explain each section as we go along: Once we've installed the package, the next thing is to define the workflow. In this article, we will be looking at how we can format our code with a recently released formatter called Laravel Pintwhich will automatically format our code on every pull request to a certain branch.įor this workflow to work, we first need to install Laravel Pint, and we can install it with a composer command like so: And, one more important aspect that needs to have consistency is code formatting and implementation of fixed styling rules. So, consistency and proper workflow are really important while working in a team of multiple developers. Whether it is about the authority to review and merge the PRs, project planning, or providing access to the server. While working on a team consisting of multiple developers, it's really important to have a predefined set of rules about different aspects of the project. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |