Skip to content

Commit 7ff24e4

Browse files
authored
feat: add support for custom editorconfig branch input (#192)
1 parent 39f6c36 commit 7ff24e4

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

.github/workflows/reusable-lint-cs-files.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77
description: "Specify a branch or commit ID"
88
required: true
99
type: string
10+
editorconfig-branch:
11+
description: 'Branch where .editorconfig is located. If not specified, ref will be used.'
12+
required: false
13+
type: string
14+
default: ''
1015
files:
1116
description: 'List of file paths to be linted, separated by a comma (`,`), pipe (`|`), or semicolon (`;`).'
1217
required: true
@@ -46,6 +51,34 @@ jobs:
4651
ref: ${{ inputs.ref }}
4752
fetch-depth: 0
4853

54+
- name: Branch Configuration
55+
id: branch-conf
56+
run: |
57+
if [ -n "${{ inputs.editorconfig-branch }}" ]; then
58+
editorconfig_branch="${{ inputs.editorconfig-branch }}"
59+
else
60+
editorconfig_branch="${{ inputs.ref }}"
61+
fi
62+
echo "editorconfig-branch=${editorconfig_branch#refs/heads/}" >> "$GITHUB_OUTPUT"
63+
echo "Editorconfig Branch: $editorconfig_branch"
64+
65+
- name: Fetch .editorconfig from Default Branch
66+
if: ${{ inputs.ref != steps.branch-conf.outputs.editorconfig-branch }}
67+
run: |
68+
ref="${{ steps.branch-conf.outputs.editorconfig-branch }}"
69+
git fetch origin "$ref"
70+
71+
if git show-ref --verify --quiet refs/heads/"$ref"; then
72+
echo "$ref was recognized as a branch"
73+
git checkout origin/"$ref" -- .editorconfig
74+
elif [[ "$ref" =~ ^[0-9a-f]{7,40}$ ]] && git rev-parse --quiet "$ref"; then
75+
echo "$ref was recognized as a commit id"
76+
git checkout "$ref" -- .editorconfig
77+
else
78+
echo "An invalid reference was specified: $ref"
79+
exit 1
80+
fi
81+
4982
- name: Create Temporary csproj for Analysis
5083
run: |
5184
{

.github/workflows/reusable-unity-cs-linter-pull-request.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ on:
4343
type: string
4444
default: '50'
4545

46-
env:
47-
EDITORCONFIG_SAMPLE_URI: 'https://github.com/IShix-g/Unity-GitHubActions/blob/main/.editorconfig'
48-
CONVERT_TO_SARIF_URI: 'https://raw.githubusercontent.com/IShix-g/Unity-GitHubActions/HEAD/.github/scripts/convert_to_sarif.py'
49-
5046
jobs:
5147
branch-conf:
5248
runs-on: ubuntu-22.04
@@ -105,13 +101,6 @@ jobs:
105101
ref: ${{ needs.branch-conf.outputs.head-branch || needs.branch-conf.outputs.base-branch }}
106102
fetch-depth: 0
107103

108-
- name: Fetch .editorconfig from Default Branch
109-
if: ${{ needs.branch-conf.outputs.editorconfig-branch != needs.branch-conf.outputs.head-branch }}
110-
run: |
111-
branch="${{ needs.branch-conf.outputs.editorconfig-branch }}"
112-
git fetch origin "$branch"
113-
git checkout origin/"$branch" -- .editorconfig
114-
115104
- name: Detect Changed C# Files
116105
id: detect-cs-files
117106
run: |

0 commit comments

Comments
 (0)