-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.nix
245 lines (225 loc) · 9.27 KB
/
action.nix
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
{ target, lib }:
let
specific = {
cache = {
description = "Restore and save";
actions = "restoring and saving";
main = "dist/restore/index.js";
post =
''
post: "dist/save/index.js"
post-if: success()'';
};
save = {
description = "Save";
actions = "saving";
main = "../dist/save-only/index.js";
post = "";
};
restore = {
description = "Restore";
actions = "restoring";
main = "../dist/restore-only/index.js";
post = "";
};
}.${target};
q = txt: "`${txt}`";
whenListOf = "When a newline-separated non-empty list of non-empty";
pathsDefault = ''`["/nix", "~/.cache/nix", "~root/.cache/nix"]`'';
nixTrue = "nix: true";
pathsDefaultWhenNix = ''When ${q nixTrue}, the action uses ${pathsDefault} as default paths, as suggested [here](https://github.com/divnix/nix-cache-action/blob/b14ec98ae694c754f57f8619ea21b6ab44ccf6e7/action.yml#L7). Otherwise, the action uses an empty list as default paths.'';
pathsWhen = ''${whenListOf} path patterns (see [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns), the action appends it to default paths and uses the resulting list for ${specific.actions} caches.'';
pathsOtherwise = ''Otherwise, the action uses default paths for ${specific.actions} caches.'';
effectOnlyOn = platform: ''Can have an effect only when the action runs on a ${q platform} runner.'';
linux = "Linux";
macos = "macOS";
effectOnlyWhenHasEffect = input: "Can have an effect only when ${q input} has effect.";
effectOnlyWhen = conditions: "Can have an effect only when ${lib.concatMapStringsSep ", " q conditions}.";
effectOnlyWhenNixEnabled = effectOnlyWhen [ nixTrue ];
noEffectOtherwise = ''Otherwise, this input has no effect.'';
gcWhen = ''When a number, the action collects garbage until Nix store size (in bytes) is at most this number just before the action tries to save a new cache.'';
overrides = input: "Overrides ${q input}.";
paths = "paths";
gc-max-store-size = "gc-max-store-size";
primary-key = "primary-key";
restore-prefixes-first-match = "restore-prefixes-first-match";
hit-primary-key = "hit-primary-key";
hit-first-match = "hit-first-match";
in
''
name: "${specific.description} Nix store"
description: "${specific.description} Nix store using GitHub Actions cache to speed up workflows."
author: "GitHub"
inputs:
${primary-key}:
description: |
- When a non-empty string, the action uses this key for ${specific.actions} a cache.
- Otherwise, the action fails.
required: true
${
if target == "cache" || target == "restore" then
''
${restore-prefixes-first-match}:
description: |
- ${whenListOf} key prefixes, when there's a miss on the ${q primary-key},
the action searches in this list for the first prefix for which there exists a cache
with a matching key and the action tries to restore that cache.
- ${noEffectOtherwise}
default: ""
restore-prefixes-all-matches:
description: |
- ${whenListOf} key prefixes, the action tries to restore
all caches whose keys match these prefixes.
- Tries caches across all refs to make use of caches created
on the current, base, and default branches
(see [docs](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache)).
- ${noEffectOtherwise}
default: ""
skip-restore-on-hit-primary-key:
description: |
- Can have an effect only when ${q restore-prefixes-first-match} has no effect.
- When `true`, when there's a hit on the ${q primary-key}, the action doesn't restore caches.
- ${noEffectOtherwise}
default: "false"
fail-on:
description: |
- Input form: `<key type>.<result>`.
- `<key type>` options: ${q primary-key}, `first-match`.
- `<result>` options: `miss`, `not-restored`.
- When the input satisfies the input form, when the event described in the input happens, the action fails.
- Example:
- Input: `${primary-key}.not-restored`.
- Event: a cache could not be restored via the ${q primary-key}.
- ${noEffectOtherwise}
default: ""''
else ""
}
nix:
description: |
- Can have an effect only when the action runs on a ${q linux} or a ${q macos} runner.
- When `true`, the action can do Nix-specific things.
- Otherwise, the action doesn't do them.
default: "true"
save:
description: |
- When `true`, the action can save a cache with the ${q primary-key}.
- Otherwise, the action can't save a cache.
default: "true"
${paths}:
description: |
- ${pathsDefaultWhenNix}
- ${pathsWhen}
- ${pathsOtherwise}
default: ""
${paths}-macos:
description: |
- ${overrides paths}
- ${effectOnlyOn macos}
default: ""
${paths}-linux:
description: |
- ${overrides paths}
- ${effectOnlyOn linux}
default: ""
${
if target == "cache" || target == "save" then
''
${gc-max-store-size}:
description: |
- ${effectOnlyWhen [nixTrue "save: true"]}
- ${gcWhen}
- ${noEffectOtherwise}
default: ""
${gc-max-store-size}-macos:
description: |
- ${overrides gc-max-store-size}
- ${effectOnlyOn macos}
default: ""
${gc-max-store-size}-linux:
description: |
- ${overrides gc-max-store-size}
- ${effectOnlyOn linux}
default: ""
purge:
description: |
- When `true`, the action purges (possibly zero) caches.
- ${noEffectOtherwise}
default: "false"
purge-${primary-key}:
description: |
- ${effectOnlyWhen ["purge: true"]}
- When `always`, the action always purges cache with the ${q primary-key}.
- When `never`, the action never purges cache with the ${q primary-key}.
- ${noEffectOtherwise}.
default: ""
purge-prefixes:
description: |
- ${effectOnlyWhen ["purge: true"]}
- ${whenListOf} cache key prefixes, the action selects for purging all caches whose keys match some of these prefixes and that are scoped to the current [GITHUB_REF](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables).
- ${noEffectOtherwise}
default: ""
purge-last-accessed:
description: |
- ${effectOnlyWhen ["purge: true"]}
- When a number, the action purges selected caches that were last accessed more than this number of seconds ago relative to the start of the `Post Restore` phase.
- ${noEffectOtherwise}
default: ""
purge-created:
description: |
- ${effectOnlyWhen ["purge: true"]}
- When a number, the action purges caches created more than this number of seconds ago relative to the start of the `Post Restore` phase.
- ${noEffectOtherwise}
default: ""
upload-chunk-size:
# The original default value may be provided here (https://github.com/actions/cache/issues/1292)
# 32MB
description: |
- When a number, the action uses it as the chunk size (in bytes) to split up large files during upload.
- Otherwise, the action uses the default value `33554432` (32MB).
default: ""''
else ""}
token:
description: The action uses it to communicate with GitHub API.
default: ''${{ github.token }}
${
if target == "cache" || target == "restore" then
''
outputs:
${primary-key}:
description: |
- A string.
- The ${q primary-key}.
hit:
description: |
- A boolean value.
- `true` when ${q hit-primary-key} is `true` or ${q hit-first-match} is `true`.
- `false` otherwise.
${hit-primary-key}:
description: |
- A boolean value.
- `true` when there was a hit on the ${q primary-key}.
- `false` otherwise.
${hit-first-match}:
description: |
- A boolean value.
- `true` when there was a hit on a key matching ${q restore-prefixes-first-match}.
- `false` otherwise.
restored-key:
description: |
- A string.
- The key of a cache restored via the ${q primary-key} or via the ${q restore-prefixes-first-match}.
- An empty string otherwise.
restored-keys:
description: |
- A possibly empty array of strings (JSON).
- Keys of restored caches.
- Example: `["key1", "key2"]`.''
else ""
}
runs:
using: "node16"
main: "${specific.main}"
${specific.post}
branding:
icon: "archive"
color: "gray-dark"''