blob: 44cdc1d6cc2fa7d806e374d8e11ed0ef7d7130b8 (
plain) (
blame)
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
|
name: clang-format (w/ diff)
description: clang-format all C/C++ files in the project, and show the diff
inputs:
version:
description: clang-format version
required: false
style:
description: clang-format -style parameter value
required: false
default: file
exclude:
description: ':-separated list of excluded files and directories'
required: false
outputs:
diff:
description: diff between the actual and the formatted code
value: '${{ steps.run.outputs.diff }}'
runs:
using: composite
steps:
- id: run
run: |
New-Variable version -Value '${{ inputs.version }}' -Option Constant
New-Variable style -Value '${{ inputs.style }}' -Option Constant
New-Variable exclude -Value '${{ inputs.exclude }}' -Option Constant
if (Get-Command python3 -ErrorAction SilentlyContinue) {
$python = @('python3')
} elseif (Get-Command py -ErrorAction SilentlyContinue) {
$python = @('py', '-3')
} elseif (Get-Command python -ErrorAction SilentlyContinue) {
$python = @('python')
} else {
echo @'
::error ::
egor-tensin/clang-format uses a Python script, which requires Python 3.6 or later.
We couldn't find a Python installation in this environment.
'@
exit 1
}
$cmake_common_version = 'v3.2'
$script_name = 'project-clang-format.py'
$script_path = Join-Path '${{ github.workspace }}' .. $script_name
$download_url = "https://raw.githubusercontent.com/egor-tensin/cmake-common/$cmake_common_version/tools/$script_name"
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest $download_url -OutFile $script_path
$clang_format = 'clang-format'
if ($version) {
$clang_format += "-$version"
}
$exclude_list = $exclude.Split(':', [System.StringSplitOptions]::RemoveEmptyEntries)
if ($exclude_list) {
$exclude_list = ,'--exclude' + $exclude_list
}
$exe, $args = $python
$output = & $exe $args $script_path --clang-format $clang_format --style $style $exclude_list | Out-String
$output = $output.TrimEnd("`n")
$output = $output.TrimEnd("`r")
Write-Output $output
# If anyone thinks this workaround is anything but complete batshit
# insanity, they should just fucking kill themselves.
# https://github.community/t/set-output-truncates-multiline-strings/16852/3
$output = $output.replace('%', '%25')
$output = $output.replace("`n", '%0A')
$output = $output.replace("`r", '%0D')
Write-Output "::set-output name=diff::$output"
shell: pwsh
branding:
icon: star
color: green
|