-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
162 lines (143 loc) · 4.97 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: 'alr install'
description: 'Install using `alr install`'
author: 'Alire Project'
inputs:
crates:
description: 'Crates to install, accepts version sets, e.g.: hello^2'
required: true
default: ''
prefix:
description: Location for the installation, will contain `<prefix>/bin` and so on
required: false
default: alire_prefix
force:
description: use `alr --force` during install
required: false
default: false
add_to_path:
description: Whether to add the prefix to path
required: false
default: true
clean:
description: Whether to remove alr afterwards, if it wasn't originally installed
required: false
default: true
cache:
description: Whether to reuse a cached previous install
required: false
default: true
outputs:
cache_hit:
description: Whether the cache was hit
value: ${{ steps.cache-output.outputs.cache_hit }}
runs:
using: "composite"
steps:
- name: Find alr in path
id: find-alr
shell: bash
run: |
which alr && echo "available=true" >> $GITHUB_OUTPUT || echo "available=false" >> $GITHUB_OUTPUT
- name: Set up alr
if: steps.find-alr.outputs.available != 'true'
uses: alire-project/setup-alire@v4
with:
cache: ${{inputs.cache}}
- name: Prepare alr version
id: alr-version
shell: bash
run: |
echo "version=$(alr --version)" >> $GITHUB_OUTPUT
- name: Prepare --force
id: force
shell: bash
run: |
if [[ "${{inputs.force}}" != "false" ]]; then
echo "force=--force" >> $GITHUB_OUTPUT
else
echo "force=" >> $GITHUB_OUTPUT
fi
- name: Prepare cache milestones
id: find-versions
shell: bash
run: |
versions=""
for crate in ${{inputs.crates}}; do
versions+=":"$(alr show ${crate} | head -1 | cut -f1 -d:)
done
echo Versions are: $versions
echo "milestones=$versions" >> $GITHUB_OUTPUT
- name: Prepare cache id
id: cache-key
shell: bash
run: |
echo "key=[2][alr-install][alr=${{steps.alr-version.outputs.version}}][${{runner.os}}][${{runner.arch}}][${{inputs.prefix}}][${{steps.find-versions.outputs.milestones}}]" >> $GITHUB_OUTPUT
- name: Reuse cached installation
if: inputs.cache == 'true'
id: cache-install
uses: actions/cache@v4
with:
path: |
${{inputs.prefix}}
key: ${{steps.cache-key.outputs.key}}
# In case of miss, give an explicit 'false' which actions/cache doesn't provide
- name: Set cache_hit output
id: cache-output
shell: bash
run: |
if [[ "${{inputs.cache}}" == "true" && "${{steps.cache-install.outputs.cache-hit}}" == "true" ]]; then
echo "cache_hit=true" >> $GITHUB_OUTPUT
else
echo "cache_hit=false" >> $GITHUB_OUTPUT
fi
- name: Diagnose cache usage
shell: bash
run: |
echo "alr-install cache requested: ${{inputs.cache}}"
echo "alr-install cache hit: ${{steps.cache-output.outputs.cache_hit}}"
echo "alr-install cache key: ${{steps.cache-key.outputs.key}}"
- name: Run `alr install`
if: inputs.cache != 'true' || steps.cache-install.outputs.cache-hit != 'true'
shell: bash
run: |
alr -d ${{steps.force.outputs.force}} install ${{inputs.crates}} --prefix ${{inputs.prefix}}
- name: Show prefix info
shell: bash
run: |
alr install --prefix ${{inputs.prefix}} --info
- name: Add to path (Windows)
if: inputs.add_to_path == 'true' && runner.os == 'Windows'
shell: pwsh
run: |
$Target = Resolve-Path ${{inputs.prefix}}\bin
Add-Content $env:GITHUB_PATH $Target
- name: Add to path (!Windows)
if: inputs.add_to_path == 'true' && runner.os != 'Windows'
shell: bash
run: |
readlink -f "${{inputs.prefix}}/bin" >> $GITHUB_PATH
- name: Cleanup
if: inputs.clean == 'true' && steps.find-alr.outputs.available != 'true'
shell: bash
run: rm -rf alire_install
# 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 save
if: ${{ inputs.cache == 'true' && steps.cache-install.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
path: |
${{inputs.prefix}}
key: ${{steps.cache-key.outputs.key}}
# Verify cache was saved properly
- name: Cache verify
if: ${{ inputs.cache == 'true' && steps.cache-install.outputs.cache-hit != 'true' }}
uses: actions/cache/restore@v4
with:
path: |
${{inputs.prefix}}
key: ${{steps.cache-key.outputs.key}}
lookup-only: true
fail-on-cache-miss: false
# Even if the cache is not found, we don't want to fail here for clients