Skip to content

Commit 57141c4

Browse files
committed
Convert absolute paths used in tasks to Windows format
The Task task runner tool uses an integrated Bash shell interpreter to allow the use of standard POSIX/Bash syntax and built-in utilities while providing cross-platform support for users who have made the poor choice of the non-standard Windows cmd or PowerShell shells. While this is a nice feature of Task, distinguishing it from other alternatives, it is still often necessary to use non-built-in utilities. So use of a Bash shell is a requirement to run our tasks even the developers using Windows. Although high quality Bash shells for Windows such as the Git Bash included as part of the Git for Windows installation generally provide a seamless experience, there is the occasional "gotcha". Relative paths work the same for POSIX and Windows, but absolute POSIX format paths may not. These paths are handled as expected by Task's integrated shell interpreter and by Bash, but when these paths are used outside that context they may no longer be correct. For example: ``` foo: cmds: - mkdir "/tmp/posix-path-test-dir" - touch "/tmp/posix-path-test-dir/posix-path-test-file" - ls "/tmp/posix-path-test-dir" - cd "/tmp/posix-path-test-dir" ``` The first three commands work as expected, but the `cd` command fails: ``` $ task foo task: [foo] mkdir "/tmp/posix-path-test-dir" task: [foo] touch "/tmp/posix-path-test-dir/posix-path-test-file" task: [foo] ls "/tmp/posix-path-test-dir" posix-path-test-file task: [foo] cd "/tmp/posix-path-test-dir" task: Failed to run task "foo": exit status 1 ``` The POSIX format `/tmp` is actually set to the system temporary directory: ``` $ cygpath -w "/tmp/posix-path-test-dir" C:\Users\per\AppData\Local\Temp\posix-path-test-dir ``` But if treated as a Windows format path, this would be the `tmp` subfolder of the root of the current drive (e.g., `C:\tmp`). Even though the command was run from Git Bash, which provides a `cd` that handles this absolute path perfectly, when run from Task the Windows native `cd` is used instead. This resulted in several of the data file validation tasks, which download the JSON schema to the temporary folder, to fail when ran on Windows. The solution is to convert these absolute paths, the occurrence of which are relatively rare in our tasks, to Windows format (which is handled fine by both the integrated, Bash, and external applications) when the task is ran on a Windows machine. The cygpath utility provides this capability: ``` $ task foo task: [foo] mkdir "C:\Users\per\AppData\Local\Temp/posix-path-test-dir" task: [foo] touch "C:\Users\per\AppData\Local\Temp/posix-path-test-dir/posix-path-test-file" task: [foo] ls "C:\Users\per\AppData\Local\Temp/posix-path-test-dir" posix-path-test-file task: [foo] cd "C:\Users\per\AppData\Local\Temp/posix-path-test-dir" ```
1 parent 73e4ec4 commit 57141c4

File tree

9 files changed

+77
-22
lines changed

9 files changed

+77
-22
lines changed

.github/workflows/check-npm-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
version: 3.x
4949

5050
- name: Validate package.json
51-
run: task npm:validate
51+
run: task --silent npm:validate
5252

5353
check-sync:
5454
runs-on: ubuntu-latest

Taskfile.yml

