Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

GitHub Action for dotnet-format

CICodeQL

Run dotnet-format v3 as part of your workflow to report formatting errors or auto fix violations as part of your pull request workflow.

Usage

Running on push.

name: Format check on pushon: pushjobs:
dotnet-format:
runs-on: ubuntu-lateststeps:
- name: Checkout repouses: actions/checkout@v2
- name: Add dotnet-format problem matcheruses: xt0rted/dotnet-format-problem-matcher@v1
- name: Restore dotnet toolsuses: xt0rted/dotnet-tool-restore@v1
- name: Run dotnet formatuses: xt0rted/dotnet-format@v1

Running on pull_request.

name: Format check on pull requeston: pull_requestjobs:
dotnet-format:
runs-on: ubuntu-lateststeps:
- name: Checkout repouses: actions/checkout@v2
- name: Add dotnet-format problem matcheruses: xt0rted/dotnet-format-problem-matcher@v1
- name: Restore dotnet toolsuses: xt0rted/dotnet-tool-restore@v1
- name: Run dotnet formatuses: xt0rted/dotnet-format@v1with:
only-changed-files: "true"

Running on demand by pull request comment, triggered by the text /dotnet format.

ℹ The provided GITHUB_TOKEN will not trigger additional workflows. To push fixes back to the pull request branch you'll need to setup a secret with a Personal Access Token that has the repo scope.

name: Format on slash commandon:
issue_comment:
types: createdjobs:
dotnet-format:
runs-on: ubuntu-lateststeps:
- name: Check for commandid: commanduses: xt0rted/slash-command-action@v1continue-on-error: truewith:
command: dotnetreaction-type: "eyes"
- name: Get branch infoif: steps.command.outputs.command-nameid: comment-branchuses: xt0rted/pull-request-comment-branch@v1with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repoif: steps.command.outputs.command-nameuses: actions/checkout@v2with:
ref: ${{ steps.comment-branch.outputs.ref }}persist-credentials: false
- name: Restore dotnet toolsif: steps.command.outputs.command-nameuses: xt0rted/dotnet-tool-restore@v1
- name: Run dotnet formatif: steps.command.outputs.command-name && steps.command.outputs.command-arguments == 'format'id: formatuses: xt0rted/dotnet-format@v1with:
action: "fix"only-changed-files: true
- name: Commit filesif: steps.command.outputs.command-name && steps.command.outputs.command-arguments == 'format' && steps.format.outputs.has-changes == 'true'run: | git config --local user.name "github-actions[bot]" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" git commit -a -m 'Automated dotnet-format update Co-authored-by: ${{ github.event.comment.user.login }} <${{ github.event.comment.user.id }}+${{ github.event.comment.user.login }}@users.noreply.github.com>' - name: Push changesif: steps.command.outputs.command-name && steps.command.outputs.command-arguments == 'format' && steps.format.outputs.has-changes == 'true'uses: ad-m/github-push-action@v0.5.0with:
branch: ${{ steps.comment-branch.outputs.ref }}github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

Token Permissions

If your repository is using token permissions, and you want to check only changed files, you'll need to set pull-request: read on either the workflow or the job.

Workflow Config

on: pull_requestpermissions:
pull-requests: readjobs:
dotnet-format:
runs-on: ubuntu-lateststeps:
- name: Run dotnet formatuses: xt0rted/dotnet-format@v1with:
only-changed-files: "true"

Job Config

on: pull_requestjobs:
dotnet-format:
runs-on: ubuntu-latestpermissions:
pull-requests: readsteps:
- name: Run dotnet formatuses: xt0rted/dotnet-format@v1with:
only-changed-files: "true"

Options

Required

NameAllowed valuesDescription
repo-tokenGITHUB_TOKEN (default) or PATGITHUB_TOKEN token or a repo scoped PAT.
version3 (default)Version of dotnet-format to use.
actioncheck (default), fixPrimary action dotnet-format should perform.

Optional

NameAllowed valuesDescription
only-changed-filestrue, false (default)Only changed files in the current pull request should be formatted.
fail-fasttrue (default), falseThe job should fail if there's a formatting error. Only used with the check action.

Outputs

NameDescription
has-changesIf any files were found to have violations or had fixes applied. Will be a string value of true or false.

License

The scripts and documentation in this project are released under the MIT License

About

A GitHub Action to run dotnet-format as part of your workflow

Topics

Resources

Stars

35 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages