blob: 62d021a1b00569150f7d328347dfdea0040b08ca (
plain) (
blame)
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
|
name: Install Cygwin
description: Install Cygwin & packages
inputs:
platform:
description: Target platform
required: false
default: x64
install-dir:
description: Installation directory
required: false
default: C:\tools\cygwin
packages:
description: Packages to install, separated by a space
required: false
env:
description: Value to set as the CYGWIN environment variable
required: false
symlinks-to-hardlinks:
description: Convert symlinks in /usr/bin to hardlinks
required: false
default: 0
runs:
using: composite
steps:
- run: |
New-Variable os -Value ('${{ runner.os }}') -Option Constant
New-Variable windows_host -Value ($os -eq 'Windows') -Option Constant
New-Variable x64 -Value ('${{ inputs.platform }}' -eq 'x64') -Option Constant
New-Variable install_dir -Value '${{ inputs.install-dir }}' -Option Constant
New-Variable packages -Value '${{ inputs.packages }}' -Option Constant
New-Variable symlinks_to_hardlinks -Value ('${{ inputs.symlinks-to-hardlinks }}' -eq '1') -Option Constant
New-Variable bin_dir -Value (Join-Path $install_dir bin) -Option Constant
New-Variable realpath -Value (Join-Path $bin_dir realpath.exe) -Option Constant
New-Variable readlink -Value (Join-Path $bin_dir readlink.exe) -Option Constant
New-Variable dirname -Value (Join-Path $bin_dir dirname.exe) -Option Constant
New-Variable cygpath -Value (Join-Path $bin_dir cygpath.exe) -Option Constant
New-Variable find -Value (Join-Path $bin_dir find.exe) -Option Constant
function Locate-Choco {
$path = Get-Command 'choco' -ErrorAction SilentlyContinue
if ($path) {
$path.Path
} else {
Join-Path ${env:ProgramData} 'chocolatey' 'bin' 'choco'
}
}
function Convert-CygwinPath {
# Like cygpath -wa, but don't resolve symlinks.
param(
[Parameter(Mandatory=$true)]
[string] $Path
)
$realpath = & $script:realpath --no-symlinks -- $Path
$dirname = & $script:dirname -- $realpath
$dirname = & $script:cygpath -wa $dirname
Join-Path $dirname (Split-Path $realpath -Leaf)
}
function Fix-CygwinLink {
# Replace a Cygwin symlink with a hardlink.
param(
[Parameter(Mandatory=$true)]
[string] $Path
)
$link_path = $Path
$link_winpath = Convert-CygwinPath $link_path
$link_ext = [System.IO.Path]::GetExtension($link_path)
$dest_path = & $script:readlink --canonicalize-existing -- $link_path
$dest_winpath = Convert-CygwinPath $dest_path
$dest_ext = [System.IO.Path]::GetExtension($dest_path)
echo "Removing symlink: $link_winpath"
Remove-Item $link_winpath -Force
# If target is an executable (i.e. its name contains one of the
# PATHEXT extensions), make sure the hardlink has the same
# extension.
$exe_exts = $env:PATHEXT.ToLower().Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)
if ($exe_exts -contains $dest_ext.ToLower() -and $dest_ext.ToLower() -ne $link_ext.ToLower()) {
$link_winpath += $dest_ext
}
echo "Creating hardlink '$link_winpath', pointing to '$dest_winpath'"
New-Item -ItemType HardLink -Path $link_winpath -Value $dest_winpath | Out-Null
}
if ($windows_host) {
echo 'CYGWIN=${{ inputs.env }}' >> $env:GITHUB_ENV
$choco = Locate-Choco
$choco_params = @(
'install',
'-y',
'--no-progress',
'--params', "/InstallDir:$install_dir"
)
if (!$x64) {
$choco_params += '--x86'
}
$choco_params += 'cygwin'
# Assuming that Cygwin is not installed when this is run.
& $choco $choco_params
# /usr/bin is really just /bin on Cygwin.
echo (Join-Path $install_dir bin) >> $env:GITHUB_PATH
echo (Join-Path $install_dir usr local bin) >> $env:GITHUB_PATH
$pkg_list = $packages.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries)
if ($pkg_list.Count -gt 0) {
& $choco install -y --no-progress --source=cygwin $pkg_list
}
if ($symlinks_to_hardlinks) {
& $find /usr/bin -type l | %{ Fix-CygwinLink $_ }
}
} else {
throw "Sorry, installing Cygwin is unsupported on $os"
}
shell: pwsh
branding:
icon: star
color: green
|