+35-11
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ tasks:
6060
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
6161
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
6262
WORKFLOW_SCHEMA_PATH:
63-
sh: mktemp -t workflow-schema-XXXXXXXXXX.json
63+
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
6464
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
6565
TEMPLATE_WORKFLOWS_DATA_PATH: "./workflow-templates/*.{yml,yaml}"
6666
deps:
@@ -115,7 +115,7 @@ tasks:
115115
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/dependabot-2.0.json
116116
SCHEMA_URL: https://json.schemastore.org/dependabot-2.0
117117
SCHEMA_PATH:
118-
sh: mktemp -t dependabot-schema-XXXXXXXXXX.json
118+
sh: task utility:mktemp-file TEMPLATE="dependabot-schema-XXXXXXXXXX.json"
119119
DATA_PATH: "**/dependabot.yml"
120120
cmds:
121121
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
@@ -199,7 +199,7 @@ tasks:
199199
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-issue-forms.json
200200
SCHEMA_URL: https://json.schemastore.org/github-issue-forms.json
201201
SCHEMA_PATH:
202-
sh: mktemp -t github-issue-forms-schema-XXXXXXXXXX.json
202+
sh: task utility:mktemp-file TEMPLATE="github-issue-forms-schema-XXXXXXXXXX.json"
203203
DATA_PATH: "issue-templates/forms/**/*.{yml,yaml}"
204204
deps:
205205
- task: npm:install-deps
@@ -314,7 +314,7 @@ tasks:
314314
# Source: https://github.com/DavidAnson/markdownlint/blob/main/schema/markdownlint-config-schema.json
315315
SCHEMA_URL: https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json
316316
SCHEMA_PATH:
317-
sh: mktemp -t markdownlint-schema-XXXXXXXXXX.json
317+
sh: task utility:mktemp-file TEMPLATE="markdownlint-schema-XXXXXXXXXX.json"
318318
DATA_PATH: "**/.markdownlint.{yml,yaml}"
319319
deps:
320320
- task: npm:install-deps
@@ -347,31 +347,31 @@ tasks:
347347
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json
348348
SCHEMA_URL: https://json.schemastore.org/package.json
349349
SCHEMA_PATH:
350-
sh: mktemp -t package-json-schema-XXXXXXXXXX.json
350+
sh: task utility:mktemp-file TEMPLATE="package-json-schema-XXXXXXXXXX.json"
351351
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/ava.json
352352
AVA_SCHEMA_URL: https://json.schemastore.org/ava.json
353353
AVA_SCHEMA_PATH:
354-
sh: mktemp -t ava-schema-XXXXXXXXXX.json
354+
sh: task utility:mktemp-file TEMPLATE="ava-schema-XXXXXXXXXX.json"
355355
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/eslintrc.json
356356
ESLINTRC_SCHEMA_URL: https://json.schemastore.org/eslintrc.json
357357
ESLINTRC_SCHEMA_PATH:
358-
sh: mktemp -t eslintrc-schema-XXXXXXXXXX.json
358+
sh: task utility:mktemp-file TEMPLATE="eslintrc-schema-XXXXXXXXXX.json"
359359
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/jscpd.json
360360
JSCPD_SCHEMA_URL: https://json.schemastore.org/jscpd.json
361361
JSCPD_SCHEMA_PATH:
362-
sh: mktemp -t jscpd-schema-XXXXXXXXXX.json
362+
sh: task utility:mktemp-file TEMPLATE="jscpd-schema-XXXXXXXXXX.json"
363363
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/prettierrc.json
364364
PRETTIERRC_SCHEMA_URL: https://json.schemastore.org/prettierrc.json
365365
PRETTIERRC_SCHEMA_PATH:
366-
sh: mktemp -t prettierrc-schema-XXXXXXXXXX.json
366+
sh: task utility:mktemp-file TEMPLATE="prettierrc-schema-XXXXXXXXXX.json"
367367
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/semantic-release.json
368368
SEMANTIC_RELEASE_SCHEMA_URL: https://json.schemastore.org/semantic-release.json
369369
SEMANTIC_RELEASE_SCHEMA_PATH:
370-
sh: mktemp -t semantic-release-schema-XXXXXXXXXX.json
370+
sh: task utility:mktemp-file TEMPLATE="semantic-release-schema-XXXXXXXXXX.json"
371371
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/stylelintrc.json
372372
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
373373
STYLELINTRC_SCHEMA_PATH:
374-
sh: mktemp -t stylelintrc-schema-XXXXXXXXXX.json
374+
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
375375
INSTANCE_PATH: "**/package.json"
376376
cmds:
377377
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
@@ -503,6 +503,30 @@ tasks:
503503
fi
504504
- shfmt -w .
505505

506+
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
507+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
508+
utility:mktemp-file:
509+
vars:
510+
RAW_PATH:
511+
sh: mktemp --tmpdir "{{.TEMPLATE}}"
512+
cmds:
513+
- task: utility:normalize-path
514+
vars:
515+
RAW_PATH: "{{.RAW_PATH}}"
516+
517+
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
518+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
519+
utility:normalize-path:
520+
cmds:
521+
- |
522+
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
523+
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
524+
# So paths passed to such applications must first be converted to Windows format.
525+
cygpath -w "{{.RAW_PATH}}"
526+
else
527+
echo "{{.RAW_PATH}}"
528+
fi
529+
506530
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-yaml-task/Taskfile.yml
507531
yaml:lint:
508532
desc: Check for problems with YAML files

