Skip to content

Commit fdc9259

Browse files
authored
feat: support env-mapping option (#11)
1 parent 499b62b commit fdc9259

12 files changed

Lines changed: 374 additions & 107 deletions

File tree

.github/workflows/main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
mount-if-exists: false
6666
workspace-copy: true
6767
native-dev-drive: false
68+
env-mapping: ''
6869

6970
test-formats:
7071
strategy:
@@ -303,3 +304,42 @@ jobs:
303304
if (-not (Test-Path -Path test.txt -PathType Leaf)) {
304305
exit 1
305306
}
307+
308+
test-env-mapping:
309+
runs-on: windows-2022
310+
steps:
311+
- name: Check out source code
312+
uses: actions/checkout@v4
313+
- name: Setup Dev Drive
314+
uses: ./
315+
with:
316+
workspace-copy: true
317+
env-mapping: |
318+
CARGO_HOME,{{ DEV_DRIVE }}/.cargo
319+
RUSTUP_HOME,{{ DEV_DRIVE }}/.rustup
320+
MY_ENV_VAR , {{ DEV_DRIVE_PATH }}
321+
MY_OTHER_ENV_VAR,{{ DEV_DRIVE_WORKSPACE }}\other\path
322+
SHOULD_WARN,
323+
should_also_warn,about_template
324+
invalid-env-var,???
325+
invalid.env.var,!!!
326+
ENV_VAR_VALUE_INCLUDES_COMMAS,{{ DEV_DRIVE}}/my file name, with commas.txt
327+
a
328+
,
329+
42,{{ DEV_DRIVE }}/42
330+
does_it_substitute_1137,{{ DEV_DRIVE }}/$DEV_DRIVE
331+
- name: Verify Env Mapping
332+
run: |
333+
if ($Env:CARGO_HOME -ne '${{ env.DEV_DRIVE }}/.cargo') { Write-Error 'Failed CARGO_HOME'; exit 1 }
334+
if ($Env:RUSTUP_HOME -ne '${{ env.DEV_DRIVE }}/.rustup') { Write-Error 'Failed RUSTUP_HOME'; exit 1 }
335+
if ($Env:MY_ENV_VAR -ne '${{ env.DEV_DRIVE_PATH }}') { Write-Error 'Failed MY_ENV_VAR'; exit 1 }
336+
if ($Env:MY_OTHER_ENV_VAR -ne '${{ env.DEV_DRIVE_WORKSPACE }}\other\path') { Write-Error 'Failed MY_OTHER_ENV_VAR'; exit 1 }
337+
if ($Env:SHOULD_WARN -ne $null) { Write-Error 'Failed SHOULD_WARN'; exit 1 }
338+
if ($Env:should_also_warn -ne $null) { Write-Error 'Failed should_also_warn'; exit 1 }
339+
if (${Env:invalid-env-var} -ne $null) { Write-Error 'Failed invalid-env-var'; exit 1 }
340+
if (${Env:invalid.env.var} -ne $null) { Write-Error 'Failed invalid.env.var'; exit 1 }
341+
if ($Env:ENV_VAR_VALUE_INCLUDES_COMMAS -ne '${{ env.DEV_DRIVE }}/my file name, with commas.txt') { Write-Error 'Failed ENV_VAR_VALUE_INCLUDES_COMMAS'; exit 1 }
342+
if ($Env:a -ne $null) { Write-Error 'Failed a'; exit 1 }
343+
if (${Env:,} -ne $null) { Write-Error 'Failed ,'; exit 1 }
344+
if (${Env:42} -ne $null) { Write-Error 'Failed 42'; exit 1 }
345+
if ($Env:does_it_substitute_1137 -ne '${{ env.DEV_DRIVE }}/$DEV_DRIVE') { Write-Error 'Failed does_it_substitute_1137'; exit 1 }

.prettierrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"arrowParens": "avoid",
33
"bracketSameLine": false,
44
"bracketSpacing": true,
5-
"editorconfig": true,
65
"endOfLine": "lf",
76
"htmlWhitespaceSensitivity": "css",
87
"jsxSingleQuote": false,

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ You can optionally pass parameters to the action as follows:
5555
workspace-copy: false
5656
# Use native dev drive support when available. Defaults to true.
5757
native-dev-drive: true
58+
# Custom mappings of output environment variables. Defaults to no mapping.
59+
env-mapping: |
60+
MY_PROJECT_BIN,{{ DEV_DRIVE }}/path/to/bin
5861
```
5962
6063
This action is [compatible](#runner-compatibility) with `windows-2022` runners or above.
@@ -158,6 +161,59 @@ This action will automatically use the built-in [Windows Dev Drive](https://lear
158161
on your behalf when it's available on your Windows runner and `ReFS` is used.
159162
You can use this option to turn this automatic usage off.
160163

164+
165+
### *env-mapping*
166+
167+
By default, this option is not set.
168+
169+
This option provides syntactic sugar to manage the environment variables exposed by this action.
170+
171+
On a particular job, it can be repetitive having to re-declare the environment variables like below.
172+
173+
```yaml
174+
- uses: samypr100/setup-dev-drive@v3
175+
- name: Step A
176+
env:
177+
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
178+
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
179+
run: ...
180+
- name: Step B
181+
env:
182+
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
183+
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
184+
run: ...
185+
- name: Step C
186+
env:
187+
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
188+
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
189+
run: ...
190+
# ...
191+
```
192+
193+
This option allows you to define them once per job as shown in the example below.
194+
195+
It leverages [handlebars](https://handlebarsjs.com/) syntax under the hood to expose the supported
196+
[environment variables](#environment-variables), giving you the ability to create new ones with
197+
their contents after the action runs, so they can be automatically set in subsequent steps.
198+
199+
**Warning**: No canonicalization is performed on the input. The template is substituted as-is with the
200+
typical values of the environment variables and the rest of the input is then appended as-is.
201+
202+
```yaml
203+
- uses: samypr100/setup-dev-drive@v3
204+
with:
205+
env-mapping: |
206+
CARGO_HOME,{{ DEV_DRIVE }}/.cargo
207+
RUSTUP_HOME,{{ DEV_DRIVE }}/.rustup
208+
- name: Step A
209+
run: ...
210+
- name: Step B
211+
run: ...
212+
- name: Step C
213+
run: ...
214+
# ...
215+
```
216+
161217
## Environment Variables
162218

163219
These environment variables are meant to be used along `working-directory` to make sure

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ inputs:
2929
native-dev-drive:
3030
description: "Use native dev drive support when available."
3131
default: "true"
32+
env-mapping:
33+
description: "Allows mapping environment variables generated by this action to new user-defined ones."
34+
required: false
3235
runs:
3336
using: "node20"
3437
main: "dist/setup/index.js"

dist/cleanup/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)