From 30e3fbc0990c072c566f0c00a890a9bc7a59260c Mon Sep 17 00:00:00 2001 From: Steve Todorov Date: Thu, 23 Mar 2023 14:12:23 +0200 Subject: [PATCH 1/4] Cleanup cache path before moving the exe file --- scripts/install/Windows.ps1 | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/install/Windows.ps1 b/scripts/install/Windows.ps1 index d0cfa1b..dff3d21 100644 --- a/scripts/install/Windows.ps1 +++ b/scripts/install/Windows.ps1 @@ -1,6 +1,23 @@ $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest Write-Host ::group::Installing $env:folder_name to tool cache -New-Item $env:RUNNER_TOOL_CACHE\$env:folder_name\ -ItemType Directory -Force -Move-Item $env:RUNNER_TEMP\$env:folder_name\* $env:RUNNER_TOOL_CACHE\$env:folder_name\ -Write-Host ::endgroup:: \ No newline at end of file + +# +# Remove cache path to avoid "file already exists" error on self-hosted runners that are not disposable +# +# Installing Rclone to tool cache +# Directory: C:\actions-runner\_work\_tool +# Mode LastWriteTime Length Name +# ---- ------------- ------ ---- +# d----- 3/23/2023 11:35 AM Rclone +# Move-Item : Cannot create a file when that file already exists. +# At C:\actions-runner\_work\_actions\AnimMouse\tool-cache\v1\scripts\install\Windows.ps1:5 char:1 +# +$cachePath = "$env:RUNNER_TOOL_CACHE\$env:folder_name" +if(Test-Path $cachePath) { + rm -f $cachePath +} + +New-Item $cachePath -ItemType Directory -Force +Move-Item $env:RUNNER_TEMP\$env:folder_name\* $cachePath +Write-Host ::endgroup:: From 9e8e676f5cc188141b8d7acf2500f4744e302032 Mon Sep 17 00:00:00 2001 From: Steve Todorov Date: Thu, 23 Mar 2023 14:37:42 +0200 Subject: [PATCH 2/4] Removing `-f` argument, as it's not supported here. --- scripts/install/Windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install/Windows.ps1 b/scripts/install/Windows.ps1 index dff3d21..5e2659a 100644 --- a/scripts/install/Windows.ps1 +++ b/scripts/install/Windows.ps1 @@ -15,7 +15,7 @@ Write-Host ::group::Installing $env:folder_name to tool cache # $cachePath = "$env:RUNNER_TOOL_CACHE\$env:folder_name" if(Test-Path $cachePath) { - rm -f $cachePath + rm $cachePath } New-Item $cachePath -ItemType Directory -Force From c2b2c3a8dd535b9bf0453cb51db3f0a87ad024b6 Mon Sep 17 00:00:00 2001 From: Steve Todorov Date: Thu, 23 Mar 2023 14:43:39 +0200 Subject: [PATCH 3/4] Windows complains. --- scripts/install/Windows.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/install/Windows.ps1 b/scripts/install/Windows.ps1 index 5e2659a..1023c8c 100644 --- a/scripts/install/Windows.ps1 +++ b/scripts/install/Windows.ps1 @@ -13,9 +13,12 @@ Write-Host ::group::Installing $env:folder_name to tool cache # Move-Item : Cannot create a file when that file already exists. # At C:\actions-runner\_work\_actions\AnimMouse\tool-cache\v1\scripts\install\Windows.ps1:5 char:1 # -$cachePath = "$env:RUNNER_TOOL_CACHE\$env:folder_name" +$runnerCachePath = $env:RUNNER_TOOL_CACHE +$folderName = $env:folder_name +$cachePath = "${runnerCachePath}\${folderName}" +Write-Output "Cache path: ${cachePath}" if(Test-Path $cachePath) { - rm $cachePath + Remove-Item -Recurse -Force $cachePath } New-Item $cachePath -ItemType Directory -Force From 6c3c88372e59b33c5583b3b5755f98608823c15b Mon Sep 17 00:00:00 2001 From: AnimMouse Date: Fri, 24 Mar 2023 16:19:29 +0800 Subject: [PATCH 4/4] refactor: Simplify by forcing Move-Item instead of checking if directory exists --- scripts/install/Windows.ps1 | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/scripts/install/Windows.ps1 b/scripts/install/Windows.ps1 index 1023c8c..5dd93bc 100644 --- a/scripts/install/Windows.ps1 +++ b/scripts/install/Windows.ps1 @@ -1,26 +1,6 @@ $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest Write-Host ::group::Installing $env:folder_name to tool cache - -# -# Remove cache path to avoid "file already exists" error on self-hosted runners that are not disposable -# -# Installing Rclone to tool cache -# Directory: C:\actions-runner\_work\_tool -# Mode LastWriteTime Length Name -# ---- ------------- ------ ---- -# d----- 3/23/2023 11:35 AM Rclone -# Move-Item : Cannot create a file when that file already exists. -# At C:\actions-runner\_work\_actions\AnimMouse\tool-cache\v1\scripts\install\Windows.ps1:5 char:1 -# -$runnerCachePath = $env:RUNNER_TOOL_CACHE -$folderName = $env:folder_name -$cachePath = "${runnerCachePath}\${folderName}" -Write-Output "Cache path: ${cachePath}" -if(Test-Path $cachePath) { - Remove-Item -Recurse -Force $cachePath -} - -New-Item $cachePath -ItemType Directory -Force -Move-Item $env:RUNNER_TEMP\$env:folder_name\* $cachePath -Write-Host ::endgroup:: +New-Item $env:RUNNER_TOOL_CACHE\$env:folder_name\ -ItemType Directory -Force +Move-Item $env:RUNNER_TEMP\$env:folder_name\* $env:RUNNER_TOOL_CACHE\$env:folder_name -Force +Write-Host ::endgroup:: \ No newline at end of file