Skip to content

Format Code with Prettier GitHub Action Automate code formatting in your GitHub Actions workflows using Prettier. Ensure consistent code style across your projects effortlessly.

License

Notifications You must be signed in to change notification settings

adhikareeprayush/Format-Code

Repository files navigation

GitHub Action: Format Code with Prettier

GitHub Marketplace Version GitHub Releases GitHub Marketplace Stars GitHub License

Automatically format your code with Prettier in GitHub Actions workflows.

Features

  • Format code using Prettier in GitHub Actions workflows.
  • Customizable Prettier configuration using .prettierrc or prettier.config.js.
  • Supports formatting JavaScript, TypeScript, CSS, JSON, YAML, and more.

Usage

To use this GitHub Action in your workflow, add a step like the following:

- name: Format Code with Prettier
  uses: adhikareeprayush/Format-Code@v1

You can configure additional options for Prettier by creating a .prettierrc or prettier.config.js file in your repository.

Inputs

  • path: The file or directory path to format (default: .).
  • prettier-version: The version of Prettier to use (default: latest).
- name: Format Code with Prettier
  uses: adhikareeprayush/format-code@v1
  with:
    path: 'src/'
    prettier-version: '2.7.1'

Outputs

This action does not provide any outputs.

Example Workflow

Here's an example workflow that formats code using Prettier:

name: Format Code

on: [push, pull_request]

jobs:
  format:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'

      - name: Install dependencies
        run: npm install

      - name: Format Code with Prettier
        uses: [email protected]/format-code@v1
        with:
          path: 'src/'
          prettier-version: '2.7.1'

      - name: Commit formatted code
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
          git add .
          git commit -m 'Format code with Prettier'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        continue-on-error: true

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support or questions, please open an issue in the GitHub repository or contact [email protected].

About

Format Code with Prettier GitHub Action Automate code formatting in your GitHub Actions workflows using Prettier. Ensure consistent code style across your projects effortlessly.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published