workflow-templates/assets/check-npm-task/Taskfile.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ tasks:
1111
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json
1212
SCHEMA_URL: https://json.schemastore.org/package.json
1313
SCHEMA_PATH:
14-
sh: mktemp -t package-json-schema-XXXXXXXXXX.json
14+
sh: task utility:mktemp-file TEMPLATE="package-json-schema-XXXXXXXXXX.json"
1515
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/ava.json
1616
AVA_SCHEMA_URL: https://json.schemastore.org/ava.json
1717
AVA_SCHEMA_PATH:
18-
sh: mktemp -t ava-schema-XXXXXXXXXX.json
18+
sh: task utility:mktemp-file TEMPLATE="ava-schema-XXXXXXXXXX.json"
1919
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/eslintrc.json
2020
ESLINTRC_SCHEMA_URL: https://json.schemastore.org/eslintrc.json
2121
ESLINTRC_SCHEMA_PATH:
22-
sh: mktemp -t eslintrc-schema-XXXXXXXXXX.json
22+
sh: task utility:mktemp-file TEMPLATE="eslintrc-schema-XXXXXXXXXX.json"
2323
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/jscpd.json
2424
JSCPD_SCHEMA_URL: https://json.schemastore.org/jscpd.json
2525
JSCPD_SCHEMA_PATH:
26-
sh: mktemp -t jscpd-schema-XXXXXXXXXX.json
26+
sh: task utility:mktemp-file TEMPLATE="jscpd-schema-XXXXXXXXXX.json"
2727
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/prettierrc.json
2828
PRETTIERRC_SCHEMA_URL: https://json.schemastore.org/prettierrc.json
2929
PRETTIERRC_SCHEMA_PATH:
30-
sh: mktemp -t prettierrc-schema-XXXXXXXXXX.json
30+
sh: task utility:mktemp-file TEMPLATE="prettierrc-schema-XXXXXXXXXX.json"
3131
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/semantic-release.json
3232
SEMANTIC_RELEASE_SCHEMA_URL: https://json.schemastore.org/semantic-release.json
3333
SEMANTIC_RELEASE_SCHEMA_PATH:
34-
sh: mktemp -t semantic-release-schema-XXXXXXXXXX.json
34+
sh: task utility:mktemp-file TEMPLATE="semantic-release-schema-XXXXXXXXXX.json"
3535
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/stylelintrc.json
3636
STYLELINTRC_SCHEMA_URL: https://json.schemastore.org/stylelintrc.json
3737
STYLELINTRC_SCHEMA_PATH:
38-
sh: mktemp -t stylelintrc-schema-XXXXXXXXXX.json
38+
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
3939
INSTANCE_PATH: "**/package.json"
4040
cmds:
4141
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}

workflow-templates/assets/check-workflows-task/Taskfile.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tasks:
99
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json
1010
WORKFLOW_SCHEMA_URL: https://json.schemastore.org/github-workflow
1111
WORKFLOW_SCHEMA_PATH:
12-
sh: mktemp -t workflow-schema-XXXXXXXXXX.json
12+
sh: task utility:mktemp-file TEMPLATE="workflow-schema-XXXXXXXXXX.json"
1313
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
1414
deps:
1515
- task: npm:install-deps
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See: https://taskfile.dev/#/usage
2+
version: "3"
3+
4+
tasks:
5+
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
6+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
7+
utility:mktemp-file:
8+
vars:
9+
RAW_PATH:
10+
sh: mktemp --tmpdir "{{.TEMPLATE}}"
11+
cmds:
12+
- task: utility:normalize-path
13+
vars:
14+
RAW_PATH: "{{.RAW_PATH}}"
15+
16+
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
17+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
18+
utility:normalize-path:
19+
cmds:
20+
- |
21+
if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then
22+
# Even though the shell handles POSIX format absolute paths as expected, external applications do not.
23+
# So paths passed to such applications must first be converted to Windows format.
24+
cygpath -w "{{.RAW_PATH}}"
25+
else
26+
echo "{{.RAW_PATH}}"
27+
fi

workflow-templates/check-npm-task.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Install the [check-npm-task.yml](check-npm-task.yml) GitHub Actions workflow to
1616
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1717
- [`Taskfile.yml`](assets/check-npm-task/Taskfile.yml) - Validation task.
1818
- Install to: repository root (or merge into the existing `Taskfile.yml`).
19+
- [`Taskfile.yml`](assets/windows-task/Taskfile.yml) - Utility tasks.
20+
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1921

2022
### Configuration
2123

workflow-templates/check-npm-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
version: 3.x
4949

5050
- name: Validate package.json
51-
run: task npm:validate
51+
run: task --silent npm:validate
5252

5353
check-sync:
5454
runs-on: ubuntu-latest

workflow-templates/check-workflows-task.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Install the [`check-workflows-task.yml`](check-workflows-task.yml) GitHub Action
1616
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1717
- [`Taskfile.yml`](assets/npm-task/Taskfile.yml) - npm tasks.
1818
- Install to: repository root (or merge into the existing `Taskfile.yml`).
19+
- [`Taskfile.yml`](assets/windows-task/Taskfile.yml) - Utility tasks.
20+
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1921

2022
### Dependencies
2123

workflow-templates/dependabot/workflow-template-copies/.github/workflows/check-npm-task.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
version: 3.x
4949

5050
- name: Validate package.json
51-
run: task npm:validate
51+
run: task --silent npm:validate
5252

5353
check-sync:
5454
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)