prettier test #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Prettier Auto-Format | |
on: | |
push: | |
branches: | |
- feat/add-prettier-format | |
jobs: | |
prettier: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Full Clone Repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Install Prettier | |
run: npm install prettier --global | |
- name: Get Previous Commit | |
id: previous-commit | |
run: | | |
previous_commit=$(git log --skip 1 -n 1 --pretty=format:"%H") | |
echo "PREVIOUS_COMMIT=$previous_commit" >> $GITHUB_ENV | |
- name: Get Modified Files | |
id: modified-files | |
run: | | |
previous_commit=${{ env.PREVIOUS_COMMIT }} | |
modified_files=$(git diff --name-only $previous_commit ${{ github.sha }}) | |
echo "MODIFIED_FILES=\"$modified_files\"" >> $GITHUB_ENV | |
- name: Format Modified Files | |
if: ${{ env.MODIFIED_FILES != '' }} | |
run: | | |
modified_files=${{ env.MODIFIED_FILES }} | |
prettier --write $modified_files | |
- name: Commit Changes | |
if: ${{ env.MODIFIED_FILES != '' }} | |
run: | | |
git config --global user.name "Whisker17" | |
git config --global user.email "[email protected]" | |
git commit -m "Auto-format code with Prettier [skip ci]" --amend --no-edit | |
- name: Push Changes | |
if: ${{ env.MODIFIED_FILES != '' }} | |
run: | | |
branch_name=${{ github.ref }} | |
git push origin $branch_name --force-with-lease |