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
80 changes: 0 additions & 80 deletions .github/actions/check-editorconfig/action.yaml

This file was deleted.

85 changes: 85 additions & 0 deletions .github/workflows/reusable-check-editorconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: "(Reusable) Check .editorconfig"

on:
workflow_call:
inputs:
ref:
description: "Specify a branch or commit ID"
required: true
type: string
max-retries:
description: "Maximum number of retries if API call fails"
required: false
type: string
default: "3"
retry-delay:
description: "Delay in seconds between retries"
required: false
type: string
default: "5"
fail-on-missing:
description: "Fail the workflow if .editorconfig does not exist"
required: false
type: boolean
default: true
outputs:
exists:
description: "Indicates whether the .editorconfig file exists"
value: ${{ jobs.check-editorconfig.outputs.exists }}

jobs:
check-editorconfig:
runs-on: ubuntu-22.04
outputs:
exists: ${{ steps.check-editorconfig.outputs.exists }}
steps:
- name: Check for .editorconfig
id: check-editorconfig
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
file_path=".editorconfig"
ref="${{ inputs.ref }}"
max_retries="${{ inputs.max-retries }}"
retry_delay_sec="${{ inputs.retry-delay }}"
fail_on_missing="${{ inputs.fail-on-missing }}"

echo "Checking .editorconfig in ref: $ref"

success=false

for ((i=1; i<=max_retries; i++)); do
response=$(gh api "repos/${{ github.repository }}/contents/$file_path?ref=$ref" \
--header "Authorization: Bearer $GH_TOKEN" \
--timeout 10s \
--jq ". | select(.type==\"file\") | select(.name==\"$file_path\")")

api_exit_code=$?

if [ $api_exit_code -eq 124 ]; then
echo "::warning::Attempt $i: API request timed out. Retrying in $retry_delay_sec seconds..."
sleep $retry_delay_sec
continue
elif [ -z "$response" ]; then
if [ $i -eq $max_retries ]; then
if [ "$fail_on_missing" = "true" ]; then
echo "::error::Failed to find .editorconfig after $max_retries retries in ref '$ref'."
else
echo "::warning::Failed to find .editorconfig after $max_retries retries in ref '$ref'. Not failing workflow."
fi
else
echo "::warning::Attempt $i: .editorconfig file not found. Retrying in $retry_delay_sec seconds..."
sleep $retry_delay_sec
fi
else
echo "::notice::Success: .editorconfig file exists in ref '$ref'."
success=true
break
fi
done

echo "exists=$success" | tee -a "$GITHUB_OUTPUT"

if [ "$success" = "false" ] && [ "$fail_on_missing" = "true" ]; then
exit 1
fi
39 changes: 24 additions & 15 deletions .github/workflows/reusable-unity-cs-linter-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ env:
CONVERT_TO_SARIF_URI: 'https://raw.githubusercontent.com/IShix-g/Unity-GitHubActions/HEAD/.github/scripts/convert_to_sarif.py'

jobs:
lint-cs-files:
branch-conf:
runs-on: ubuntu-22.04
timeout-minutes: 12
outputs:
base-branch: ${{ steps.branch-conf.outputs.base-branch }}
head-branch: ${{ steps.branch-conf.outputs.head-branch }}
editorconfig-branch: ${{ steps.branch-conf.outputs.editorconfig-branch }}
steps:
- name: Branch Configuration
id: branch-conf
Expand Down Expand Up @@ -80,33 +83,39 @@ jobs:
echo "Head Branch: $head_branch"
echo "Editorconfig Branch: $editorconfig_branch"

- uses: IShix-g/Unity-GitHubActions/.github/actions/check-editorconfig@main
with:
ref: ${{ steps.branch-conf.outputs.editorconfig-branch }}
max-retries: '3'
retry-delay: '5'
fail-on-missing: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
check-editorconfig:
needs: [branch-conf]
uses: ./.github/workflows/reusable-check-editorconfig.yaml
with:
ref: ${{ needs.branch-conf.outputs.editorconfig-branch }}
max-retries: '3'
retry-delay: '5'
fail-on-missing: true
secrets: inherit

lint-cs-files:
needs: [branch-conf, check-editorconfig]
runs-on: ubuntu-22.04
timeout-minutes: 12
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ steps.branch-conf.outputs.head-branch || steps.branch-conf.outputs.base-branch }}
ref: ${{ needs.branch-conf.outputs.head-branch || needs.branch-conf.outputs.base-branch }}
fetch-depth: 0

- name: Fetch .editorconfig from Default Branch
if: ${{ steps.branch-conf.outputs.editorconfig-branch != steps.branch-conf.outputs.head-branch }}
if: ${{ needs.branch-conf.outputs.editorconfig-branch != needs.branch-conf.outputs.head-branch }}
run: |
branch="${{ steps.branch-conf.outputs.editorconfig-branch }}"
branch="${{ needs.branch-conf.outputs.editorconfig-branch }}"
git fetch origin "$branch"
git checkout origin/"$branch" -- .editorconfig

- name: Detect Changed C# Files
id: detect-cs-files
run: |
base_branch=origin/${{ steps.branch-conf.outputs.base-branch }}
head_branch=${{ steps.branch-conf.outputs.head-branch || 'HEAD' }}
base_branch=origin/${{ needs.branch-conf.outputs.base-branch }}
head_branch=${{ needs.branch-conf.outputs.head-branch || 'HEAD' }}
files=$(git diff --name-only "$base_branch"..."$head_branch" | grep '\.cs$' || true)
include_regexes=$(echo "${{ inputs.include-paths }}" | tr ',' '\n')
exclude_regexes=$(echo "${{ inputs.exclude-paths }}" | tr ',' '\n')
Expand Down
Loading