generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
232 lines (206 loc) · 9.11 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: 'Alire Setup'
description: 'Install Alire package manager'
author: 'Alire Project'
inputs:
version:
description: Use this argument to install a stable or nightly release. Use a version number without v prefix, e.g., 1.0.1, 1.1.0, or 'nightly'. This argument will be ignored if a branch argument is supplied. Defaults to the latest stable release.
required: false
default: '2.0.2'
# Also to be updated in test-cache-yml
branch:
description: Use this argument to install a development branch (e.g., master).
required: false
default: ''
toolchain:
description: Arguments to pass to `alr toolchain` after setup.
required: false
default: 'gnat_native gprbuild'
msys2:
description: Whether to install MSYS2 on Windows. When false, `msys2.do_not_install` will be set to true in alr's settings.
required: false
default: true
cache:
description: Whether to reuse a cached previous install.
required: false
default: true
outputs:
cache_hit:
description: Whether a cached installation was reused
value: ${{ steps.cache-output.outputs.cache_hit }}
runs:
using: "composite"
steps:
- name: Identify hash from which alr was built
# Identifies the version and hash to be used for the cache key
id: find-hash
shell: bash
run: |
if [[ "${{ inputs.branch }}" != "" ]]; then
echo "hash=$(git ls-remote --heads https://github.com/alire-project/alire ${{ inputs.branch }} | cut -f1)" >> $GITHUB_OUTPUT
echo "version=${{ inputs.branch }}" >> $GITHUB_OUTPUT
elif [[ "${{ inputs.version }}" != "nightly" ]]; then
echo "hash=$(git ls-remote --tags https://github.com/alire-project/alire v${{ inputs.version }} | cut -f1)" >> $GITHUB_OUTPUT
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
else
echo "hash=$(git ls-remote --tags https://github.com/alire-project/alire ${{ inputs.version }} | cut -f1)" >> $GITHUB_OUTPUT
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
fi
# This saves us duplicating caches for msys2 and non-msys2 on non-Windows
- name: Override msys2 for non-Windows platforms
id: override
shell: bash
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
echo "msys2=${{ inputs.msys2 }}" >> $GITHUB_OUTPUT
else
echo "msys2=false" >> $GITHUB_OUTPUT
fi
- name: Generate cache key
id: cache-key
shell: bash
run: |
echo "key=alr[1][${{steps.find-hash.outputs.version}}][${{inputs.toolchain}}][msys2=${{steps.override.outputs.msys2}}][${{runner.os}}][${{runner.arch}}][${{steps.find-hash.outputs.hash}}]" >> $GITHUB_OUTPUT
# The first value in square brackets is to make the key unique for debugging
- name: Reuse cached installation
if: ${{ inputs.cache == 'true' }}
id: cache-alr
uses: actions/cache/restore@v4
with:
path: |
~/.cache/alire
~/.config/alire
~/.local/share/alire
./alire_install
~/AppData/Local/alire
# .cache contains msys64 install on Windows
# .config contains the toolchain at the default location, besides index config
# ./alire_install contains alr itself
# ~/AppData and ./local/share/alire is used with Alire 2.0 onwards
# Note that '~' is recommended on Windows too: https://github.com/actions/cache
# THESE MUST BE EXACTLY THE SAME IN SAME ORDER IN ALL CACHE-RELATED STEPS
key: ${{steps.cache-key.outputs.key}}
- name: Check cache output
shell: bash
run: |
echo Cache hit result: [${{steps.cache-alr.outputs.cache-hit}}] cache-key: ${{steps.cache-key.outputs.key}}
# In case of miss, give an explicit 'false' which actions/cache doesn't provide
- name: Set cache_hit to false if needed
id: cache-output
shell: bash
run: |
if [[ "${{inputs.cache}}" == "true" && "${{steps.cache-alr.outputs.cache-hit}}" == "true" ]]; then
echo "cache_hit=true" >> $GITHUB_OUTPUT
else
echo "cache_hit=false" >> $GITHUB_OUTPUT
fi
# Ascertain if we need to install a toolchain for building from sources
- name: Find GNAT
shell: bash
id: find-gnat
run: gnat --version && echo "available=true" >> $GITHUB_OUTPUT || echo "available=false" >> $GITHUB_OUTPUT
# Setup a GNAT if necessary to build from branch. We cannot use alr-install
# as that creates infinite recursion. Rather than relying on the old action
# that sets up CE editions, we simply fetch a stable alr capable of running
# `alr install`, and we use that to install the latest FSF GNAT.
# BEGIN TOOLCHAIN INSTALLATION
- name: Identify need for GNAT
if: inputs.branch != '' && steps.find-gnat.outputs.available != 'true' && steps.cache-alr.outputs.cache-hit != 'true'
id: need-GNAT
shell: bash
run: echo "need=true" >> $GITHUB_OUTPUT
# Download a stable alr capable of installing a toolchain. Avoid to install
# a msys2 at this point which is not needed and confuses later tests.
- name: Install GNAT (I)
if: steps.need-GNAT.outputs.need == 'true'
shell: bash
run: |
os_lower=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]')
case "${{ runner.arch }}" in
ARM64) arch=aarch64;;
X64) arch=x86_64;;
*) echo "Unknown arch: ${{runner.arch}}"; exit 1;;
esac
alr_version=2.0.2
alr_filename=alr-${alr_version}-bin-${arch}-${os_lower}.zip
curl -L -O https://github.com/alire-project/alire/releases/download/v${alr_version}/${alr_filename}
unzip -o ${alr_filename} "bin/alr*" -d tmp_alr
rm ${alr_filename}
echo "$(pwd -W 2>/dev/null || pwd)/tmp_alr/bin" >> $GITHUB_PATH
tmp_alr/bin/alr settings --global --set msys2.do_not_install true || \
tmp_alr/bin/alr config --global --set msys2.do_not_install true
# Perform the actual `alr install` and remove the `alr` just used to avoid
# conflicts with the `alr` being built.
- name: Install GNAT (II)
if: steps.need-GNAT.outputs.need == 'true'
shell: bash
run: |
alr install gnat_native gprbuild --prefix=$PWD/setup_alire_prefix
echo REMOVAL TARGET: $(which alr)
rm -rf tmp_alr && echo REMOVED stable alr used for toolchain install
- name: Install GNAT (III) - Add to path
if: steps.need-GNAT.outputs.need == 'true'
shell: bash
run: |
path_to_add=$(pwd -W 2>/dev/null || pwd)/setup_alire_prefix/bin
echo Adding to PATH: $path_to_add
echo "$path_to_add" >> $GITHUB_PATH
# END TOOLCHAIN INSTALLATION
# To run the old setup action which is javascript
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
# Install alr. If found cached it will return without reinstalling (but setting PATH).
# We forward inputs as they're bugged for JS in composite actions.
- run: node $(echo "${{ github.action_path }}/lib/main.js" | sed 's/\\/\//g') '${{ toJSON(inputs) }}'
shell: bash
# on Windows, backlashes mess things for bash, and powershell chokes on toJSON output
# Remove our installed toolchain as not to interfere with other
# actions/workflows down the line
- name: Remove GNAT (IV)
if: steps.need-GNAT.outputs.need == 'true'
shell: bash
run: |
rm -rf setup_alire_prefix && \
echo REMOVED toolchain used to build alr at $PWD/setup_alire_prefix
# Display result for the record, and do some housekeeping
- shell: bash
run: |
which alr
alr --version
{ alr index --update-all >/dev/null && echo "Index refreshed"; } || echo "Index refresh failed"
# Report GNAT version if available (might be deselected with `toolchain` argument)
- shell: bash
run: |
alr -n -q init --bin find_gnat >/dev/null && cd find_gnat
echo "Using gnat: $(alr exec -- which gnat)" || true
echo "$(alr exec -- gnat --version)" || true
cd ../find_gnat/.. && rm -rf find_gnat
# Save cache early so we can verify its proper working in a test workflow. Otherwise
# it's not saved until workflow completion and by then it's too late.
# When cache was hit, attempting to save will fail and emit a warning, so avoid it.
- name: Cache install
if: ${{ inputs.cache == 'true' && steps.cache-alr.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
path: |
~/.cache/alire
~/.config/alire
~/.local/share/alire
./alire_install
~/AppData/Local/alire
key: ${{ steps.cache-key.outputs.key }}
# Verify cache was saved properly
- name: Cache verify
if: ${{ inputs.cache == 'true' && steps.cache-alr.outputs.cache-hit != 'true' }}
uses: actions/cache/restore@v4
with:
path: |
~/.cache/alire
~/.config/alire
~/.local/share/alire
./alire_install
~/AppData/Local/alire
key: ${{steps.cache-key.outputs.key}}
lookup-only: true
fail-on-cache-miss: false