-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
162 lines (137 loc) · 5.5 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: 'Google Bloaty Action'
description: 'Build and run google/bloaty on a set of files'
author: Kendal Harland
inputs:
bloaty-version:
description: A Git ref specifying the version of bloaty to build.
default: 'refs/heads/main'
required: false
bloaty-checkout-dir:
description: Where to clone and build google/bloaty
default: ${{ github.workspace }}/.google-bloaty
required: false
bloaty-args:
description: The arguments to pass to bloaty. Input filenames must use absolute paths.
default: ''
required: true
bloaty-input-files:
description: A list of input filenames and glob patterns separated by newlines. You cannot set bloaty's -c flag when using this.
default: ''
required: false
bloaty-output-file:
description: A filename where bloaty output should be written.
default: 'bloaty-output'
required: true
cache-bloaty:
description: Cache the bloaty executable for faster builds.
default: 'false'
required: false
cache-bloaty-key:
description: The key to use when caching bloaty. Only used if 'cache-bloaty' is true. Defaults to bloaty-<bloaty-version>
default: ''
required: false
compiler:
description: Tell cmake to use this compiler.
default: '' # Let cmake decide.
required: false
runs:
using: composite
steps:
- name: Resolve bloaty cache key
if: inputs.cache-bloaty == 'true'
id: cache-key
shell: pwsh
run: |
if ("${{ inputs.cache-bloaty-key }}") {
"cache-key=${{ inputs.cache-bloaty-key }}" | Out-File $env:GITHUB_OUTPUT -Encoding utf8 -Append
} else {
"cache-key=bloaty-${{ inputs.bloaty-version }}" | Out-File $env:GITHUB_OUTPUT -Encoding utf8 -Append
}
- name: Restore bloaty cache
if: inputs.cache-bloaty == 'true'
id: cache
uses: actions/cache/restore@v3
with:
key: ${{ steps.cache-key.outputs.cache-key }}
path: .caches/bloaty
- name: Generate bloaty options file
shell: bash
run: |
BloatyOptionsFile="${{ github.workspace }}/.bloaty.textproto"
mkdir -p $(dirname ${BloatyOptionsFile})
touch $BloatyOptionsFile
echo "BLOATY_OPTIONS_FILE=$BloatyOptionsFile" >> $GITHUB_ENV
# Bash is used here because with globstar enabled we can easily handle recursive
# glob patterns.
- name: Generate bloaty options file contents
if: inputs.bloaty-input-files != ''
shell: bash
run: |
# Enables recursive glob patterns. Requires Bash v4+.
shopt -s globstar
# Parse input patterns, taking care to convert \ to / to avoid
# incorrectly escaping filenames that come from windows.
BloatyInputFiles=$(echo "${{ inputs.bloaty-input-files }}" | sed 's/\\/\//g')
IFS=$'\n' read -d '%' -a Patterns <<<"${BloatyInputFiles}%"
declare -p Patterns
# Glob files and generate filenames in the options file, replacing backslashes
# with forward slashes.
for Pattern in ${Patterns[@]}; do
# We don't use xargs here because it can't handle large inputs.
for Filename in $(ls "${Pattern}"); do
echo "filename: \"${Filename}\"" >> $BLOATY_OPTIONS_FILE
done
done
echo "-- Contents of $BLOATY_OPTIONS_FILE"
cat $BLOATY_OPTIONS_FILE
- name: Checkout google/bloaty
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: google/bloaty
ref: ${{ inputs.bloaty-version }}
path: ${{ inputs.bloaty-checkout-dir }}
show-progress: false
- name: Setup Ninja
if: steps.cache.outputs.cache-hit != 'true'
uses: seanmiddleditch/gha-setup-ninja@v4
- name: Show runner.arch context
shell: pwsh
run: echo "${{ runner.arch }}"
- name: Configure bloaty
if: steps.cache.outputs.cache-hit != 'true' && inputs.compiler != ''
shell: pwsh
run: |
cmake -B ${{ inputs.bloaty-checkout-dir }}/.build `
-S ${{ inputs.bloaty-checkout-dir }} `
-G Ninja `
-D CMAKE_CXX_COMPILER="${{ inputs.compiler }}" `
-D CMAKE_C_COMPILER="${{ inputs.compiler }}"
- name: Configure bloaty
if: steps.cache.outputs.cache-hit != 'true' && inputs.compiler == ''
shell: pwsh
run: |
cmake -B ${{ inputs.bloaty-checkout-dir }}/.build `
-S ${{ inputs.bloaty-checkout-dir }} `
-G Ninja
- name: Build bloaty
if: steps.cache.outputs.cache-hit != 'true'
shell: pwsh
run: |
cmake --build ${{ inputs.bloaty-checkout-dir }}/.build
# Copy bloaty.exe to the same path used by the cache so we can add it to our PATH
# in the next step, regardless of whether we hit the cache earlier.
New-Item -Path .caches/bloaty -ItemType Directory -Force | Out-Null
Copy-Item ${{ inputs.bloaty-checkout-dir }}/.build/bloaty.exe -Destination .caches/bloaty
- name: Cache bloaty
if: inputs.cache-bloaty == 'true' && steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
key: ${{ steps.cache-key.outputs.cache-key }}
path: .caches/bloaty
- name: Add bloaty to path
shell: pwsh
run: echo ".caches/bloaty" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Run bloaty
shell: pwsh
run: bloaty -c ${{ env.BLOATY_OPTIONS_FILE }} ${{ inputs.bloaty-args }} | Out-File ${{ inputs.bloaty-output-file }} -Encoding utf8