-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
132 lines (124 loc) · 5.92 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: "PHPStan Baseline Refresh"
description: "Automatically create a PR when the PHPStan baseline can be refreshed"
inputs:
github_token:
description: "GitHub user token to create the PR"
required: true
configuration_path:
description: "Path to PHPStan configuration file (.neon or .php)"
default: "phpstan.neon"
required: true
baseline_path:
description: "Path to PHPStan baseline file (.neon or .php)"
required: true
phpstan_path:
description: "Path to PHPStan"
default: "vendor/bin/phpstan"
required: true
phpstan_additional_arguments:
description: "Additional arguments passed to the analyze command"
default: "--ansi"
required: false
add_unmatched_errors_in_baseline:
description: "When enabled, errors that pop up during the analyze run are ignored and added to the baseline too. This can be useful when your main branch is no longer passing because of a bad merge."
default: false
branch:
description: "Name of the branch to push to"
default: "phpstan-baseline"
required: true
target_branch:
description: "Name of the branch to target the PR to"
default: "main"
required: true
commit_name:
description: "Name of the author"
default: "GitHub Actions"
required: true
commit_email:
description: "Email of the author"
default: "actions@github.com"
required: true
commit_message:
description: "Commit message when PHPStan baseline changed"
default: "PHPStan > Update baseline"
required: true
pr_create:
description: "Wether or not to create the PR"
default: true
required: true
pr_title:
description: "Title of the PR"
default: "PHPStan > Update baseline"
required: true
pr_reviewer:
description: "Comma-separated list (no spaces) of people and teams that should be added as reviewer"
required: false
pr_body:
description: "Body of the PR"
required: true
default: |
This PR is automatically created to cleanup our baseline.
Since the last refresh of the baseline we have fixed {0} ignored errors.
Keep it up all! :muscle:
There are only {1} ignored errors left :sweat_smile:
runs:
using: "composite"
steps:
- name: PHPStan
shell: bash
continue-on-error: ${{ inputs.pr_create == 1 && inputs.add_unmatched_errors_in_baseline == 1 }}
run: |
echo "Running PHPStan"
${{ inputs.phpstan_path }} analyze --configuration=${{ inputs.configuration_path }} ${{ inputs.phpstan_additional_arguments }}
- name: Ignored errors
id: before-refresh
shell: bash
run: |
set -eu
if [[ "${{ inputs.baseline_path }}" == *.neon ]]; then
IGNORED_COUNT=$(cat ${{ inputs.baseline_path }} | grep 'count: ' | sed 's/[^0-9]*//g' | paste -sd+ - | bc)
elif [[ "${{ inputs.baseline_path }}" == *.php ]]; then
IGNORED_COUNT=$(cat ${{ inputs.baseline_path }} | grep "'count' => " | sed 's/[^0-9]*//g' | paste -sd+ - | bc)
else
echo "Baseline is not a .neon or .php file"
exit 1
fi
echo "Baseline currently has $IGNORED_COUNT ignored errors"
echo "ignored-count=$IGNORED_COUNT" >> $GITHUB_OUTPUT
- name: Refresh baseline
if: ${{ inputs.pr_create == 1 }}
id: refresh-baseline
shell: bash
run: |
set -eu
echo "Generating new baseline"
${{ inputs.phpstan_path }} analyze --configuration=${{ inputs.configuration_path }} ${{ inputs.phpstan_additional_arguments }} --generate-baseline ${{ inputs.baseline_path }}
CHANGED=$(git diff --quiet ${{ inputs.baseline_path }} && echo 0 || echo 1)
echo "changed=$CHANGED" >> $GITHUB_OUTPUT
if [[ "${{ inputs.baseline_path }}" == *.neon ]]; then
NEW_IGNORED_COUNT=$(cat ${{ inputs.baseline_path }} | grep 'count: ' | sed 's/[^0-9]*//g' | paste -sd+ - | bc)
elif [[ "${{ inputs.baseline_path }}" == *.php ]]; then
NEW_IGNORED_COUNT=$(cat ${{ inputs.baseline_path }} | grep "'count' => " | sed 's/[^0-9]*//g' | paste -sd+ - | bc)
fi
echo "Baseline now has $NEW_IGNORED_COUNT ignored errors"
echo "new-ignored-count=$NEW_IGNORED_COUNT" >> $GITHUB_OUTPUT
FIXED=$(echo "${{ steps.before-refresh.outputs.ignored-count }} - " $NEW_IGNORED_COUNT | bc)
echo "Fixed $FIXED error(s)"
echo "fixed=$FIXED" >> $GITHUB_OUTPUT
- name: Push baseline to branch
if: ${{ inputs.pr_create == 1 && steps.refresh-baseline.outputs.changed == 1 }}
shell: bash
env:
GH_TOKEN: ${{ inputs.github_token }}
run: |
set -eu
echo "Pushing baseline to branch ${{ inputs.branch }}"
git config --local user.email "${{ inputs.commit_email }}"
git config --local user.name "${{ inputs.commit_name }}"
git checkout -b ${{ inputs.branch }}
git add ${{ inputs.baseline_path }}
git commit -m "${{ inputs.commit_message }}"
git push --set-upstream origin ${{ inputs.branch }} --force
cat << EOF | gh pr create --base ${{ inputs.target_branch }} --title "${{ inputs.pr_title }}" --reviewer "${{ inputs.pr_reviewer }}" --body-file -
${{ format(inputs.pr_body, steps.refresh-baseline.outputs.fixed, steps.refresh-baseline.outputs.new-ignored-count) }}
EOF