deskflow/.github/actions/lint-error/action.yml
2024-09-23 17:12:07 +01:00

85 lines
2.2 KiB
YAML

name: "Lint error"
description: "Checks for lint errors and posts a helpful comment"
inputs:
format-command:
description: "The command to run to fix lint errors"
required: true
format-tool:
description: "The name of the linting tool"
required: true
runs:
using: "composite"
steps:
- name: Run format command
run: ${{ inputs.format-command }}
shell: bash
- name: Find changes
id: changes
run: |
file=${{ inputs.format-tool }}.diff
diff=$(git diff | tee $file)
if [ -z "$diff" ]; then
echo "No changes detected"
exit 0
fi
echo "file=$file" >> $GITHUB_OUTPUT
{
echo "diff<<EOF"
cat $file
echo "EOF"
} >> $GITHUB_OUTPUT
shell: bash
- name: Upload to GitHub
id: upload
if: steps.changes.outputs.diff
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.format-tool }}-diff
path: ${{ steps.changes.outputs.file }}
if-no-files-found: error
- name: Set summary
id: summary
if: steps.changes.outputs.diff
run: |
code_block="\`\`\`"
summary=$(cat<<EOF
❌ \`${{ inputs.format-tool }}\`: It looks like your changes don't match our code style.
🛠️ Please either run \`${{ inputs.format-command }}\` or apply this patch with \`git apply\`:
[\`${{ steps.changes.outputs.file }}\`](${{ steps.upload.outputs.artifact-url }})
$code_block diff
${{ steps.changes.outputs.diff }}
$code_block
EOF
)
echo "$summary" >> $GITHUB_STEP_SUMMARY
file="ci_summary.md"
echo "❌🛠️ \`${{ inputs.format-tool }}\`: Lint errors, fix available." >> $file
echo "file=$file" >> $GITHUB_OUTPUT
shell: bash
- name: Upload CI summary as artifact
if: steps.summary.outputs.file
uses: actions/upload-artifact@v4
with:
name: summary-${{ inputs.format-tool }}
path: ${{ steps.summary.outputs.file }}
if-no-files-found: error
- name: Fail if diff exists
if: steps.changes.outputs.diff
run: exit 1
shell: bash