Feature code style check GitHub Action #1
Workflow file for this run
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: code-style-check | |
on: pull_request | |
jobs: | |
get-changed-files: | |
runs-on: ubuntu-latest | |
outputs: | |
cs_files: ${{ steps.cs.outputs.cs_files }} | |
js_css_files: ${{ steps.js_css.outputs.js_css_files }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Get diff | |
run: | | |
{ | |
echo 'diff<<EOF' | |
git diff origin/main --name-status | |
echo EOF | |
} >> "$GITHUB_ENV" | |
- name: Assign C# files to output | |
id: cs | |
run: | | |
{ | |
echo 'cs_files<<EOF' | |
echo "$diff" | grep -E "^[ACMR][0-9]{0,3}[[:space:]]+.+\.cs$" | sed -E "s/.*[[:space:]]+//" | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
- name: Assign JS/CSS files to output | |
id: js_css | |
run: | | |
{ | |
echo 'js_css_files<<EOF' | |
echo "$diff" | grep -E "^[ACMR][0-9]{0,3}[[:space:]]+.+\.(js|css)$" | sed -E "s/.*[[:space:]]+//" | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
run-dotnet-format: | |
if: needs.get-changed-files.outputs.cs_files != '' | |
runs-on: ubuntu-latest | |
needs: get-changed-files | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: dotnet format | |
run: dotnet format style src/TagzApp.sln --verbosity detailed --verify-no-changes --include ${{ needs.get-changed-files.outputs.cs_files }} | |
run-prettier: | |
if: needs.get-changed-files.outputs.js_css_files != '' | |
runs-on: ubuntu-latest | |
needs: get-changed-files | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: prettier | |
uses: creyD/prettier_action@v4.3 | |
with: | |
prettier_options: --write ${{ needs.get-changed-files.outputs.js_css_files }} | |
dry: true |