33name : O2 linter
44
55" on " : [pull_request_target, push]
6+ env :
7+ BRANCH_MAIN : master
68permissions : {}
79
810concurrency :
@@ -16,29 +18,35 @@ jobs:
1618 permissions :
1719 pull-requests : write
1820 steps :
21+ - name : Set branches
22+ run : |
23+ if [[ "${{ github.event_name }}" == "push" ]]; then
24+ branch_head="${{ github.ref }}"
25+ branch_base="${{ env.BRANCH_MAIN }}"
26+ else
27+ branch_head="refs/pull/${{ github.event.pull_request.number }}/merge"
28+ branch_base="${{ github.event.pull_request.base.ref }}"
29+ fi
30+ echo BRANCH_HEAD="$branch_head" >> "$GITHUB_ENV"
31+ echo BRANCH_BASE="$branch_base" >> "$GITHUB_ENV"
1932 - name : Checkout Code
2033 uses : actions/checkout@v4
21- env :
22- branch_head : ${{ github.event_name == 'push' && github.ref || 'refs/pull/'github.event.number'/merge' }}
2334 with :
24- ref : ${{ env.branch_head }}
35+ ref : ${{ env.BRANCH_HEAD }}
2536 fetch-depth : 0 # needed to get the full history
2637 - name : Run tests
2738 id : linter
28- env :
29- branch_head : ${{ github.event_name == 'push' && github.ref || 'refs/pull/'github.event.number'/merge' }}
30- branch_base : ${{ github.event_name == 'push' && 'master' || github.event.pull_request.base.ref }}
3139 run : |
3240 # Diff against the common ancestor of the source branch and the target branch.
33- echo "Diffing ${{ env.branch_head }} against ${{ env.branch_base }}."
34- readarray -t files < <(git diff --diff-filter d --name-only origin/${{ env.branch_base }}...)
41+ echo "Diffing ${{ env.BRANCH_HEAD }} against ${{ env.BRANCH_BASE }}."
42+ readarray -t files < <(git diff --diff-filter d --name-only origin/${{ env.BRANCH_BASE }}...)
3543 if [ ${#files[@]} -eq 0 ]; then
3644 echo "::notice::No files to lint."
3745 echo "linter_ran=0" >> "$GITHUB_OUTPUT"
3846 exit 0
3947 fi
4048 echo "linter_ran=1" >> "$GITHUB_OUTPUT"
41- [ ${{ github.event_name }} == ' pull_request_target' ] && options="-g"
49+ [[ " ${{ github.event_name }}" == " pull_request_target" ] ] && options="-g"
4250 # shellcheck disable=SC2086 # Ignore unquoted options.
4351 python3 Scripts/o2_linter.py $options "${files[@]}"
4452 echo "Tip: If you allow actions in your fork repository, O2 linter will run when you push commits."
0 commit comments