Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/actions/code-style/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Code Style"
description: "Run code-style checks/fixes: formatting, headers, etc."
inputs:
mode:
description: "Operation mode: fix or check"
required: false
default: "check"
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run dotnet-format
uses: xt0rted/dotnet-format@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
action: ${{ inputs.mode }}
only-changed-files: true
- name: Process C# file headers
uses: ./.github/actions/code-style/header-fixer
with:
mode: ${{ inputs.mode }}
- name: Process trailing whitespace
uses: ./.github/actions/code-style/trailing-whitespace
with:
mode: ${{ inputs.mode }}
- name: Process using directives
uses: ./.github/actions/code-style/using-sorter
with:
mode: ${{ inputs.mode }}
- name: Commit & push changes
if: ${{ inputs.mode == 'fix' }}
shell: bash
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git add .
git diff --quiet || (git commit -m "chore: automatically fix code style" && git push)
58 changes: 58 additions & 0 deletions .github/actions/code-style/header-fixer/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "Header Fixer"
description: "Check or fix C# file headers to match .editorconfig header template"
inputs:
mode:
description: "Operation mode: fix or check"
required: false
default: "check"
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Process C# file headers
if: always()
shell: bash
run: |
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- '*.cs')
ERR=0
for file in $FILES; do
if [ -f "$file" ]; then
year=$(grep -m1 '^ \* Copyright' "$file" | grep -oE '[0-9]{4}')
[ -z "$year" ] && year=$(date +%Y)
EXPECTED_HEADER=$(cat <<EOF
/*
* SmartHopper - AI-powered Grasshopper Plugin
* Copyright (C) $year Marc Roca Musach
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*/
EOF
)
header=$(head -n $(echo "$EXPECTED_HEADER" | wc -l) "$file")
if [ "$header" != "$EXPECTED_HEADER" ]; then
if [ "${{ inputs.mode }}" = "fix" ]; then
echo "Updating header in $file"
tail -n +$(grep -n '^namespace ' "$file" | head -n1 | cut -d: -f1) "$file" > tmp && mv tmp "$file"
printf "%s\n\n%s" "$EXPECTED_HEADER" "$(cat \"$file\")" > "$file"
else
echo "Header mismatch in $file"
ERR=1
fi
fi
fi
done
exit $ERR
- name: Commit & push changes
if: ${{ inputs.mode == 'fix' }}
shell: bash
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git add .
git diff --quiet || (git commit -m "chore: automatically fixed file headers" && git push)
47 changes: 47 additions & 0 deletions .github/actions/code-style/namespace-fixer/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Namespace Fixer"
description: "Check or fix C# file namespaces to match file path"
inputs:
mode:
description: "Operation mode: fix or check"
required: false
default: "check"
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Process C# namespaces
if: always()
shell: bash
run: |
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- '*.cs')
ERR=0
for file in $FILES; do
if [ -f "$file" ]; then
rel=${file#src/}
ns=SmartHopper.${rel%.*}
ns=${ns//\//.}
actual=$(grep -m1 '^namespace ' "$file" | cut -d ' ' -f2)
if [ "$actual" != "$ns" ]; then
if [ "${{ inputs.mode }}" = "fix" ]; then
echo "Updating namespace in $file to $ns"
sed -i "s/^namespace .*/namespace $ns/" "$file"
echo "WARNING: References to this file may need manual updates."
else
echo "Namespace mismatch in $file: expected $ns but found $actual"
ERR=1
fi
fi
fi
done
exit $ERR
- name: Commit & push changes
if: ${{ inputs.mode == 'fix' }}
shell: bash
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git add .
git diff --quiet || (git commit -m "chore: automatically fix namespaces" && git push)
42 changes: 42 additions & 0 deletions .github/actions/code-style/trailing-whitespace/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Trailing Whitespace"
description: "Check or fix trailing whitespace and normalize line endings"
inputs:
mode:
description: "Operation mode: fix or check"
required: false
default: "check"
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Process trailing whitespace
shell: bash
run: |
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
ERR=0
for file in $FILES; do
if [[ -f "$file" ]]; then
if [[ "${{ inputs.mode }}" == "fix" ]]; then
sed -i 's/[ \t]*$//' "$file"
# normalize to unix line endings
sed -i 's/\r$//' "$file"
else
if grep -qE '[ \t]+$' "$file" || file "$file" | grep -q CRLF; then
echo "Trailing whitespace or CRLF found in $file"
ERR=1
fi
fi
fi
done
exit $ERR
- name: Commit & push changes
if: ${{ inputs.mode == 'fix' }}
shell: bash
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git add .
git diff --quiet || (git commit -m "chore: automatically fixed trailing whitespace" && git push)
44 changes: 44 additions & 0 deletions .github/actions/code-style/using-sorter/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Using Sorter"
description: "Check or fix C# using directives ordering and remove unused usings"
inputs:
mode:
description: "Operation mode: fix or check"
required: false
default: "check"
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Run using sorter
shell: bash
run: |
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- '*.cs')
ERR=0
dotnet tool install -g dotnet-format || true
export PATH="$HOME/.dotnet/tools:$PATH"
for file in $FILES; do
if [ -f "$file" ]; then
if [ "${{ inputs.mode }}" = "check" ]; then
dotnet format "$file" --verify-no-changes --fix-analyzers
else
dotnet format "$file" --fix-analyzers
fi
fi
done
# fail if any check error
exit $ERR
- name: Commit & push changes
if: ${{ inputs.mode == 'fix' }}
shell: bash
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git add .
git diff --quiet || (git commit -m "chore: automatically sort using directives" && git push)
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ runs:
echo "Adding issue #$ISSUE_NUMBER to changelog: $ISSUE_TITLE"

# Format the line to add
LINE="- Fixes \"$ISSUE_TITLE\" ([#$ISSUE_NUMBER](https://github.com/$REPO/issues/$ISSUE_NUMBER))."
LINE="- (automatically added) Fixes \"$ISSUE_TITLE\" ([#$ISSUE_NUMBER](https://github.com/$REPO/issues/$ISSUE_NUMBER))."

# Add the line to the Fixed section at the determined position
sed -i "${INSERT_LINE}i\\$LINE" "$CHANGELOG_PATH"
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/documentation/update-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ inputs:
required: true
type: choice
options:
- create-release # Create a new release section from Unreleased content
- add-line # Add a new line to a section in the Unreleased area
- create-release # Create a new release section from Unreleased content
- add-line # Add a new line to a section in the Unreleased area
version:
description: 'Version to add to changelog (required for create-release action)'
required: false
Expand Down
Loading